@hypequery/datasets 0.32.0 → 0.34.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent-catalog.d.ts +3 -3
- package/dist/agent-catalog.d.ts.map +1 -1
- package/dist/cache/protocol-cache-keys.d.ts.map +1 -1
- package/dist/cache/protocol-cache-keys.js +25 -1
- package/dist/cache/query-signature.d.ts.map +1 -1
- package/dist/cache/query-signature.js +16 -5
- package/dist/catalog.d.ts +5 -1
- package/dist/catalog.d.ts.map +1 -1
- package/dist/catalog.js +9 -0
- package/dist/client-contract/build-from-deployment.d.ts +2 -2
- package/dist/client-contract/build-from-deployment.d.ts.map +1 -1
- package/dist/client-contract/build-from-deployment.js +7 -0
- package/dist/cloud-publication.d.ts +3 -3
- package/dist/cloud-publication.d.ts.map +1 -1
- package/dist/cloud-publishing.d.ts +2 -2
- package/dist/cloud-publishing.d.ts.map +1 -1
- package/dist/codegen/dataset-source.d.ts.map +1 -1
- package/dist/codegen/dataset-source.js +4 -1
- package/dist/contract-3-authoring.fixture.d.ts +103 -0
- package/dist/contract-3-authoring.fixture.d.ts.map +1 -0
- package/dist/contract-3-authoring.fixture.js +40 -0
- package/dist/contract.d.ts +5 -1
- package/dist/contract.d.ts.map +1 -1
- package/dist/contract.js +9 -0
- package/dist/dataset-compilation.d.ts +3 -0
- package/dist/dataset-compilation.d.ts.map +1 -1
- package/dist/dataset-query.d.ts +5 -0
- package/dist/dataset-query.d.ts.map +1 -1
- package/dist/dataset.d.ts.map +1 -1
- package/dist/dataset.js +12 -2
- package/dist/event-operations.d.ts +43 -0
- package/dist/event-operations.d.ts.map +1 -0
- package/dist/event-operations.js +137 -0
- package/dist/execution-capabilities.d.ts +2 -1
- package/dist/execution-capabilities.d.ts.map +1 -1
- package/dist/execution-capabilities.js +1 -1
- package/dist/execution-capabilities.json +6 -6
- package/dist/executor.d.ts +13 -0
- package/dist/executor.d.ts.map +1 -1
- package/dist/executor.js +42 -8
- package/dist/index.d.ts +6 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/portable-execution-errors.d.ts +11 -0
- package/dist/portable-execution-errors.d.ts.map +1 -1
- package/dist/portable-execution-errors.js +14 -0
- package/dist/portable-executor.d.ts +22 -5
- package/dist/portable-executor.d.ts.map +1 -1
- package/dist/portable-executor.js +64 -5
- package/dist/protocol-adapter.d.ts +12 -0
- package/dist/protocol-adapter.d.ts.map +1 -1
- package/dist/protocol-adapter.js +30 -8
- package/dist/protocol-deployment-adapter.d.ts +10 -3
- package/dist/protocol-deployment-adapter.d.ts.map +1 -1
- package/dist/protocol-deployment-adapter.js +60 -26
- package/dist/protocol-rehydrate.d.ts +3 -16
- package/dist/protocol-rehydrate.d.ts.map +1 -1
- package/dist/protocol-rehydrate.js +71 -11
- package/dist/query-builder-protocol.d.ts +10 -0
- package/dist/query-builder-protocol.d.ts.map +1 -1
- package/dist/query-planner.d.ts.map +1 -1
- package/dist/query-planner.js +3 -1
- package/dist/relationship-check.d.ts.map +1 -1
- package/dist/relationship-check.js +2 -0
- package/dist/semantic-planner.d.ts.map +1 -1
- package/dist/semantic-planner.js +16 -3
- package/dist/types.d.ts +109 -7
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/agent-catalog-projection.d.ts +2 -2
- package/dist/utils/agent-catalog-projection.d.ts.map +1 -1
- package/dist/utils/agent-catalog-projection.js +31 -2
- package/dist/utils/build-dataset-query-builder.d.ts.map +1 -1
- package/dist/utils/build-dataset-query-builder.js +4 -8
- package/dist/utils/calculation-stage-sql.d.ts +31 -0
- package/dist/utils/calculation-stage-sql.d.ts.map +1 -0
- package/dist/utils/calculation-stage-sql.js +98 -0
- package/dist/utils/compile-calculated-dataset-query.d.ts +24 -0
- package/dist/utils/compile-calculated-dataset-query.d.ts.map +1 -0
- package/dist/utils/compile-calculated-dataset-query.js +133 -0
- package/dist/utils/compile-dataset-query.d.ts.map +1 -1
- package/dist/utils/compile-dataset-query.js +11 -3
- package/dist/utils/dataset-definition-validation.d.ts.map +1 -1
- package/dist/utils/dataset-definition-validation.js +90 -6
- package/dist/utils/dataset-events.d.ts +19 -0
- package/dist/utils/dataset-events.d.ts.map +1 -0
- package/dist/utils/dataset-events.js +46 -0
- package/dist/utils/dataset-having.d.ts.map +1 -1
- package/dist/utils/dataset-having.js +6 -1
- package/dist/utils/dataset-query-result.d.ts.map +1 -1
- package/dist/utils/dataset-query-result.js +7 -1
- package/dist/utils/dataset-query-validation.d.ts +1 -1
- package/dist/utils/dataset-query-validation.d.ts.map +1 -1
- package/dist/utils/dataset-query-validation.js +25 -47
- package/dist/utils/dataset-source.d.ts +2 -2
- package/dist/utils/dataset-source.d.ts.map +1 -1
- package/dist/utils/dataset-source.js +8 -1
- package/dist/utils/dimension-selection-overrides.d.ts +19 -0
- package/dist/utils/dimension-selection-overrides.d.ts.map +1 -0
- package/dist/utils/dimension-selection-overrides.js +22 -0
- package/dist/utils/event-breakdown-sql.d.ts +15 -0
- package/dist/utils/event-breakdown-sql.d.ts.map +1 -0
- package/dist/utils/event-breakdown-sql.js +17 -0
- package/dist/utils/event-condition-sql.d.ts +18 -0
- package/dist/utils/event-condition-sql.d.ts.map +1 -0
- package/dist/utils/event-condition-sql.js +63 -0
- package/dist/utils/event-operation-shape.d.ts +8 -0
- package/dist/utils/event-operation-shape.d.ts.map +1 -0
- package/dist/utils/event-operation-shape.js +66 -0
- package/dist/utils/event-operation-spec.d.ts +43 -0
- package/dist/utils/event-operation-spec.d.ts.map +1 -0
- package/dist/utils/event-operation-spec.js +68 -0
- package/dist/utils/event-range-span.d.ts +4 -0
- package/dist/utils/event-range-span.d.ts.map +1 -0
- package/dist/utils/event-range-span.js +22 -0
- package/dist/utils/event-result-values.d.ts +8 -0
- package/dist/utils/event-result-values.d.ts.map +1 -0
- package/dist/utils/event-result-values.js +21 -0
- package/dist/utils/event-source-sql.d.ts +38 -0
- package/dist/utils/event-source-sql.d.ts.map +1 -0
- package/dist/utils/event-source-sql.js +71 -0
- package/dist/utils/filter-predicate-tree.d.ts +28 -0
- package/dist/utils/filter-predicate-tree.d.ts.map +1 -0
- package/dist/utils/filter-predicate-tree.js +80 -0
- package/dist/utils/filter-tree.d.ts +42 -0
- package/dist/utils/filter-tree.d.ts.map +1 -0
- package/dist/utils/filter-tree.js +164 -0
- package/dist/utils/filtered-aggregation-sql.d.ts.map +1 -1
- package/dist/utils/filtered-aggregation-sql.js +3 -0
- package/dist/utils/funnel-rows.d.ts +10 -0
- package/dist/utils/funnel-rows.d.ts.map +1 -0
- package/dist/utils/funnel-rows.js +30 -0
- package/dist/utils/funnel-sql.d.ts +18 -0
- package/dist/utils/funnel-sql.d.ts.map +1 -0
- package/dist/utils/funnel-sql.js +104 -0
- package/dist/utils/metric-derived-query.d.ts.map +1 -1
- package/dist/utils/metric-derived-query.js +4 -5
- package/dist/utils/metric-query-builder.d.ts.map +1 -1
- package/dist/utils/metric-query-builder.js +4 -5
- package/dist/utils/metric-query-validation.d.ts.map +1 -1
- package/dist/utils/metric-query-validation.js +18 -7
- package/dist/utils/other-bucket-sql.d.ts +23 -0
- package/dist/utils/other-bucket-sql.d.ts.map +1 -0
- package/dist/utils/other-bucket-sql.js +51 -0
- package/dist/utils/portable-aggregations.d.ts +10 -6
- package/dist/utils/portable-aggregations.d.ts.map +1 -1
- package/dist/utils/portable-aggregations.js +13 -8
- package/dist/utils/portable-grains.d.ts +17 -8
- package/dist/utils/portable-grains.d.ts.map +1 -1
- package/dist/utils/portable-grains.js +26 -11
- package/dist/utils/portable-query-calculations.d.ts +14 -0
- package/dist/utils/portable-query-calculations.d.ts.map +1 -0
- package/dist/utils/portable-query-calculations.js +31 -0
- package/dist/utils/portable-semantic-query.d.ts.map +1 -1
- package/dist/utils/portable-semantic-query.js +27 -1
- package/dist/utils/protocol-contract-3.d.ts +30 -0
- package/dist/utils/protocol-contract-3.d.ts.map +1 -0
- package/dist/utils/protocol-contract-3.js +93 -0
- package/dist/utils/protocol-metric-capabilities.d.ts.map +1 -1
- package/dist/utils/protocol-metric-capabilities.js +2 -1
- package/dist/utils/protocol-metric-expressions.d.ts.map +1 -1
- package/dist/utils/protocol-metric-expressions.js +6 -1
- package/dist/utils/protocol-rehydrate-filters.js +2 -1
- package/dist/utils/protocol-rehydrate-time-keys.d.ts +5 -0
- package/dist/utils/protocol-rehydrate-time-keys.d.ts.map +1 -0
- package/dist/utils/protocol-rehydrate-time-keys.js +5 -0
- package/dist/utils/query-calculation-errors.d.ts +6 -0
- package/dist/utils/query-calculation-errors.d.ts.map +1 -0
- package/dist/utils/query-calculation-errors.js +9 -0
- package/dist/utils/query-calculation-formula.d.ts +19 -0
- package/dist/utils/query-calculation-formula.d.ts.map +1 -0
- package/dist/utils/query-calculation-formula.js +77 -0
- package/dist/utils/query-calculation-outputs.d.ts +24 -0
- package/dist/utils/query-calculation-outputs.d.ts.map +1 -0
- package/dist/utils/query-calculation-outputs.js +72 -0
- package/dist/utils/query-calculation-plan.d.ts +67 -0
- package/dist/utils/query-calculation-plan.d.ts.map +1 -0
- package/dist/utils/query-calculation-plan.js +416 -0
- package/dist/utils/query-calculation-types.d.ts +97 -0
- package/dist/utils/query-calculation-types.d.ts.map +1 -0
- package/dist/utils/query-calculation-types.js +8 -0
- package/dist/utils/query-field-references.d.ts.map +1 -1
- package/dist/utils/query-field-references.js +2 -1
- package/dist/utils/query-filter-errors.d.ts +11 -0
- package/dist/utils/query-filter-errors.d.ts.map +1 -0
- package/dist/utils/query-filter-errors.js +65 -0
- package/dist/utils/query-timezone.d.ts +6 -3
- package/dist/utils/query-timezone.d.ts.map +1 -1
- package/dist/utils/query-timezone.js +5 -1
- package/dist/utils/relationship-builder-plan.d.ts.map +1 -1
- package/dist/utils/relationship-builder-plan.js +2 -1
- package/dist/utils/relationship-fields.d.ts.map +1 -1
- package/dist/utils/relationship-fields.js +5 -0
- package/dist/utils/relationship-measure-sql.d.ts.map +1 -1
- package/dist/utils/relationship-measure-sql.js +2 -0
- package/dist/utils/relationship-validation.d.ts +3 -1
- package/dist/utils/relationship-validation.d.ts.map +1 -1
- package/dist/utils/relationship-validation.js +8 -4
- package/dist/utils/relative-date-filters.d.ts +21 -0
- package/dist/utils/relative-date-filters.d.ts.map +1 -0
- package/dist/utils/relative-date-filters.js +86 -0
- package/dist/utils/relative-date-range.d.ts +20 -0
- package/dist/utils/relative-date-range.d.ts.map +1 -0
- package/dist/utils/relative-date-range.js +75 -0
- package/dist/utils/retention-rows.d.ts +9 -0
- package/dist/utils/retention-rows.d.ts.map +1 -0
- package/dist/utils/retention-rows.js +30 -0
- package/dist/utils/retention-sql.d.ts +16 -0
- package/dist/utils/retention-sql.d.ts.map +1 -0
- package/dist/utils/retention-sql.js +68 -0
- package/dist/utils/scoped-dataset-source.d.ts.map +1 -1
- package/dist/utils/scoped-dataset-source.js +4 -0
- package/dist/utils/segments.d.ts +3 -2
- package/dist/utils/segments.d.ts.map +1 -1
- package/dist/utils/segments.js +5 -4
- package/dist/utils/semantic-query-syntax.d.ts.map +1 -1
- package/dist/utils/semantic-query-syntax.js +8 -2
- package/dist/utils/sql-dataset-source.d.ts +36 -0
- package/dist/utils/sql-dataset-source.d.ts.map +1 -0
- package/dist/utils/sql-dataset-source.js +126 -0
- package/dist/utils/time-axis-bounds.d.ts +11 -4
- package/dist/utils/time-axis-bounds.d.ts.map +1 -1
- package/dist/utils/time-axis-bounds.js +14 -6
- package/dist/utils/time-measure-axis.d.ts +2 -2
- package/dist/utils/time-measure-axis.d.ts.map +1 -1
- package/dist/utils/time-measure-axis.js +13 -3
- package/dist/utils/time-measure-dataset-sql.d.ts +1 -1
- package/dist/utils/time-measure-dataset-sql.d.ts.map +1 -1
- package/dist/utils/time-measure-dataset-sql.js +15 -5
- package/dist/utils/time-measure-source-sql.d.ts +2 -2
- package/dist/utils/time-measure-source-sql.d.ts.map +1 -1
- package/dist/utils/time-measure-source-sql.js +7 -8
- package/dist/utils/time-query-measures.d.ts +5 -0
- package/dist/utils/time-query-measures.d.ts.map +1 -1
- package/dist/utils/time-query-measures.js +7 -0
- package/dist/utils/unsupported-contract-reasons.d.ts +5 -1
- package/dist/utils/unsupported-contract-reasons.d.ts.map +1 -1
- package/dist/utils/unsupported-contract-reasons.js +5 -1
- package/package.json +3 -3
|
@@ -1,21 +1,26 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Aggregations that the published deployment contract can carry.
|
|
3
3
|
*
|
|
4
|
-
* `approxCountDistinct`
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* `approxCountDistinct` is an expression extension 2 and deployment contract 3
|
|
5
|
+
* feature (RFC 0015). A deployment carries it as a contract 3 measure; the
|
|
6
|
+
* standalone dataset contract and published metrics stay on contract 2 and
|
|
7
|
+
* refuse it with an error naming it.
|
|
7
8
|
* `merge` is a deployment measure with its state function (RFC 0022), but the
|
|
8
9
|
* expression grammar has no merge aggregate, so a metric over one is refused.
|
|
9
10
|
*/
|
|
10
11
|
function refuseApproximate(aggregation, owner) {
|
|
11
12
|
if (aggregation === 'approxCountDistinct') {
|
|
12
|
-
throw new Error(`${owner} uses approxCountDistinct, which cannot be published
|
|
13
|
-
'need deployment contract 3 (RFC 0015).
|
|
13
|
+
throw new Error(`${owner} uses approxCountDistinct, which cannot be published here: approximate aggregations ` +
|
|
14
|
+
'need deployment contract 3 (RFC 0015). Publish it as a dataset measure, or use countDistinct here.');
|
|
14
15
|
}
|
|
15
16
|
}
|
|
16
|
-
/**
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
/**
|
|
18
|
+
* A dataset measure's aggregation as the contract carries it; otherwise throws
|
|
19
|
+
* naming `owner`. Contract 3 carries `approxCountDistinct`; contract 2 does not.
|
|
20
|
+
*/
|
|
21
|
+
export function requirePublishableMeasureAggregation(aggregation, owner, contractVersion = 2) {
|
|
22
|
+
if (contractVersion === 2)
|
|
23
|
+
refuseApproximate(aggregation, owner);
|
|
19
24
|
return aggregation;
|
|
20
25
|
}
|
|
21
26
|
/** Returns `aggregation` when an expression can carry it; otherwise throws naming `owner`. */
|
|
@@ -1,20 +1,29 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Time grains that the published deployment contract can carry.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* contract validation error.
|
|
4
|
+
* Contract 2 carries `day` through `year`. Contract 3 (RFC 0015) adds `minute`
|
|
5
|
+
* and `hour`, and the portable runtime accepts them in a query's `by` through
|
|
6
|
+
* semantic invocation 2. Metrics and the standalone dataset contract stay on
|
|
7
|
+
* the contract 2 registry.
|
|
9
8
|
*/
|
|
10
|
-
import type { ProtocolTimeGrain } from '@hypequery/protocol';
|
|
9
|
+
import type { ProtocolQueryTimeGrain, ProtocolTimeGrain } from '@hypequery/protocol';
|
|
11
10
|
import type { TimeGrain } from '../types.js';
|
|
12
11
|
/** Grains deployment contract 2 and invocation 1 carry, in ascending order. */
|
|
13
12
|
export declare const PORTABLE_TIME_GRAINS: readonly ProtocolTimeGrain[];
|
|
13
|
+
/**
|
|
14
|
+
* Grains a rebuilt dataset accepts: every grain the planner can bucket on.
|
|
15
|
+
* Invocation 1 still refuses `minute` and `hour` before they reach it.
|
|
16
|
+
*/
|
|
17
|
+
export declare const PUBLISHED_TIME_GRAINS: readonly ProtocolQueryTimeGrain[];
|
|
14
18
|
export declare function isPortableTimeGrain(grain: TimeGrain): grain is ProtocolTimeGrain;
|
|
15
|
-
|
|
19
|
+
export declare function isSubDayTimeGrain(grain: TimeGrain): boolean;
|
|
20
|
+
/** Returns `grain` when contract 2 can carry it; otherwise throws naming `owner`. */
|
|
16
21
|
export declare function requirePortableTimeGrain(grain: TimeGrain, owner: string): ProtocolTimeGrain;
|
|
17
|
-
/**
|
|
22
|
+
/**
|
|
23
|
+
* No deployment contract carries a dataset-level grain restriction, and a
|
|
24
|
+
* published dataset accepts every grain. Publishing a restriction would
|
|
25
|
+
* silently widen it, so a dataset must either declare none or list them all.
|
|
26
|
+
*/
|
|
18
27
|
export declare function assertPublishableTimeGrains(dataset: {
|
|
19
28
|
readonly name: string;
|
|
20
29
|
readonly timeGrains?: readonly TimeGrain[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"portable-grains.d.ts","sourceRoot":"","sources":["../../src/utils/portable-grains.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"portable-grains.d.ts","sourceRoot":"","sources":["../../src/utils/portable-grains.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,sBAAsB,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAErF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAE7C,+EAA+E;AAC/E,eAAO,MAAM,oBAAoB,EAAE,SAAS,iBAAiB,EAE3D,CAAC;AAEH;;;GAGG;AACH,eAAO,MAAM,qBAAqB,EAAE,SAAS,sBAAsB,EAErC,CAAC;AAI/B,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,SAAS,GAAG,KAAK,IAAI,iBAAiB,CAEhF;AAED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,SAAS,GAAG,OAAO,CAE3D;AAED,qFAAqF;AACrF,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,GAAG,iBAAiB,CAQ3F;AAED;;;;GAIG;AACH,wBAAgB,2BAA2B,CACzC,OAAO,EAAE;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,SAAS,SAAS,EAAE,CAAA;CAAE,GAC7E,IAAI,CAUN"}
|
|
@@ -1,35 +1,50 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Time grains that the published deployment contract can carry.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* contract validation error.
|
|
4
|
+
* Contract 2 carries `day` through `year`. Contract 3 (RFC 0015) adds `minute`
|
|
5
|
+
* and `hour`, and the portable runtime accepts them in a query's `by` through
|
|
6
|
+
* semantic invocation 2. Metrics and the standalone dataset contract stay on
|
|
7
|
+
* the contract 2 registry.
|
|
9
8
|
*/
|
|
9
|
+
import { SUPPORTED_TIME_GRAINS } from '../constants.js';
|
|
10
10
|
/** Grains deployment contract 2 and invocation 1 carry, in ascending order. */
|
|
11
11
|
export const PORTABLE_TIME_GRAINS = Object.freeze([
|
|
12
12
|
'day', 'week', 'month', 'quarter', 'year',
|
|
13
13
|
]);
|
|
14
|
+
/**
|
|
15
|
+
* Grains a rebuilt dataset accepts: every grain the planner can bucket on.
|
|
16
|
+
* Invocation 1 still refuses `minute` and `hour` before they reach it.
|
|
17
|
+
*/
|
|
18
|
+
export const PUBLISHED_TIME_GRAINS = Object.freeze([
|
|
19
|
+
...SUPPORTED_TIME_GRAINS,
|
|
20
|
+
]);
|
|
14
21
|
const CONTRACT_2_GRAINS = new Set(PORTABLE_TIME_GRAINS);
|
|
15
22
|
export function isPortableTimeGrain(grain) {
|
|
16
23
|
return CONTRACT_2_GRAINS.has(grain);
|
|
17
24
|
}
|
|
18
|
-
|
|
25
|
+
export function isSubDayTimeGrain(grain) {
|
|
26
|
+
return grain === 'minute' || grain === 'hour';
|
|
27
|
+
}
|
|
28
|
+
/** Returns `grain` when contract 2 can carry it; otherwise throws naming `owner`. */
|
|
19
29
|
export function requirePortableTimeGrain(grain, owner) {
|
|
20
30
|
if (!isPortableTimeGrain(grain)) {
|
|
21
|
-
throw new Error(`${owner} uses the "${grain}" time grain, which cannot be published
|
|
31
|
+
throw new Error(`${owner} uses the "${grain}" time grain, which cannot be published here: sub-day grains ` +
|
|
22
32
|
'need deployment contract 3 (RFC 0015). Use it for local queries, or pin a grain of a day or longer.');
|
|
23
33
|
}
|
|
24
34
|
return grain;
|
|
25
35
|
}
|
|
26
|
-
/**
|
|
36
|
+
/**
|
|
37
|
+
* No deployment contract carries a dataset-level grain restriction, and a
|
|
38
|
+
* published dataset accepts every grain. Publishing a restriction would
|
|
39
|
+
* silently widen it, so a dataset must either declare none or list them all.
|
|
40
|
+
*/
|
|
27
41
|
export function assertPublishableTimeGrains(dataset) {
|
|
28
42
|
if (dataset.timeGrains === undefined)
|
|
29
43
|
return;
|
|
30
|
-
const missing =
|
|
44
|
+
const missing = SUPPORTED_TIME_GRAINS.filter(grain => !dataset.timeGrains?.includes(grain));
|
|
31
45
|
if (missing.length > 0) {
|
|
32
|
-
throw new Error(`Dataset "${dataset.name}" timeGrains excludes ${missing.join(', ')}, but deployment
|
|
33
|
-
'cannot preserve dataset-level grain restrictions
|
|
46
|
+
throw new Error(`Dataset "${dataset.name}" timeGrains excludes ${missing.join(', ')}, but deployment contracts ` +
|
|
47
|
+
'cannot preserve dataset-level grain restrictions, and a published dataset accepts every grain. ' +
|
|
48
|
+
'Remove timeGrains to publish it, or keep this dataset local.');
|
|
34
49
|
}
|
|
35
50
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RFC 0026 fields of a validated portable query, in the dataset client's
|
|
3
|
+
* shape: identifiers become strings and a filter calculation's `where`
|
|
4
|
+
* comparisons become `{ field, operator, value }` filters, exactly as the
|
|
5
|
+
* query's own `filters` do.
|
|
6
|
+
*/
|
|
7
|
+
import type { ProtocolDatasetQuery } from '@hypequery/protocol';
|
|
8
|
+
import type { DatasetQueryCalculation, DatasetQueryLimitBy, DatasetQueryOtherBucket } from './query-calculation-types.js';
|
|
9
|
+
export declare function portableCalculationFields(operation: ProtocolDatasetQuery): {
|
|
10
|
+
calculations?: DatasetQueryCalculation[];
|
|
11
|
+
limitBy?: DatasetQueryLimitBy;
|
|
12
|
+
other?: DatasetQueryOtherBucket;
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=portable-query-calculations.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"portable-query-calculations.d.ts","sourceRoot":"","sources":["../../src/utils/portable-query-calculations.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAIhE,OAAO,KAAK,EAAE,uBAAuB,EAAE,mBAAmB,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AAO1H,wBAAgB,yBAAyB,CAAC,SAAS,EAAE,oBAAoB,GAAG;IAC1E,YAAY,CAAC,EAAE,uBAAuB,EAAE,CAAC;IACzC,OAAO,CAAC,EAAE,mBAAmB,CAAC;IAC9B,KAAK,CAAC,EAAE,uBAAuB,CAAC;CACjC,CAsBA"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RFC 0026 fields of a validated portable query, in the dataset client's
|
|
3
|
+
* shape: identifiers become strings and a filter calculation's `where`
|
|
4
|
+
* comparisons become `{ field, operator, value }` filters, exactly as the
|
|
5
|
+
* query's own `filters` do.
|
|
6
|
+
*/
|
|
7
|
+
import { PortableExecutionUnsupportedError } from '../portable-execution-errors.js';
|
|
8
|
+
import { rehydrateMeasureFilter } from './protocol-rehydrate-filters.js';
|
|
9
|
+
import { UNSUPPORTED_CONTRACT_REASONS } from './unsupported-contract-reasons.js';
|
|
10
|
+
/** A protocol value whose identifiers are branded strings, as plain JSON. */
|
|
11
|
+
function plain(value) {
|
|
12
|
+
return JSON.parse(JSON.stringify(value));
|
|
13
|
+
}
|
|
14
|
+
export function portableCalculationFields(operation) {
|
|
15
|
+
const calculations = operation.calculations?.map((entry, index) => {
|
|
16
|
+
if (!('filter' in entry))
|
|
17
|
+
return plain(entry);
|
|
18
|
+
return {
|
|
19
|
+
name: String(entry.name),
|
|
20
|
+
filter: {
|
|
21
|
+
measure: String(entry.filter.measure),
|
|
22
|
+
where: entry.filter.where.map((expression, at) => rehydrateMeasureFilter(expression, () => new PortableExecutionUnsupportedError(`Calculation ${index} condition ${at} is not a field/operator/value comparison, so it cannot be planned.`, { reason: UNSUPPORTED_CONTRACT_REASONS.queryFilterNotComparison }))),
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
});
|
|
26
|
+
return {
|
|
27
|
+
...(calculations === undefined || calculations.length === 0 ? {} : { calculations }),
|
|
28
|
+
...(operation.limitBy === undefined ? {} : { limitBy: plain(operation.limitBy) }),
|
|
29
|
+
...(operation.other === undefined ? {} : { other: plain(operation.other) }),
|
|
30
|
+
};
|
|
31
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"portable-semantic-query.d.ts","sourceRoot":"","sources":["../../src/utils/portable-semantic-query.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"portable-semantic-query.d.ts","sourceRoot":"","sources":["../../src/utils/portable-semantic-query.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAsB,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AACrF,OAAO,KAAK,EAIV,qBAAqB,EAEtB,MAAM,aAAa,CAAC;AAMrB,wBAAgB,aAAa,CAAC,MAAM,EAAE,OAAO,GAAG,qBAAqB,GAAG,SAAS,CAKhF;AA4BD,wBAAgB,aAAa,CAAC,SAAS,EAAE,qBAAqB,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CA0CxG"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { PortableExecutionUnsupportedError } from '../portable-execution-errors.js';
|
|
2
2
|
import { rehydrateMeasureFilter } from './protocol-rehydrate-filters.js';
|
|
3
3
|
import { UNSUPPORTED_CONTRACT_REASONS } from './unsupported-contract-reasons.js';
|
|
4
|
+
import { portableCalculationFields } from './portable-query-calculations.js';
|
|
4
5
|
export function tenantRuntime(tenant) {
|
|
5
6
|
if (tenant === undefined || tenant === null)
|
|
6
7
|
return undefined;
|
|
@@ -10,8 +11,23 @@ export function tenantRuntime(tenant) {
|
|
|
10
11
|
return { in: tenant.map(String) };
|
|
11
12
|
return tenant;
|
|
12
13
|
}
|
|
14
|
+
/**
|
|
15
|
+
* A query predicate as a dataset filter node. `logical` nodes become groups
|
|
16
|
+
* (RFC 0029); every leaf must be a field/operator/value comparison or a null
|
|
17
|
+
* check, which is all the data plane validated against the contract.
|
|
18
|
+
*/
|
|
19
|
+
function operationFilter(expression, index) {
|
|
20
|
+
if (expression.kind === 'logical') {
|
|
21
|
+
return expression.operator === 'not'
|
|
22
|
+
? { not: operationFilter(expression.operand, index) }
|
|
23
|
+
: expression.operator === 'and'
|
|
24
|
+
? { and: expression.operands.map(operand => operationFilter(operand, index)) }
|
|
25
|
+
: { or: expression.operands.map(operand => operationFilter(operand, index)) };
|
|
26
|
+
}
|
|
27
|
+
return rehydrateMeasureFilter(expression, () => new PortableExecutionUnsupportedError(`Filter ${index} holds a comparison that is not a field/operator/value comparison, so it cannot be planned.`, { reason: UNSUPPORTED_CONTRACT_REASONS.queryFilterNotComparison }));
|
|
28
|
+
}
|
|
13
29
|
function operationFilters(operation) {
|
|
14
|
-
return (operation.filters ?? []).map(
|
|
30
|
+
return (operation.filters ?? []).map(operationFilter);
|
|
15
31
|
}
|
|
16
32
|
export function semanticQuery(operation, maxRows) {
|
|
17
33
|
const filters = operationFilters(operation);
|
|
@@ -27,12 +43,18 @@ export function semanticQuery(operation, maxRows) {
|
|
|
27
43
|
? { measures: operation.measures.map(String) }
|
|
28
44
|
: {}),
|
|
29
45
|
...(filters.length > 0 ? { filters } : {}),
|
|
46
|
+
// RFC 0015: the rebuilt dataset resolves each name and rejects unknown ones.
|
|
47
|
+
...(operation.segments === undefined || operation.segments.length === 0
|
|
48
|
+
? {}
|
|
49
|
+
: { segments: operation.segments.map(String) }),
|
|
30
50
|
...(orderBy.length > 0 ? { orderBy } : {}),
|
|
31
51
|
// An omitted limit becomes the budget, so a caller cannot ask for an
|
|
32
52
|
// unbounded scan by leaving it out.
|
|
33
53
|
limit: operation.limit ?? maxRows,
|
|
34
54
|
...(operation.offset === undefined ? {} : { offset: operation.offset }),
|
|
35
55
|
...(operation.by === undefined ? {} : { by: operation.by }),
|
|
56
|
+
// RFC 0029: the data plane checked the axis against the contract.
|
|
57
|
+
...(operation.timeKey === undefined ? {} : { timeKey: String(operation.timeKey) }),
|
|
36
58
|
// RFC 0025: the dataset client applies both on the queryBuilder path,
|
|
37
59
|
// and validates `having` against the selection again.
|
|
38
60
|
...(operation.kind === 'dataset' && operation.having !== undefined
|
|
@@ -44,5 +66,9 @@ export function semanticQuery(operation, maxRows) {
|
|
|
44
66
|
}
|
|
45
67
|
: {}),
|
|
46
68
|
...(operation.timezone === undefined ? {} : { timezone: operation.timezone }),
|
|
69
|
+
// RFC 0026: calculations reach the dataset client in its own shape.
|
|
70
|
+
...(operation.kind === 'dataset' ? portableCalculationFields(operation) : {}),
|
|
71
|
+
// RFC 0029: the dataset client plans a filled series on the time axis.
|
|
72
|
+
...(operation.kind === 'dataset' && operation.fill === true ? { fill: true } : {}),
|
|
47
73
|
};
|
|
48
74
|
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The contract 3 parts of a published dataset (RFC 0015): segments, window and
|
|
3
|
+
* shift measures, and the `approximate` marker on derived measures.
|
|
4
|
+
*
|
|
5
|
+
* Producers follow the lowest-version rule: a deployment is contract 3 only
|
|
6
|
+
* when one of its datasets uses a feature contract 2 cannot express, so every
|
|
7
|
+
* other deployment keeps its contract 2 bytes and identity. Python's builder
|
|
8
|
+
* (`hypequery.datasets.deployment`) emits the same contract for the same
|
|
9
|
+
* definition; `specs/datasets/contract-3-authoring-v1.json` pins both.
|
|
10
|
+
*/
|
|
11
|
+
import { type ProtocolDatasetSegment, type ProtocolDatasetShiftMeasure, type ProtocolDatasetWindowMeasure } from '@hypequery/protocol';
|
|
12
|
+
import type { AnyDatasetInstance } from '../types.js';
|
|
13
|
+
/** The contract 3 features `dataset` uses, by name, in a fixed order. */
|
|
14
|
+
export declare function contract3Features(dataset: AnyDatasetInstance): string[];
|
|
15
|
+
/** True when the deployment holding `dataset` must be contract 3. */
|
|
16
|
+
export declare function usesContract3Features(dataset: AnyDatasetInstance): boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Segments as contract predicates, sorted by name. One condition is a bare
|
|
19
|
+
* comparison; several are the `and` of their comparisons in authored order.
|
|
20
|
+
*/
|
|
21
|
+
export declare function protocolSegments(dataset: AnyDatasetInstance): ProtocolDatasetSegment[];
|
|
22
|
+
type ProtocolTimeMeasure = ProtocolDatasetWindowMeasure | ProtocolDatasetShiftMeasure;
|
|
23
|
+
/** Window and shift measures in the order the dataset declares them. */
|
|
24
|
+
export declare function protocolTimeMeasures(dataset: AnyDatasetInstance): ProtocolTimeMeasure[];
|
|
25
|
+
/** The `approximate` marker for a derived measure: set when any input is approximate. */
|
|
26
|
+
export declare function derivedApproximateMarker(dataset: AnyDatasetInstance, name: string): {
|
|
27
|
+
readonly approximate?: true;
|
|
28
|
+
};
|
|
29
|
+
export {};
|
|
30
|
+
//# sourceMappingURL=protocol-contract-3.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protocol-contract-3.d.ts","sourceRoot":"","sources":["../../src/utils/protocol-contract-3.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAEL,KAAK,sBAAsB,EAC3B,KAAK,2BAA2B,EAChC,KAAK,4BAA4B,EAElC,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EACV,kBAAkB,EAGnB,MAAM,aAAa,CAAC;AAQrB,yEAAyE;AACzE,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,kBAAkB,GAAG,MAAM,EAAE,CAavE;AAED,qEAAqE;AACrE,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAE1E;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,kBAAkB,GAAG,sBAAsB,EAAE,CAatF;AAGD,KAAK,mBAAmB,GAAG,4BAA4B,GAAG,2BAA2B,CAAC;AAoCtF,wEAAwE;AACxE,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,kBAAkB,GAAG,mBAAmB,EAAE,CAMvF;AAED,yFAAyF;AACzF,wBAAgB,wBAAwB,CACtC,OAAO,EAAE,kBAAkB,EAC3B,IAAI,EAAE,MAAM,GACX;IAAE,QAAQ,CAAC,WAAW,CAAC,EAAE,IAAI,CAAA;CAAE,CAEjC"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The contract 3 parts of a published dataset (RFC 0015): segments, window and
|
|
3
|
+
* shift measures, and the `approximate` marker on derived measures.
|
|
4
|
+
*
|
|
5
|
+
* Producers follow the lowest-version rule: a deployment is contract 3 only
|
|
6
|
+
* when one of its datasets uses a feature contract 2 cannot express, so every
|
|
7
|
+
* other deployment keeps its contract 2 bytes and identity. Python's builder
|
|
8
|
+
* (`hypequery.datasets.deployment`) emits the same contract for the same
|
|
9
|
+
* definition; `specs/datasets/contract-3-authoring-v1.json` pins both.
|
|
10
|
+
*/
|
|
11
|
+
import { parseProtocolIdentifier, } from '@hypequery/protocol';
|
|
12
|
+
import { isApproximateBaseMeasure, isApproximateMeasure } from './approximate-measures.js';
|
|
13
|
+
import { byName } from './by-name.js';
|
|
14
|
+
import { splitDatasetMeasures } from './dataset-measures.js';
|
|
15
|
+
import { isSubDayTimeGrain } from './portable-grains.js';
|
|
16
|
+
import { filterExpression } from './protocol-metric-expressions.js';
|
|
17
|
+
import { toProtocolSemanticMetadata } from './protocol-semantic-metadata.js';
|
|
18
|
+
/** The contract 3 features `dataset` uses, by name, in a fixed order. */
|
|
19
|
+
export function contract3Features(dataset) {
|
|
20
|
+
const { base, windows, shifts } = splitDatasetMeasures(dataset.measures);
|
|
21
|
+
return [
|
|
22
|
+
...(Object.keys(dataset.segments ?? {}).length > 0 ? ['segments'] : []),
|
|
23
|
+
...(Object.keys(windows).length > 0 ? ['window measures'] : []),
|
|
24
|
+
...(Object.keys(shifts).length > 0 ? ['shift measures'] : []),
|
|
25
|
+
...(Object.values(base).some(measure => measure.aggregation === 'approxCountDistinct')
|
|
26
|
+
? ['approxCountDistinct'] : []),
|
|
27
|
+
...(dataset.defaults?.timeGrain !== undefined && isSubDayTimeGrain(dataset.defaults.timeGrain)
|
|
28
|
+
? ['a sub-day default grain'] : []),
|
|
29
|
+
// RFC 0029: published as `alternateTimeFields`, never silently dropped.
|
|
30
|
+
...((dataset.timeKeys?.length ?? 0) > 0 ? ['alternate time keys'] : []),
|
|
31
|
+
];
|
|
32
|
+
}
|
|
33
|
+
/** True when the deployment holding `dataset` must be contract 3. */
|
|
34
|
+
export function usesContract3Features(dataset) {
|
|
35
|
+
return contract3Features(dataset).length > 0;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Segments as contract predicates, sorted by name. One condition is a bare
|
|
39
|
+
* comparison; several are the `and` of their comparisons in authored order.
|
|
40
|
+
*/
|
|
41
|
+
export function protocolSegments(dataset) {
|
|
42
|
+
return Object.entries(dataset.segments ?? {}).map(([name, segment]) => {
|
|
43
|
+
const conditions = segment.filters.map(filterExpression);
|
|
44
|
+
const predicate = conditions.length === 1
|
|
45
|
+
? conditions[0]
|
|
46
|
+
: { kind: 'logical', operator: 'and', operands: conditions };
|
|
47
|
+
return {
|
|
48
|
+
name: parseProtocolIdentifier(name),
|
|
49
|
+
predicate,
|
|
50
|
+
...(segment.label !== undefined ? { label: segment.label } : {}),
|
|
51
|
+
...(segment.description !== undefined ? { description: segment.description } : {}),
|
|
52
|
+
};
|
|
53
|
+
}).sort(byName);
|
|
54
|
+
}
|
|
55
|
+
function timeMeasure(dataset, name, definition) {
|
|
56
|
+
const wrapped = dataset.measures[definition.measure];
|
|
57
|
+
const approximate = wrapped?.__type === 'measure_definition' && isApproximateBaseMeasure(wrapped);
|
|
58
|
+
const common = {
|
|
59
|
+
name: parseProtocolIdentifier(name),
|
|
60
|
+
measure: parseProtocolIdentifier(definition.measure),
|
|
61
|
+
requiresTimeRange: true,
|
|
62
|
+
...(approximate ? { approximate: true } : {}),
|
|
63
|
+
...(definition.label !== undefined ? { label: definition.label } : {}),
|
|
64
|
+
...(definition.description !== undefined ? { description: definition.description } : {}),
|
|
65
|
+
...toProtocolSemanticMetadata(definition),
|
|
66
|
+
};
|
|
67
|
+
if (definition.__type === 'shift_measure_definition') {
|
|
68
|
+
return {
|
|
69
|
+
kind: 'shift',
|
|
70
|
+
...common,
|
|
71
|
+
interval: { amount: definition.interval.amount, unit: definition.interval.unit },
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
return {
|
|
75
|
+
kind: 'window',
|
|
76
|
+
...common,
|
|
77
|
+
...(definition.trailing !== undefined
|
|
78
|
+
? { trailing: { amount: definition.trailing.amount, unit: definition.trailing.unit } }
|
|
79
|
+
: {}),
|
|
80
|
+
...(definition.toDate !== undefined ? { toDate: definition.toDate } : {}),
|
|
81
|
+
...(definition.cumulative === true ? { cumulative: true } : {}),
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
/** Window and shift measures in the order the dataset declares them. */
|
|
85
|
+
export function protocolTimeMeasures(dataset) {
|
|
86
|
+
return Object.entries(dataset.measures)
|
|
87
|
+
.filter((entry) => (entry[1].__type === 'window_measure_definition' || entry[1].__type === 'shift_measure_definition'))
|
|
88
|
+
.map(([name, definition]) => timeMeasure(dataset, name, definition));
|
|
89
|
+
}
|
|
90
|
+
/** The `approximate` marker for a derived measure: set when any input is approximate. */
|
|
91
|
+
export function derivedApproximateMarker(dataset, name) {
|
|
92
|
+
return isApproximateMeasure(dataset.measures, name) ? { approximate: true } : {};
|
|
93
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"protocol-metric-capabilities.d.ts","sourceRoot":"","sources":["../../src/utils/protocol-metric-capabilities.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"protocol-metric-capabilities.d.ts","sourceRoot":"","sources":["../../src/utils/protocol-metric-capabilities.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AACjE,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAwB,MAAM,aAAa,CAAC;AAUnF,uFAAuF;AACvF,wBAAgB,8BAA8B,CAAC,MAAM,EAAE,YAAY,EAAE,KAAK,EAAE,WAAW,GAAG,MAAM,EAAE,CAajG;AAED,mFAAmF;AACnF,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,qBAAqB,GAAG,YAAY,CAkC1G"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { filterLeaves } from './filter-tree.js';
|
|
1
2
|
const CAPABILITIES = Symbol('hypequery.protocol-metric-capabilities');
|
|
2
3
|
/** Runtime restrictions travel with a cloned handle, including publication aliases. */
|
|
3
4
|
export function protocolMetricCapabilityErrors(handle, query) {
|
|
@@ -9,7 +10,7 @@ export function protocolMetricCapabilityErrors(handle, query) {
|
|
|
9
10
|
if (!capabilities.dimensions.includes(dimension))
|
|
10
11
|
errors.push(`Dimension "${dimension}" is not published for this metric.`);
|
|
11
12
|
}
|
|
12
|
-
for (const filter of query.filters
|
|
13
|
+
for (const filter of filterLeaves(query.filters)) {
|
|
13
14
|
if (!capabilities.filters.includes(filter.field))
|
|
14
15
|
errors.push(`Filter "${filter.field}" is not published for this metric.`);
|
|
15
16
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"protocol-metric-expressions.d.ts","sourceRoot":"","sources":["../../src/utils/protocol-metric-expressions.ts"],"names":[],"mappings":"AAAA,OAAO,EAEgB,KAAK,kBAAkB,EAAE,KAAK,wBAAwB,EAC5E,MAAM,qBAAqB,CAAC;AAE7B,OAAO,KAAK,EAAE,eAAe,EAAE,wBAAwB,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAuC9G,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,YAAY,GAAG,kBAAkB,
|
|
1
|
+
{"version":3,"file":"protocol-metric-expressions.d.ts","sourceRoot":"","sources":["../../src/utils/protocol-metric-expressions.ts"],"names":[],"mappings":"AAAA,OAAO,EAEgB,KAAK,kBAAkB,EAAE,KAAK,wBAAwB,EAC5E,MAAM,qBAAqB,CAAC;AAE7B,OAAO,KAAK,EAAE,eAAe,EAAE,wBAAwB,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAuC9G,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,YAAY,GAAG,kBAAkB,CAyBzE;AAsDD,gFAAgF;AAChF,wBAAgB,wBAAwB,CAAC,UAAU,EAAE,wBAAwB,GAAG,kBAAkB,CAEjG;AAED;;;;;GAKG;AACH,wBAAgB,+BAA+B,CAAC,UAAU,EAAE,wBAAwB,GAAG,kBAAkB,CAExG;AAED,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,eAAe,GAAG,iBAAiB,GAAG,kBAAkB,CAQ9F;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,iBAAiB,GAAG,wBAAwB,CASlF"}
|
|
@@ -38,9 +38,14 @@ export function filterExpression(filter) {
|
|
|
38
38
|
if (filter.operator === 'isNull' || filter.operator === 'isNotNull') {
|
|
39
39
|
return { kind: 'comparison', operator: filter.operator, left };
|
|
40
40
|
}
|
|
41
|
+
// RFC 0003: `between` bounds are a two-item tuple; `in`/`notIn` take an array.
|
|
41
42
|
const right = {
|
|
42
43
|
kind: 'literal',
|
|
43
|
-
value:
|
|
44
|
+
value: filter.operator === 'between' && Array.isArray(filter.value)
|
|
45
|
+
? validateCanonicalValue({
|
|
46
|
+
$hypequery: { type: 'tuple', version: 1, values: filter.value.map(canonicalValue) },
|
|
47
|
+
})
|
|
48
|
+
: canonicalValue(filter.value),
|
|
44
49
|
};
|
|
45
50
|
const result = {
|
|
46
51
|
kind: 'comparison',
|
|
@@ -33,7 +33,8 @@ function fromCanonicalValue(value, unsupported) {
|
|
|
33
33
|
.$hypequery;
|
|
34
34
|
if (tagged === undefined)
|
|
35
35
|
throw unsupported();
|
|
36
|
-
|
|
36
|
+
// `in`/`notIn` carry an array; `between` carries a two-item tuple.
|
|
37
|
+
if (tagged.type === 'array' || tagged.type === 'tuple') {
|
|
37
38
|
return (tagged.values ?? []).map(item => fromCanonicalValue(item, unsupported));
|
|
38
39
|
}
|
|
39
40
|
if (tagged.value === undefined)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protocol-rehydrate-time-keys.d.ts","sourceRoot":"","sources":["../../src/utils/protocol-rehydrate-time-keys.ts"],"names":[],"mappings":"AAAA,0FAA0F;AAC1F,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,GAAG;IAAE,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAA;CAAE,CAG3E"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** Thrown when a calculation names a kind or field this executor cannot run yet. */
|
|
2
|
+
export declare class UnsupportedQueryCalculationError extends Error {
|
|
3
|
+
readonly reasons: readonly string[];
|
|
4
|
+
constructor(reasons: readonly string[]);
|
|
5
|
+
}
|
|
6
|
+
//# sourceMappingURL=query-calculation-errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query-calculation-errors.d.ts","sourceRoot":"","sources":["../../src/utils/query-calculation-errors.ts"],"names":[],"mappings":"AAAA,oFAAoF;AACpF,qBAAa,gCAAiC,SAAQ,KAAK;IAC7C,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE;gBAA1B,OAAO,EAAE,SAAS,MAAM,EAAE;CAIhD"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** Thrown when a calculation names a kind or field this executor cannot run yet. */
|
|
2
|
+
export class UnsupportedQueryCalculationError extends Error {
|
|
3
|
+
reasons;
|
|
4
|
+
constructor(reasons) {
|
|
5
|
+
super(reasons.join('; '));
|
|
6
|
+
this.reasons = reasons;
|
|
7
|
+
this.name = 'UnsupportedQueryCalculationError';
|
|
8
|
+
}
|
|
9
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RFC 0026 formula nodes as derived measures.
|
|
3
|
+
*
|
|
4
|
+
* A formula calculation becomes an ordinary derived measure of the query's
|
|
5
|
+
* dataset view, so the derived and time-measure planners render it through
|
|
6
|
+
* the same dialect formula renderer model-level derived measures use.
|
|
7
|
+
*/
|
|
8
|
+
import type { DerivedMeasureDefinition } from '../types.js';
|
|
9
|
+
import type { QueryFormulaNode } from './query-calculation-types.js';
|
|
10
|
+
/** Every reference a formula makes, in first-use order. */
|
|
11
|
+
export declare function formulaReferences(node: QueryFormulaNode): string[];
|
|
12
|
+
/**
|
|
13
|
+
* A derived measure computing `node`. `resolve` maps each reference to the
|
|
14
|
+
* measure it reads (a selected measure, or an earlier calculation's internal
|
|
15
|
+
* name). Each input is its own alias, so the formula honours whatever names a
|
|
16
|
+
* planner passes for them.
|
|
17
|
+
*/
|
|
18
|
+
export declare function formulaMeasure(node: QueryFormulaNode, resolve: (name: string) => string): DerivedMeasureDefinition;
|
|
19
|
+
//# sourceMappingURL=query-calculation-formula.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query-calculation-formula.d.ts","sourceRoot":"","sources":["../../src/utils/query-calculation-formula.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,KAAK,EAAE,wBAAwB,EAAe,MAAM,aAAa,CAAC;AACzE,OAAO,KAAK,EAAwB,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAK3F,2DAA2D;AAC3D,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,gBAAgB,GAAG,MAAM,EAAE,CAWlE;AAoCD;;;;;GAKG;AACH,wBAAgB,cAAc,CAC5B,IAAI,EAAE,gBAAgB,EACtB,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,GAChC,wBAAwB,CAW1B"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RFC 0026 formula nodes as derived measures.
|
|
3
|
+
*
|
|
4
|
+
* A formula calculation becomes an ordinary derived measure of the query's
|
|
5
|
+
* dataset view, so the derived and time-measure planners render it through
|
|
6
|
+
* the same dialect formula renderer model-level derived measures use.
|
|
7
|
+
*/
|
|
8
|
+
const BINARY = new Set(['add', 'subtract', 'multiply', 'divide']);
|
|
9
|
+
const BINARY_SQL = { add: '+', subtract: '-', multiply: '*', divide: '/' };
|
|
10
|
+
/** Every reference a formula makes, in first-use order. */
|
|
11
|
+
export function formulaReferences(node) {
|
|
12
|
+
const names = [];
|
|
13
|
+
const visit = (arg) => {
|
|
14
|
+
if (typeof arg === 'string') {
|
|
15
|
+
if (!names.includes(arg))
|
|
16
|
+
names.push(arg);
|
|
17
|
+
}
|
|
18
|
+
else if (typeof arg === 'object' && arg !== null) {
|
|
19
|
+
arg.args.forEach(visit);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
node.args.forEach(visit);
|
|
23
|
+
return names;
|
|
24
|
+
}
|
|
25
|
+
function expression(arg, ref) {
|
|
26
|
+
if (typeof arg === 'string')
|
|
27
|
+
return { kind: 'ref', name: ref(arg) };
|
|
28
|
+
if (typeof arg === 'number')
|
|
29
|
+
return { kind: 'literal', value: arg };
|
|
30
|
+
const args = arg.args.map(child => expression(child, ref));
|
|
31
|
+
if (arg.op === 'percentChange') {
|
|
32
|
+
const [current, previous] = args;
|
|
33
|
+
return {
|
|
34
|
+
kind: 'binary',
|
|
35
|
+
operator: 'divide',
|
|
36
|
+
left: { kind: 'binary', operator: 'subtract', left: current, right: previous },
|
|
37
|
+
right: { kind: 'function', name: 'nullIfZero', args: [previous] },
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
if (BINARY.has(arg.op)) {
|
|
41
|
+
const [left, right] = args;
|
|
42
|
+
return { kind: 'binary', operator: arg.op, left, right };
|
|
43
|
+
}
|
|
44
|
+
return { kind: 'function', name: arg.op, args };
|
|
45
|
+
}
|
|
46
|
+
/** Generic SQL for `FormulaExpr.toSQL`; planners render through the dialect instead. */
|
|
47
|
+
function expressionSql(node) {
|
|
48
|
+
switch (node.kind) {
|
|
49
|
+
case 'ref': return node.name;
|
|
50
|
+
case 'literal': return String(node.value);
|
|
51
|
+
case 'binary': return `(${expressionSql(node.left)}) ${BINARY_SQL[node.operator]} (${expressionSql(node.right)})`;
|
|
52
|
+
case 'function': {
|
|
53
|
+
const name = node.name === 'nullIfZero' ? 'NULLIF' : node.name.toUpperCase();
|
|
54
|
+
const args = node.args.map(expressionSql);
|
|
55
|
+
return node.name === 'nullIfZero' ? `${name}(${args[0]}, 0)` : `${name}(${args.join(', ')})`;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* A derived measure computing `node`. `resolve` maps each reference to the
|
|
61
|
+
* measure it reads (a selected measure, or an earlier calculation's internal
|
|
62
|
+
* name). Each input is its own alias, so the formula honours whatever names a
|
|
63
|
+
* planner passes for them.
|
|
64
|
+
*/
|
|
65
|
+
export function formulaMeasure(node, resolve) {
|
|
66
|
+
const uses = {};
|
|
67
|
+
for (const name of formulaReferences(node))
|
|
68
|
+
uses[resolve(name)] = resolve(name);
|
|
69
|
+
return {
|
|
70
|
+
__type: 'derived_measure_definition',
|
|
71
|
+
uses,
|
|
72
|
+
formula: (inputs) => {
|
|
73
|
+
const built = expression(node, name => inputs[resolve(name)] ?? resolve(name));
|
|
74
|
+
return { __type: 'formula_expr', expression: built, toSQL: () => expressionSql(built) };
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The output columns RFC 0026 calculations add to a result, decided from the
|
|
3
|
+
* query alone: names, internal planner names, kinds and types.
|
|
4
|
+
*/
|
|
5
|
+
import type { DatasetQuery } from '../types.js';
|
|
6
|
+
import type { DatasetCalculationColumn, DatasetQueryCalculation, QueryCalculationKind } from './query-calculation-types.js';
|
|
7
|
+
/**
|
|
8
|
+
* Calculation measures are planned under reserved names, so a caller's output
|
|
9
|
+
* name never collides with, shadows or reveals a field of the model.
|
|
10
|
+
*/
|
|
11
|
+
export declare const CALCULATION_INTERNAL_PREFIX = "_hq_calc_";
|
|
12
|
+
export interface CalculationOutput extends DatasetCalculationColumn {
|
|
13
|
+
/** The measure or column name the planners use. */
|
|
14
|
+
readonly internal: string;
|
|
15
|
+
}
|
|
16
|
+
/** True when the query needs the calculation planner. */
|
|
17
|
+
export declare function hasQueryCalculations(query: Pick<DatasetQuery, 'calculations' | 'limitBy' | 'other'>): boolean;
|
|
18
|
+
/** The single kind member of an entry, or undefined when it has none or several. */
|
|
19
|
+
export declare function calculationKind(entry: DatasetQueryCalculation): QueryCalculationKind | undefined;
|
|
20
|
+
/** Every output column in output order. Entries without exactly one kind add none. */
|
|
21
|
+
export declare function calculationOutputs(query: Pick<DatasetQuery, 'calculations'>): CalculationOutput[];
|
|
22
|
+
/** The public metadata for each output column. */
|
|
23
|
+
export declare function calculationColumns(query: Pick<DatasetQuery, 'calculations'>): DatasetCalculationColumn[];
|
|
24
|
+
//# sourceMappingURL=query-calculation-outputs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query-calculation-outputs.d.ts","sourceRoot":"","sources":["../../src/utils/query-calculation-outputs.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,KAAK,EAAE,wBAAwB,EAAE,uBAAuB,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AAE5H;;;GAGG;AACH,eAAO,MAAM,2BAA2B,cAAc,CAAC;AAEvD,MAAM,WAAW,iBAAkB,SAAQ,wBAAwB;IACjE,mDAAmD;IACnD,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;CAC3B;AAED,yDAAyD;AACzD,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,IAAI,CAAC,YAAY,EAAE,cAAc,GAAG,SAAS,GAAG,OAAO,CAAC,GAAG,OAAO,CAI7G;AAED,oFAAoF;AACpF,wBAAgB,eAAe,CAAC,KAAK,EAAE,uBAAuB,GAAG,oBAAoB,GAAG,SAAS,CAIhG;AAED,sFAAsF;AACtF,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,IAAI,CAAC,YAAY,EAAE,cAAc,CAAC,GAAG,iBAAiB,EAAE,CAiDjG;AAED,kDAAkD;AAClD,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,IAAI,CAAC,YAAY,EAAE,cAAc,CAAC,GAAG,wBAAwB,EAAE,CAExG"}
|