@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
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Query-scoped calculations (RFC 0026) as the dataset client accepts them.
|
|
3
|
+
*
|
|
4
|
+
* The shapes mirror the portable query envelope, except that a `filter`
|
|
5
|
+
* calculation's `where` uses the client's `{ field, operator, value }`
|
|
6
|
+
* filters, exactly as `DatasetQuery.filters` does.
|
|
7
|
+
*/
|
|
8
|
+
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"query-field-references.d.ts","sourceRoot":"","sources":["../../src/utils/query-field-references.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"query-field-references.d.ts","sourceRoot":"","sources":["../../src/utils/query-field-references.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,YAAY,EAAgB,MAAM,aAAa,CAAC;AASlF;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,kBAAkB,EAAE,KAAK,EAAE,YAAY,GAAG,MAAM,EAAE,CAsB/F"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { filterLeaves } from './filter-tree.js';
|
|
1
2
|
import { baseMeasureNames, isBaseMeasure } from './dataset-measures.js';
|
|
2
3
|
import { measureDependencies } from './measure-dependencies.js';
|
|
3
4
|
import { segmentFilters } from './segments.js';
|
|
@@ -14,7 +15,7 @@ function filterField(dataset, filter) {
|
|
|
14
15
|
export function queryFieldReferences(dataset, query) {
|
|
15
16
|
const names = [
|
|
16
17
|
...(query.dimensions ?? []),
|
|
17
|
-
...(query.filters
|
|
18
|
+
...filterLeaves(query.filters).map(filter => filterField(dataset, filter)),
|
|
18
19
|
...segmentFilters(dataset, query.segments).map(filter => filterField(dataset, filter)),
|
|
19
20
|
...(query.orderBy ?? []).map(order => order.field),
|
|
20
21
|
...(query.having ?? []).map(condition => condition.measure),
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { AnyDatasetInstance, DatasetFilterNode, ExecutionContext } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Why each comparison of a filter tree cannot apply to `ds`: an unknown or
|
|
4
|
+
* disallowed field or operator (under `not`, the negated operator the
|
|
5
|
+
* allowlist must permit), a value of the wrong type, an unresolved relative
|
|
6
|
+
* range, or the tenant field under runtime tenancy. Query `filters` and RFC
|
|
7
|
+
* 0026 filter calculations share these rules; a malformed tree is reported by
|
|
8
|
+
* `filterTreeErrors`, not here.
|
|
9
|
+
*/
|
|
10
|
+
export declare function queryFilterErrors(ds: AnyDatasetInstance, queryFilters: readonly DatasetFilterNode[], context?: ExecutionContext): string[];
|
|
11
|
+
//# sourceMappingURL=query-filter-errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query-filter-errors.d.ts","sourceRoot":"","sources":["../../src/utils/query-filter-errors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAW3F;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAC/B,EAAE,EAAE,kBAAkB,EACtB,YAAY,EAAE,SAAS,iBAAiB,EAAE,EAC1C,OAAO,CAAC,EAAE,gBAAgB,GACzB,MAAM,EAAE,CAyDV"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { validateFilterValue } from '../validation.js';
|
|
2
|
+
import { SEMANTIC_FILTER_OPERATORS } from '../constants.js';
|
|
3
|
+
import { getRuntimeTenantPredicate } from './tenant-runtime.js';
|
|
4
|
+
import { isQualifiedField } from './relationship-fields.js';
|
|
5
|
+
import { validateQualifiedFilter } from './relationship-validation.js';
|
|
6
|
+
import { filterAllowsOperator } from './filter-operator-policy.js';
|
|
7
|
+
import { effectiveFilters } from './effective-filters.js';
|
|
8
|
+
import { effectiveFilterLeaves } from './filter-tree.js';
|
|
9
|
+
import { relativeDateFilterError } from './relative-date-filters.js';
|
|
10
|
+
/**
|
|
11
|
+
* Why each comparison of a filter tree cannot apply to `ds`: an unknown or
|
|
12
|
+
* disallowed field or operator (under `not`, the negated operator the
|
|
13
|
+
* allowlist must permit), a value of the wrong type, an unresolved relative
|
|
14
|
+
* range, or the tenant field under runtime tenancy. Query `filters` and RFC
|
|
15
|
+
* 0026 filter calculations share these rules; a malformed tree is reported by
|
|
16
|
+
* `filterTreeErrors`, not here.
|
|
17
|
+
*/
|
|
18
|
+
export function queryFilterErrors(ds, queryFilters, context) {
|
|
19
|
+
const errors = [];
|
|
20
|
+
const filters = effectiveFilters(ds);
|
|
21
|
+
const filterNames = Object.keys(filters);
|
|
22
|
+
for (const { filter, operators } of effectiveFilterLeaves(queryFilters)) {
|
|
23
|
+
// The client resolves every valid relative range first (RFC 0029); one
|
|
24
|
+
// still here could not be resolved, and says why.
|
|
25
|
+
if (filter.operator === 'inDateRange') {
|
|
26
|
+
errors.push(relativeDateFilterError(ds, filter) ?? `Filter "${filter.field}": "inDateRange" was not resolved before validation.`);
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
if (isQualifiedField(filter.field)) {
|
|
30
|
+
const filterError = validateQualifiedFilter(ds, filter, context, operators);
|
|
31
|
+
if (filterError) {
|
|
32
|
+
errors.push(filterError);
|
|
33
|
+
}
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
if (!filterNames.includes(filter.field)) {
|
|
37
|
+
errors.push(`Unknown filter fields: ${filter.field}. Available: ${filterNames.join(', ')}`);
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
const filterDefinition = filters[filter.field];
|
|
41
|
+
const refused = operators.find(operator => !filterAllowsOperator(filterDefinition, operator));
|
|
42
|
+
if (refused) {
|
|
43
|
+
errors.push(`Filter "${filter.field}" does not allow operator "${refused}"${refused === filter.operator ? '' : ` (the negation of "${filter.operator}")`}. Allowed: ${(filterDefinition?.operators ?? SEMANTIC_FILTER_OPERATORS).join(', ')}`);
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
const resolvedField = filterDefinition.field;
|
|
47
|
+
const resolvedDimension = ds.dimensions[resolvedField];
|
|
48
|
+
const resolvedColumn = resolvedDimension?.sql
|
|
49
|
+
? undefined
|
|
50
|
+
: resolvedDimension?.column ?? resolvedField;
|
|
51
|
+
if (getRuntimeTenantPredicate(context) && ds.tenantKey && resolvedColumn === ds.tenantKey) {
|
|
52
|
+
errors.push(`Cannot filter on tenant field "${filter.field}" when runtime tenancy enforcement is active.`);
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
const fieldType = resolvedDimension?.fieldType;
|
|
56
|
+
if (!fieldType) {
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
const filterError = validateFilterValue(filter, fieldType);
|
|
60
|
+
if (filterError) {
|
|
61
|
+
errors.push(filterError);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return errors;
|
|
65
|
+
}
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import type { DatasetSqlDialectRules } from '../dataset-sql-dialect.js';
|
|
2
|
-
import type { AnyDatasetInstance
|
|
2
|
+
import type { AnyDatasetInstance } from '../types.js';
|
|
3
|
+
import type { PlannedFilter, PlannedFilterOperator } from './filter-predicate-tree.js';
|
|
3
4
|
/** Named zones only: reject fixed offsets, invalid zones, and SQL fragments. */
|
|
4
5
|
export declare function isQueryTimezone(value: unknown): value is string;
|
|
5
6
|
export declare function queryTimezoneErrors(timezone: unknown): string[];
|
|
7
|
+
/** The canonical IANA name a query zone is rendered as; `UTC` when absent. */
|
|
8
|
+
export declare function queryTimezoneName(timezone: string | undefined): string;
|
|
6
9
|
/** Conversion preserves timestamp instants and interprets Date values as local dates. */
|
|
7
10
|
export declare function queryTimeSql(dialect: DatasetSqlDialectRules, expression: string, timezone: string | undefined): string;
|
|
8
11
|
/** True when a local filter field reads one of the dataset's time-axis columns. */
|
|
@@ -13,7 +16,7 @@ export declare function queryTimeFilterSql(dialect: DatasetSqlDialectRules, ds:
|
|
|
13
16
|
export interface QueryTimePredicate {
|
|
14
17
|
/** The column side of the predicate, converted to a zone when the value needs one. */
|
|
15
18
|
readonly expression: string;
|
|
16
|
-
readonly operator:
|
|
19
|
+
readonly operator: PlannedFilterOperator;
|
|
17
20
|
/** The value to bind, with instants rewritten to the wall clock of that zone. */
|
|
18
21
|
readonly value: unknown;
|
|
19
22
|
}
|
|
@@ -43,5 +46,5 @@ export interface QueryTimeFilterOptions {
|
|
|
43
46
|
* changes a member's meaning. Non-timestamp fields and `like` patterns are
|
|
44
47
|
* bound unchanged.
|
|
45
48
|
*/
|
|
46
|
-
export declare function queryTimeFilter(dialect: DatasetSqlDialectRules, ds: AnyDatasetInstance, filter:
|
|
49
|
+
export declare function queryTimeFilter(dialect: DatasetSqlDialectRules, ds: AnyDatasetInstance, filter: PlannedFilter, expression: string, timezone: string | undefined, options?: QueryTimeFilterOptions): QueryTimePredicate[];
|
|
47
50
|
//# sourceMappingURL=query-timezone.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"query-timezone.d.ts","sourceRoot":"","sources":["../../src/utils/query-timezone.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AACxE,OAAO,KAAK,EAAE,kBAAkB,EAAE,
|
|
1
|
+
{"version":3,"file":"query-timezone.d.ts","sourceRoot":"","sources":["../../src/utils/query-timezone.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AACxE,OAAO,KAAK,EAAE,kBAAkB,EAAwB,MAAM,aAAa,CAAC;AAC5E,OAAO,KAAK,EAAE,aAAa,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAMvF,gFAAgF;AAChF,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAS/D;AAED,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,OAAO,GAAG,MAAM,EAAE,CAG/D;AASD,8EAA8E;AAC9E,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CAEtE;AAED,yFAAyF;AACzF,wBAAgB,YAAY,CAAC,OAAO,EAAE,sBAAsB,EAAE,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CAEtH;AAED,mFAAmF;AACnF,wBAAgB,eAAe,CAAC,EAAE,EAAE,kBAAkB,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAK9E;AAED,sFAAsF;AACtF,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,sBAAsB,EAC/B,EAAE,EAAE,kBAAkB,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,SAAS,GACtF,MAAM,CAER;AAED,8EAA8E;AAC9E,MAAM,WAAW,kBAAkB;IACjC,sFAAsF;IACtF,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,QAAQ,EAAE,qBAAqB,CAAC;IACzC,iFAAiF;IACjF,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;CACzB;AAED,MAAM,WAAW,sBAAsB;IACrC;;;;;OAKG;IACH,QAAQ,CAAC,KAAK,CAAC,EAAE,QAAQ,GAAG,WAAW,CAAC;CACzC;AAID;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,eAAe,CAC7B,OAAO,EAAE,sBAAsB,EAC/B,EAAE,EAAE,kBAAkB,EACtB,MAAM,EAAE,aAAa,EACrB,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,MAAM,GAAG,SAAS,EAC5B,OAAO,GAAE,sBAA2B,GACnC,kBAAkB,EAAE,CA0CtB"}
|
|
@@ -26,6 +26,10 @@ function canonicalTimezone(timezone) {
|
|
|
26
26
|
throw new Error(errors[0]);
|
|
27
27
|
return new Intl.DateTimeFormat('en', { timeZone: timezone }).resolvedOptions().timeZone;
|
|
28
28
|
}
|
|
29
|
+
/** The canonical IANA name a query zone is rendered as; `UTC` when absent. */
|
|
30
|
+
export function queryTimezoneName(timezone) {
|
|
31
|
+
return canonicalTimezone(timezone);
|
|
32
|
+
}
|
|
29
33
|
/** Conversion preserves timestamp instants and interprets Date values as local dates. */
|
|
30
34
|
export function queryTimeSql(dialect, expression, timezone) {
|
|
31
35
|
return dialect.toQueryTimezone(expression, canonicalTimezone(timezone));
|
|
@@ -70,7 +74,7 @@ export function queryTimeFilter(dialect, ds, filter, expression, timezone, optio
|
|
|
70
74
|
: expression;
|
|
71
75
|
const local = { expression: localExpression, operator: filter.operator, value: filter.value };
|
|
72
76
|
// A null check has no value to read in any zone.
|
|
73
|
-
if (fieldType !== 'timestamp' || filter.operator === 'like'
|
|
77
|
+
if (fieldType !== 'timestamp' || filter.operator === 'like' || filter.operator === 'notLike'
|
|
74
78
|
|| filter.operator === 'isNull' || filter.operator === 'isNotNull')
|
|
75
79
|
return [local];
|
|
76
80
|
const values = Array.isArray(filter.value) ? filter.value : [filter.value];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"relationship-builder-plan.d.ts","sourceRoot":"","sources":["../../src/utils/relationship-builder-plan.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"relationship-builder-plan.d.ts","sourceRoot":"","sources":["../../src/utils/relationship-builder-plan.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAEnD,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AAIxE;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,KAAK,EACV,kBAAkB,EAClB,YAAY,EACZ,gBAAgB,EAChB,WAAW,EACZ,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AACrE,OAAO,EAAuC,KAAK,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAG7F,MAAM,WAAW,mBAAmB;IAClC,+DAA+D;IAC/D,YAAY,EAAE,MAAM,CAAC;IACrB,iEAAiE;IACjE,MAAM,EAAE,MAAM,CAAC;IACf,wEAAwE;IACxE,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,CAAC,EAAE,SAAS,eAAe,EAAE,CAAC;IAClC,sCAAsC;IACtC,IAAI,EAAE,MAAM,CAAC;IACb,wCAAwC;IACxC,EAAE,EAAE,MAAM,CAAC;IACX,4EAA4E;IAC5E,KAAK,EAAE,iBAAiB,EAAE,CAAC;IAC3B,uFAAuF;IACvF,KAAK,EAAE,OAAO,CAAC;CAChB;AAED,MAAM,WAAW,0BAA0B;IACzC,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,mBAAmB,EAAE,CAAC;IAC7B,kBAAkB,EAAE,GAAG,CAAC,MAAM,EAAE,mBAAmB,CAAC,CAAC;IACrD,oEAAoE;IACpE,OAAO,EAAE,sBAAsB,CAAC;CACjC;AAED,KAAK,SAAS,GAAG,IAAI,CAAC,YAAY,GAAG,WAAW,EAAE,YAAY,GAAG,SAAS,GAAG,SAAS,CAAC,GAAG,IAAI,CAAC,YAAY,EAAE,UAAU,CAAC,CAAC;AAEzH;;;;;GAKG;AACH,wBAAgB,+BAA+B,CAC7C,EAAE,EAAE,kBAAkB,EACtB,KAAK,EAAE,SAAS,EAChB,OAAO,CAAC,EAAE,gBAAgB,EAC1B,OAAO,GAAE,sBAAoD,GAC5D,0BAA0B,GAAG,SAAS,CAmDxC;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAC/B,GAAG,EAAE,0BAA0B,GAAG,SAAS,EAC3C,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,GACb,MAAM,CAER;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,0BAA0B,CACxC,EAAE,EAAE,kBAAkB,EACtB,IAAI,EAAE,MAAM,EACZ,GAAG,EAAE,0BAA0B,GAC9B,MAAM,CAaR;AAED;;;;;;;;;GASG;AACH,wBAAgB,sBAAsB,CACpC,EAAE,EAAE,gBAAgB,EACpB,GAAG,EAAE,0BAA0B,GAAG,SAAS,GAC1C,gBAAgB,CAoClB"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { filterLeaves } from './filter-tree.js';
|
|
1
2
|
import { relationshipKeys } from './relationship-keys.js';
|
|
2
3
|
import { relationshipJoinSource } from './relationship-measure-sql.js';
|
|
3
4
|
import { clickhouseDatasetSqlDialect } from './clickhouse-dataset-sql-dialect.js';
|
|
@@ -15,7 +16,7 @@ export function buildRelationshipBuilderContext(ds, query, context, dialect = cl
|
|
|
15
16
|
const referenced = [
|
|
16
17
|
...(query.dimensions ?? []),
|
|
17
18
|
...(query.measures ?? []),
|
|
18
|
-
...(query.filters
|
|
19
|
+
...filterLeaves(query.filters).map((filter) => filter.field),
|
|
19
20
|
...(query.orderBy ?? []).map((order) => order.field),
|
|
20
21
|
...runtimeConstraints(context).map((constraint) => constraint.field),
|
|
21
22
|
].filter(isQualifiedField);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"relationship-fields.d.ts","sourceRoot":"","sources":["../../src/utils/relationship-fields.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EACV,kBAAkB,EAClB,mBAAmB,EACnB,sBAAsB,EACvB,MAAM,aAAa,CAAC;AAErB;;;;;;GAMG;AACH,wBAAgB,+BAA+B,CAC7C,IAAI,EAAE,MAAM,EACZ,YAAY,EAAE,sBAAsB,GACnC,MAAM,EAAE,CAEV;AAED;;;;;GAKG;AACH,wBAAgB,+BAA+B,CAC7C,IAAI,EAAE,MAAM,EACZ,YAAY,EAAE,sBAAsB,GACnC,MAAM,EAAE,CAEV;AAgBD,MAAM,WAAW,oBAAoB;IACnC,2DAA2D;IAC3D,YAAY,EAAE,MAAM,CAAC;IACrB,6EAA6E;IAC7E,KAAK,EAAE,MAAM,CAAC;CACf;AAED,yEAAyE;AACzE,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEtD;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,oBAAoB,GAAG,IAAI,CAM7E;AAED,MAAM,WAAW,sBAAsB;IACrC,8EAA8E;IAC9E,gBAAgB,EAAE,MAAM,CAAC;IACzB,YAAY,EAAE,sBAAsB,CAAC;IACrC,4CAA4C;IAC5C,MAAM,EAAE,kBAAkB,CAAC;IAC3B,+DAA+D;IAC/D,mBAAmB,EAAE,MAAM,CAAC;IAC5B,eAAe,EAAE,mBAAmB,CAAC;IACrC,oDAAoD;IACpD,YAAY,EAAE,MAAM,CAAC;IACrB,yEAAyE;IACzE,aAAa,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,MAAM,wBAAwB,GAChC;IAAE,QAAQ,EAAE,sBAAsB,CAAC;IAAC,KAAK,CAAC,EAAE,SAAS,CAAA;CAAE,GACvD;IAAE,QAAQ,CAAC,EAAE,SAAS,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAE5C;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CACnC,EAAE,EAAE,kBAAkB,EACtB,IAAI,EAAE,MAAM,GACX,wBAAwB,GAAG,IAAI,
|
|
1
|
+
{"version":3,"file":"relationship-fields.d.ts","sourceRoot":"","sources":["../../src/utils/relationship-fields.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EACV,kBAAkB,EAClB,mBAAmB,EACnB,sBAAsB,EACvB,MAAM,aAAa,CAAC;AAErB;;;;;;GAMG;AACH,wBAAgB,+BAA+B,CAC7C,IAAI,EAAE,MAAM,EACZ,YAAY,EAAE,sBAAsB,GACnC,MAAM,EAAE,CAEV;AAED;;;;;GAKG;AACH,wBAAgB,+BAA+B,CAC7C,IAAI,EAAE,MAAM,EACZ,YAAY,EAAE,sBAAsB,GACnC,MAAM,EAAE,CAEV;AAgBD,MAAM,WAAW,oBAAoB;IACnC,2DAA2D;IAC3D,YAAY,EAAE,MAAM,CAAC;IACrB,6EAA6E;IAC7E,KAAK,EAAE,MAAM,CAAC;CACf;AAED,yEAAyE;AACzE,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEtD;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,oBAAoB,GAAG,IAAI,CAM7E;AAED,MAAM,WAAW,sBAAsB;IACrC,8EAA8E;IAC9E,gBAAgB,EAAE,MAAM,CAAC;IACzB,YAAY,EAAE,sBAAsB,CAAC;IACrC,4CAA4C;IAC5C,MAAM,EAAE,kBAAkB,CAAC;IAC3B,+DAA+D;IAC/D,mBAAmB,EAAE,MAAM,CAAC;IAC5B,eAAe,EAAE,mBAAmB,CAAC;IACrC,oDAAoD;IACpD,YAAY,EAAE,MAAM,CAAC;IACrB,yEAAyE;IACzE,aAAa,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,MAAM,wBAAwB,GAChC;IAAE,QAAQ,EAAE,sBAAsB,CAAC;IAAC,KAAK,CAAC,EAAE,SAAS,CAAA;CAAE,GACvD;IAAE,QAAQ,CAAC,EAAE,SAAS,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAE5C;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CACnC,EAAE,EAAE,kBAAkB,EACtB,IAAI,EAAE,MAAM,GACX,wBAAwB,GAAG,IAAI,CAgEjC"}
|
|
@@ -86,6 +86,11 @@ export function resolveQualifiedField(ds, name) {
|
|
|
86
86
|
};
|
|
87
87
|
}
|
|
88
88
|
const target = relationship.target();
|
|
89
|
+
if (target.sqlSource) {
|
|
90
|
+
return {
|
|
91
|
+
error: `Relationship "${relationshipName}" on dataset "${ds.name}" targets "${target.name}", which reads a SQL source; SQL-sourced datasets can't be relationship targets yet (RFC 0028).`,
|
|
92
|
+
};
|
|
93
|
+
}
|
|
89
94
|
const targetDimension = Object.hasOwn(target.dimensions, field)
|
|
90
95
|
? target.dimensions[field]
|
|
91
96
|
: undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"relationship-measure-sql.d.ts","sourceRoot":"","sources":["../../src/utils/relationship-measure-sql.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"relationship-measure-sql.d.ts","sourceRoot":"","sources":["../../src/utils/relationship-measure-sql.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,kBAAkB,EAAmB,MAAM,aAAa,CAAC;AAEvE,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,gCAAgC,CAAC;AAIjF,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AAExE;;;;;;;;;;GAUG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,kBAAkB,EAAE,EAAE,EAAE,SAAS,MAAM,EAAE,EAAE,KAAK,EAAE,SAAS,MAAM,EAAE,EAAE,OAAO,EAAE,sBAAsB;;;EAsBlJ;AAgBD,wBAAgB,8BAA8B,CAAC,EAAE,EAAE,kBAAkB,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,0BAA0B,EAAE,OAAO,EAAE,sBAAsB;;;;EAexJ"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { assertTableSource } from './sql-dataset-source.js';
|
|
1
2
|
import { currentRowPredicate } from './dataset-source.js';
|
|
2
3
|
import { resolveRelationshipMeasure } from './relationship-measures.js';
|
|
3
4
|
import { resolveDimensionExpression } from '../query-planner.js';
|
|
@@ -44,6 +45,7 @@ export function relationshipJoinSource(target, to, names, dialect) {
|
|
|
44
45
|
}
|
|
45
46
|
/** The target's quoted table, read with `FINAL` when the target dataset requires it. */
|
|
46
47
|
function relationshipTargetTable(target, dialect) {
|
|
48
|
+
assertTableSource(target, 'a relationship target');
|
|
47
49
|
const quoted = dialect.quoteQualifiedName(target.source);
|
|
48
50
|
if (!target.rowResolution)
|
|
49
51
|
return quoted;
|
|
@@ -18,6 +18,8 @@ export declare function validateRelationshipTenantRuntime(ds: AnyDatasetInstance
|
|
|
18
18
|
* active and the joined target declares a `tenantKey`, an explicit filter on
|
|
19
19
|
* that column is rejected (the planner injects the tenant predicate instead).
|
|
20
20
|
*/
|
|
21
|
-
export declare function validateQualifiedFilter(ds: AnyDatasetInstance, filter: MetricFilter, context?: ExecutionContext
|
|
21
|
+
export declare function validateQualifiedFilter(ds: AnyDatasetInstance, filter: MetricFilter, context?: ExecutionContext,
|
|
22
|
+
/** Operators the allowlist must permit: the negation's under `not` (RFC 0029). */
|
|
23
|
+
operators?: readonly string[]): string | null;
|
|
22
24
|
export {};
|
|
23
25
|
//# sourceMappingURL=relationship-validation.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"relationship-validation.d.ts","sourceRoot":"","sources":["../../src/utils/relationship-validation.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"relationship-validation.d.ts","sourceRoot":"","sources":["../../src/utils/relationship-validation.ts"],"names":[],"mappings":"AAIA;;;GAGG;AAEH,OAAO,KAAK,EACV,kBAAkB,EAClB,YAAY,EACZ,gBAAgB,EAChB,YAAY,EACZ,WAAW,EACZ,MAAM,aAAa,CAAC;AAYrB,KAAK,iBAAiB,GAAG,IAAI,CAC3B,YAAY,GAAG,WAAW,EAC1B,YAAY,GAAG,SAAS,GAAG,SAAS,CACrC,GAAG,IAAI,CAAC,YAAY,EAAE,UAAU,CAAC,CAAC;AAEnC;;;;GAIG;AACH,wBAAgB,iCAAiC,CAC/C,EAAE,EAAE,kBAAkB,EACtB,KAAK,EAAE,iBAAiB,EACxB,OAAO,CAAC,EAAE,gBAAgB,GACzB,MAAM,GAAG,SAAS,CAqBpB;AAED;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,CACrC,EAAE,EAAE,kBAAkB,EACtB,MAAM,EAAE,YAAY,EACpB,OAAO,CAAC,EAAE,gBAAgB;AAC1B,kFAAkF;AAClF,SAAS,GAAE,SAAS,MAAM,EAAsB,GAC/C,MAAM,GAAG,IAAI,CA6Bf"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { filterLeaves } from './filter-tree.js';
|
|
1
2
|
import { resolveRelationshipReference } from './relationship-measures.js';
|
|
2
3
|
import { filterAllowsOperator } from './filter-operator-policy.js';
|
|
3
4
|
import { effectiveFilters } from './effective-filters.js';
|
|
@@ -17,7 +18,7 @@ export function validateRelationshipTenantRuntime(ds, query, context) {
|
|
|
17
18
|
const referenced = [
|
|
18
19
|
...(query.dimensions ?? []),
|
|
19
20
|
...(query.measures ?? []),
|
|
20
|
-
...(query.filters
|
|
21
|
+
...filterLeaves(query.filters).map((filter) => filter.field),
|
|
21
22
|
...(query.orderBy ?? []).map((order) => order.field),
|
|
22
23
|
...runtimeConstraints(context).map((constraint) => constraint.field),
|
|
23
24
|
].filter(isQualifiedField);
|
|
@@ -37,7 +38,9 @@ export function validateRelationshipTenantRuntime(ds, query, context) {
|
|
|
37
38
|
* active and the joined target declares a `tenantKey`, an explicit filter on
|
|
38
39
|
* that column is rejected (the planner injects the tenant predicate instead).
|
|
39
40
|
*/
|
|
40
|
-
export function validateQualifiedFilter(ds, filter, context
|
|
41
|
+
export function validateQualifiedFilter(ds, filter, context,
|
|
42
|
+
/** Operators the allowlist must permit: the negation's under `not` (RFC 0029). */
|
|
43
|
+
operators = [filter.operator]) {
|
|
41
44
|
const resolution = resolveQualifiedField(ds, filter.field);
|
|
42
45
|
if (!resolution) {
|
|
43
46
|
return null;
|
|
@@ -57,8 +60,9 @@ export function validateQualifiedFilter(ds, filter, context) {
|
|
|
57
60
|
|| definition.field !== targetDimensionName) {
|
|
58
61
|
return `Filter "${filter.field}" is not exposed by target dataset "${target.name}".`;
|
|
59
62
|
}
|
|
60
|
-
|
|
61
|
-
|
|
63
|
+
const refused = operators.find(operator => !filterAllowsOperator(definition, operator));
|
|
64
|
+
if (refused) {
|
|
65
|
+
return `Filter "${filter.field}" does not allow operator "${refused}".`;
|
|
62
66
|
}
|
|
63
67
|
return validateFilterValue(filter, targetDimension.fieldType);
|
|
64
68
|
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { AnyDatasetInstance, DatasetFilterNode, MetricFilter } from '../types.js';
|
|
2
|
+
/** Why `filter` can't be resolved, or `undefined` when it can. */
|
|
3
|
+
export declare function relativeDateFilterError(ds: AnyDatasetInstance, filter: MetricFilter): string | undefined;
|
|
4
|
+
/**
|
|
5
|
+
* The query's filters with every resolvable `inDateRange` replaced by its
|
|
6
|
+
* bounds. A comparison at the top level, or directly inside an `and`, becomes
|
|
7
|
+
* two comparisons there, so a top-level range still bounds the time axis; one
|
|
8
|
+
* under `or`/`not` becomes an `and` group. Unresolvable ones, and every
|
|
9
|
+
* filter of a malformed tree, are left for validation to report.
|
|
10
|
+
*/
|
|
11
|
+
export declare function resolveRelativeDateFilters(ds: AnyDatasetInstance, filters: DatasetFilterNode[] | undefined, now: Date, timezone: string | undefined): DatasetFilterNode[] | undefined;
|
|
12
|
+
/**
|
|
13
|
+
* `query` with every relative range resolved against `now` in the query's
|
|
14
|
+
* zone (UTC by default), as the dataset client prepares it. A query with an
|
|
15
|
+
* invalid zone is returned as written, for validation to report.
|
|
16
|
+
*/
|
|
17
|
+
export declare function withResolvedRelativeDates<T extends {
|
|
18
|
+
filters?: DatasetFilterNode[];
|
|
19
|
+
timezone?: string;
|
|
20
|
+
}>(ds: AnyDatasetInstance, query: T, now: Date): T;
|
|
21
|
+
//# sourceMappingURL=relative-date-filters.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"relative-date-filters.d.ts","sourceRoot":"","sources":["../../src/utils/relative-date-filters.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAcvF,kEAAkE;AAClE,wBAAgB,uBAAuB,CAAC,EAAE,EAAE,kBAAkB,EAAE,MAAM,EAAE,YAAY,GAAG,MAAM,GAAG,SAAS,CAaxG;AAED;;;;;;GAMG;AACH,wBAAgB,0BAA0B,CACxC,EAAE,EAAE,kBAAkB,EACtB,OAAO,EAAE,iBAAiB,EAAE,GAAG,SAAS,EACxC,GAAG,EAAE,IAAI,EACT,QAAQ,EAAE,MAAM,GAAG,SAAS,GAC3B,iBAAiB,EAAE,GAAG,SAAS,CAqCjC;AAED;;;;GAIG;AACH,wBAAgB,yBAAyB,CAAC,CAAC,SAAS;IAAE,OAAO,CAAC,EAAE,iBAAiB,EAAE,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAE,EACtG,EAAE,EAAE,kBAAkB,EACtB,KAAK,EAAE,CAAC,EACR,GAAG,EAAE,IAAI,GACR,CAAC,CAIH"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { isProtocolRelativeDateRange } from '@hypequery/protocol';
|
|
2
|
+
import { filterTreeErrors, isFilterGroup } from './filter-tree.js';
|
|
3
|
+
import { datasetTimeKeys } from './dataset-time-keys.js';
|
|
4
|
+
import { isTimeKeyFilter, queryTimezoneErrors } from './query-timezone.js';
|
|
5
|
+
import { resolveRelativeDateRange } from './relative-date-range.js';
|
|
6
|
+
/**
|
|
7
|
+
* `inDateRange` caller filters (RFC 0029). The client resolves each one to a
|
|
8
|
+
* half-open `gte`/`lt` pair once per query, before validation, caching and
|
|
9
|
+
* planning, so every later stage sees ordinary comparisons on the time axis.
|
|
10
|
+
*/
|
|
11
|
+
const GRAMMAR = 'today, yesterday, this|last <unit>, last <N> <unit>s or month|quarter|year to date (unit: day, week, month, quarter, year)';
|
|
12
|
+
/** Why `filter` can't be resolved, or `undefined` when it can. */
|
|
13
|
+
export function relativeDateFilterError(ds, filter) {
|
|
14
|
+
const axes = datasetTimeKeys(ds);
|
|
15
|
+
// Compared by backing column, as the planner reads the axis: a `timeKey`
|
|
16
|
+
// may name a column that a differently named dimension reads.
|
|
17
|
+
if (!isTimeKeyFilter(ds, filter.field)) {
|
|
18
|
+
return axes.length === 0
|
|
19
|
+
? `Filter "${filter.field}" cannot use "inDateRange": dataset "${ds.name}" has no time axis.`
|
|
20
|
+
: `Filter "${filter.field}" cannot use "inDateRange": it applies only to a time axis (${axes.join(', ')}).`;
|
|
21
|
+
}
|
|
22
|
+
if (!isProtocolRelativeDateRange(filter.value)) {
|
|
23
|
+
return `Filter "${filter.field}": ${JSON.stringify(filter.value) ?? String(filter.value)} is not a relative date range. Use ${GRAMMAR}.`;
|
|
24
|
+
}
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* The query's filters with every resolvable `inDateRange` replaced by its
|
|
29
|
+
* bounds. A comparison at the top level, or directly inside an `and`, becomes
|
|
30
|
+
* two comparisons there, so a top-level range still bounds the time axis; one
|
|
31
|
+
* under `or`/`not` becomes an `and` group. Unresolvable ones, and every
|
|
32
|
+
* filter of a malformed tree, are left for validation to report.
|
|
33
|
+
*/
|
|
34
|
+
export function resolveRelativeDateFilters(ds, filters, now, timezone) {
|
|
35
|
+
// A malformed tree (a null filter, a cycle, a group nested too deep) is left
|
|
36
|
+
// as written: validation reports it, and walking it here could throw.
|
|
37
|
+
if (!Array.isArray(filters) || filterTreeErrors(filters).length > 0)
|
|
38
|
+
return filters;
|
|
39
|
+
let changed = false;
|
|
40
|
+
const bounds = (filter) => {
|
|
41
|
+
if (filter.operator !== 'inDateRange' || typeof filter.field !== 'string' || relativeDateFilterError(ds, filter)) {
|
|
42
|
+
return undefined;
|
|
43
|
+
}
|
|
44
|
+
const range = resolveRelativeDateRange(filter.value, now, timezone ?? 'UTC');
|
|
45
|
+
changed = true;
|
|
46
|
+
return [
|
|
47
|
+
{ field: filter.field, operator: 'gte', value: range.start },
|
|
48
|
+
{ field: filter.field, operator: 'lt', value: range.end },
|
|
49
|
+
];
|
|
50
|
+
};
|
|
51
|
+
// Within a conjunction (the top level, an `and`), bounds splice in place.
|
|
52
|
+
const conjunction = (nodes) => nodes.flatMap(node => {
|
|
53
|
+
if (!isFilterGroup(node))
|
|
54
|
+
return bounds(node) ?? [node];
|
|
55
|
+
return [group(node)];
|
|
56
|
+
});
|
|
57
|
+
const single = (node) => {
|
|
58
|
+
if (!isFilterGroup(node)) {
|
|
59
|
+
const resolved = bounds(node);
|
|
60
|
+
return resolved ? { and: resolved } : node;
|
|
61
|
+
}
|
|
62
|
+
return group(node);
|
|
63
|
+
};
|
|
64
|
+
// The tree is well formed here: each group has exactly one key.
|
|
65
|
+
const group = (node) => {
|
|
66
|
+
const record = node;
|
|
67
|
+
if (record.and)
|
|
68
|
+
return { and: conjunction(record.and) };
|
|
69
|
+
if (record.or)
|
|
70
|
+
return { or: record.or.map(single) };
|
|
71
|
+
return { not: single(record.not) };
|
|
72
|
+
};
|
|
73
|
+
const resolved = conjunction(filters);
|
|
74
|
+
return changed ? resolved : filters;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* `query` with every relative range resolved against `now` in the query's
|
|
78
|
+
* zone (UTC by default), as the dataset client prepares it. A query with an
|
|
79
|
+
* invalid zone is returned as written, for validation to report.
|
|
80
|
+
*/
|
|
81
|
+
export function withResolvedRelativeDates(ds, query, now) {
|
|
82
|
+
if (!Array.isArray(query.filters) || queryTimezoneErrors(query.timezone).length > 0)
|
|
83
|
+
return query;
|
|
84
|
+
const filters = resolveRelativeDateFilters(ds, query.filters, now, query.timezone);
|
|
85
|
+
return filters === query.filters ? query : { ...query, filters };
|
|
86
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Relative date ranges (RFC 0029): `today`, `last 30 days`, `this quarter`
|
|
3
|
+
* and the rest of the grammar, resolved to half-open local-date bounds.
|
|
4
|
+
*/
|
|
5
|
+
/** Half-open `[start, end)` local dates, each `YYYY-MM-DD`. */
|
|
6
|
+
export interface ResolvedDateRange {
|
|
7
|
+
readonly start: string;
|
|
8
|
+
readonly end: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Resolve a relative range at `now` in `timezone`, or `undefined` when the
|
|
12
|
+
* value is not in the grammar.
|
|
13
|
+
*
|
|
14
|
+
* - `this <unit>` includes the whole current period, future days included;
|
|
15
|
+
* - `last <unit>` and `last N <unit>s` are whole periods ending where the
|
|
16
|
+
* current one starts, so they exclude it (`last 7 days` ends yesterday);
|
|
17
|
+
* - `<unit> to date` runs from the current period's start through today.
|
|
18
|
+
*/
|
|
19
|
+
export declare function resolveRelativeDateRange(value: unknown, now: Date, timezone: string): ResolvedDateRange | undefined;
|
|
20
|
+
//# sourceMappingURL=relative-date-range.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"relative-date-range.d.ts","sourceRoot":"","sources":["../../src/utils/relative-date-range.ts"],"names":[],"mappings":"AAEA;;;GAGG;AAEH,+DAA+D;AAC/D,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;CACtB;AA+CD;;;;;;;;GAQG;AACH,wBAAgB,wBAAwB,CACtC,KAAK,EAAE,OAAO,EACd,GAAG,EAAE,IAAI,EACT,QAAQ,EAAE,MAAM,GACf,iBAAiB,GAAG,SAAS,CAqB/B"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { parseProtocolRelativeDateRange } from '@hypequery/protocol';
|
|
2
|
+
/** The earliest bound a range resolves to: ClickHouse stores nothing earlier. */
|
|
3
|
+
const EARLIEST = Date.UTC(1900, 0, 1);
|
|
4
|
+
const DAY_MS = 86_400_000;
|
|
5
|
+
/** Today's calendar date in `timezone`, as a UTC-midnight timestamp. */
|
|
6
|
+
function localToday(now, timezone) {
|
|
7
|
+
const parts = new Intl.DateTimeFormat('en-US', {
|
|
8
|
+
timeZone: timezone, year: 'numeric', month: '2-digit', day: '2-digit',
|
|
9
|
+
}).formatToParts(now);
|
|
10
|
+
const part = (type) => Number(parts.find(entry => entry.type === type).value);
|
|
11
|
+
return Date.UTC(part('year'), part('month') - 1, part('day'));
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* The first day of the unit containing `day`. Weeks start on Sunday, the day
|
|
15
|
+
* the `week` grain truncates to, so `this week` is always one `week` bucket.
|
|
16
|
+
*/
|
|
17
|
+
function startOf(unit, day) {
|
|
18
|
+
const date = new Date(day);
|
|
19
|
+
const year = date.getUTCFullYear();
|
|
20
|
+
const month = date.getUTCMonth();
|
|
21
|
+
switch (unit) {
|
|
22
|
+
case 'day': return day;
|
|
23
|
+
case 'week': return day - date.getUTCDay() * DAY_MS;
|
|
24
|
+
case 'month': return Date.UTC(year, month, 1);
|
|
25
|
+
case 'quarter': return Date.UTC(year, Math.floor(month / 3) * 3, 1);
|
|
26
|
+
case 'year': return Date.UTC(year, 0, 1);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
/** `start` moved by `count` units; `start` is always the first day of its unit. */
|
|
30
|
+
function shift(unit, start, count) {
|
|
31
|
+
if (unit === 'day')
|
|
32
|
+
return start + count * DAY_MS;
|
|
33
|
+
if (unit === 'week')
|
|
34
|
+
return start + count * 7 * DAY_MS;
|
|
35
|
+
const months = count * (unit === 'month' ? 1 : unit === 'quarter' ? 3 : 12);
|
|
36
|
+
const date = new Date(start);
|
|
37
|
+
return Date.UTC(date.getUTCFullYear(), date.getUTCMonth() + months, 1);
|
|
38
|
+
}
|
|
39
|
+
function formatDate(day) {
|
|
40
|
+
const date = new Date(Math.max(day, EARLIEST));
|
|
41
|
+
const pad = (value, width = 2) => String(value).padStart(width, '0');
|
|
42
|
+
return `${pad(date.getUTCFullYear(), 4)}-${pad(date.getUTCMonth() + 1)}-${pad(date.getUTCDate())}`;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Resolve a relative range at `now` in `timezone`, or `undefined` when the
|
|
46
|
+
* value is not in the grammar.
|
|
47
|
+
*
|
|
48
|
+
* - `this <unit>` includes the whole current period, future days included;
|
|
49
|
+
* - `last <unit>` and `last N <unit>s` are whole periods ending where the
|
|
50
|
+
* current one starts, so they exclude it (`last 7 days` ends yesterday);
|
|
51
|
+
* - `<unit> to date` runs from the current period's start through today.
|
|
52
|
+
*/
|
|
53
|
+
export function resolveRelativeDateRange(value, now, timezone) {
|
|
54
|
+
const range = parseProtocolRelativeDateRange(value);
|
|
55
|
+
if (!range)
|
|
56
|
+
return undefined;
|
|
57
|
+
const today = localToday(now, timezone);
|
|
58
|
+
const tomorrow = today + DAY_MS;
|
|
59
|
+
switch (range.kind) {
|
|
60
|
+
case 'today':
|
|
61
|
+
return { start: formatDate(today), end: formatDate(tomorrow) };
|
|
62
|
+
case 'yesterday':
|
|
63
|
+
return { start: formatDate(today - DAY_MS), end: formatDate(today) };
|
|
64
|
+
case 'this': {
|
|
65
|
+
const start = startOf(range.unit, today);
|
|
66
|
+
return { start: formatDate(start), end: formatDate(shift(range.unit, start, 1)) };
|
|
67
|
+
}
|
|
68
|
+
case 'last': {
|
|
69
|
+
const current = startOf(range.unit, today);
|
|
70
|
+
return { start: formatDate(shift(range.unit, current, -range.count)), end: formatDate(current) };
|
|
71
|
+
}
|
|
72
|
+
case 'toDate':
|
|
73
|
+
return { start: formatDate(startOf(range.unit, today)), end: formatDate(tomorrow) };
|
|
74
|
+
}
|
|
75
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { RetentionSpec } from './event-operation-spec.js';
|
|
2
|
+
import { type EventResultRow } from './event-result-values.js';
|
|
3
|
+
/**
|
|
4
|
+
* Expand one row per cohort (`_hq_size`, `_hq_retained[]`, `_hq_observable`)
|
|
5
|
+
* into one row per observable period (RFC 0027): breakdown values, `cohort`,
|
|
6
|
+
* `period`, `entities`, `retained` and `rate`.
|
|
7
|
+
*/
|
|
8
|
+
export declare function retentionResultRows(spec: RetentionSpec, breakdownAliases: readonly string[], rows: readonly Record<string, unknown>[]): EventResultRow[];
|
|
9
|
+
//# sourceMappingURL=retention-rows.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"retention-rows.d.ts","sourceRoot":"","sources":["../../src/utils/retention-rows.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,EAA6B,KAAK,cAAc,EAAyB,MAAM,0BAA0B,CAAC;AAEjH;;;;GAIG;AACH,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,aAAa,EACnB,gBAAgB,EAAE,SAAS,MAAM,EAAE,EACnC,IAAI,EAAE,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,GACvC,cAAc,EAAE,CAyBlB"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { countValue, ratio, scalar } from './event-result-values.js';
|
|
2
|
+
/**
|
|
3
|
+
* Expand one row per cohort (`_hq_size`, `_hq_retained[]`, `_hq_observable`)
|
|
4
|
+
* into one row per observable period (RFC 0027): breakdown values, `cohort`,
|
|
5
|
+
* `period`, `entities`, `retained` and `rate`.
|
|
6
|
+
*/
|
|
7
|
+
export function retentionResultRows(spec, breakdownAliases, rows) {
|
|
8
|
+
const result = [];
|
|
9
|
+
for (const row of rows) {
|
|
10
|
+
const entities = countValue(row._hq_size);
|
|
11
|
+
const retained = row._hq_retained;
|
|
12
|
+
if (!Array.isArray(retained) || retained.length !== spec.periods) {
|
|
13
|
+
throw new Error('The executor returned retention counts of the wrong length.');
|
|
14
|
+
}
|
|
15
|
+
const observable = Math.min(countValue(row._hq_observable), spec.periods);
|
|
16
|
+
const group = Object.fromEntries(spec.breakdown.map((name, index) => [name, scalar(row[breakdownAliases[index]])]));
|
|
17
|
+
for (let period = 1; period <= observable; period += 1) {
|
|
18
|
+
const count = countValue(retained[period - 1]);
|
|
19
|
+
result.push(Object.freeze({
|
|
20
|
+
...group,
|
|
21
|
+
cohort: scalar(row._hq_cohort),
|
|
22
|
+
period,
|
|
23
|
+
entities,
|
|
24
|
+
retained: count,
|
|
25
|
+
rate: ratio(count, entities),
|
|
26
|
+
}));
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return result;
|
|
30
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { AnyDatasetInstance } from '../types.js';
|
|
2
|
+
import type { DatasetQueryExecutionOptions } from '../dataset-query.js';
|
|
3
|
+
import { buildEventSourceSql } from './event-source-sql.js';
|
|
4
|
+
import type { RetentionSpec } from './event-operation-spec.js';
|
|
5
|
+
import type { PlannedEventStatement } from './funnel-sql.js';
|
|
6
|
+
/**
|
|
7
|
+
* Plan retention (RFC 0027) as one statement: scan → per entity, the bucket
|
|
8
|
+
* of its first start event and the set of buckets it returned in → per
|
|
9
|
+
* cohort, its size and how many returned in each of the next N buckets →
|
|
10
|
+
* ranked breakdown groups.
|
|
11
|
+
*
|
|
12
|
+
* Each cohort also reports how many of its periods end by the range end;
|
|
13
|
+
* later ones are not fully observed and get no row.
|
|
14
|
+
*/
|
|
15
|
+
export declare function buildRetentionSql(ds: AnyDatasetInstance, spec: RetentionSpec, options: DatasetQueryExecutionOptions, readsFinal: (joinCtx: ReturnType<typeof buildEventSourceSql>['joinCtx']) => boolean): PlannedEventStatement;
|
|
16
|
+
//# sourceMappingURL=retention-sql.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"retention-sql.d.ts","sourceRoot":"","sources":["../../src/utils/retention-sql.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,qBAAqB,CAAC;AAIxE,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAM5D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAE7D;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAC/B,EAAE,EAAE,kBAAkB,EACtB,IAAI,EAAE,aAAa,EACnB,OAAO,EAAE,4BAA4B,EACrC,UAAU,EAAE,CAAC,OAAO,EAAE,UAAU,CAAC,OAAO,mBAAmB,CAAC,CAAC,SAAS,CAAC,KAAK,OAAO,GAClF,qBAAqB,CAkDvB"}
|