@malloydata/malloy 0.0.391 → 0.0.393
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/api/asynchronous.js +0 -3
- package/dist/api/foundation/compile.d.ts +1 -1
- package/dist/api/foundation/config.d.ts +80 -8
- package/dist/api/foundation/config.js +151 -69
- package/dist/api/foundation/config_compile.js +27 -35
- package/dist/api/foundation/config_discover.js +5 -9
- package/dist/api/foundation/config_overlays.d.ts +6 -0
- package/dist/api/foundation/config_overlays.js +12 -0
- package/dist/api/foundation/config_resolve.d.ts +4 -1
- package/dist/api/foundation/config_resolve.js +64 -4
- package/dist/api/foundation/core.d.ts +75 -2
- package/dist/api/foundation/core.js +104 -6
- package/dist/api/foundation/index.d.ts +2 -0
- package/dist/api/foundation/readers.js +1 -1
- package/dist/api/foundation/runtime.d.ts +68 -2
- package/dist/api/foundation/runtime.js +212 -10
- package/dist/api/foundation/types.d.ts +2 -1
- package/dist/index.d.ts +3 -1
- package/dist/lang/ast/ast-utils.js +0 -1
- package/dist/lang/ast/expressions/expr-aggregate-function.d.ts +1 -1
- package/dist/lang/ast/expressions/expr-aggregate-function.js +9 -8
- package/dist/lang/ast/expressions/expr-coalesce.d.ts +1 -1
- package/dist/lang/ast/expressions/expr-coalesce.js +2 -3
- package/dist/lang/ast/expressions/expr-count-distinct.js +1 -1
- package/dist/lang/ast/expressions/expr-count.js +6 -4
- package/dist/lang/ast/expressions/expr-filter-expr.js +0 -1
- package/dist/lang/ast/expressions/expr-func.js +9 -4
- package/dist/lang/ast/expressions/expr-given.d.ts +18 -0
- package/dist/lang/ast/expressions/expr-given.js +69 -0
- package/dist/lang/ast/expressions/expr-granular-time.d.ts +1 -1
- package/dist/lang/ast/expressions/expr-id-reference.js +3 -2
- package/dist/lang/ast/expressions/expr-now.js +0 -1
- package/dist/lang/ast/expressions/expr-props.d.ts +132 -132
- package/dist/lang/ast/expressions/expr-props.js +2 -2
- package/dist/lang/ast/expressions/expr-ungroup.d.ts +1 -1
- package/dist/lang/ast/expressions/expr-ungroup.js +4 -4
- package/dist/lang/ast/expressions/for-range.d.ts +1 -1
- package/dist/lang/ast/expressions/function-ordering.d.ts +1 -1
- package/dist/lang/ast/expressions/function-ordering.js +2 -2
- package/dist/lang/ast/expressions/time-literal.d.ts +3 -3
- package/dist/lang/ast/field-space/include-utils.js +2 -2
- package/dist/lang/ast/field-space/index-field-space.js +18 -23
- package/dist/lang/ast/field-space/passthrough-space.d.ts +1 -1
- package/dist/lang/ast/field-space/query-spaces.d.ts +6 -2
- package/dist/lang/ast/field-space/query-spaces.js +29 -19
- package/dist/lang/ast/field-space/reference-field.js +1 -1
- package/dist/lang/ast/field-space/rename-space-field.d.ts +1 -1
- package/dist/lang/ast/field-space/rename-space-field.js +2 -2
- package/dist/lang/ast/field-space/struct-space-field-base.js +2 -3
- package/dist/lang/ast/index.d.ts +2 -0
- package/dist/lang/ast/index.js +2 -0
- package/dist/lang/ast/query-builders/index-builder.d.ts +1 -1
- package/dist/lang/ast/query-builders/index-builder.js +4 -3
- package/dist/lang/ast/query-builders/reduce-builder.d.ts +2 -2
- package/dist/lang/ast/query-builders/reduce-builder.js +4 -5
- package/dist/lang/ast/query-elements/query-arrow.js +3 -2
- package/dist/lang/ast/query-elements/query-base.d.ts +1 -1
- package/dist/lang/ast/query-elements/query-base.js +1 -1
- package/dist/lang/ast/query-elements/query-refine.js +3 -1
- package/dist/lang/ast/query-items/field-declaration.js +2 -2
- package/dist/lang/ast/query-properties/drill.js +6 -6
- package/dist/lang/ast/query-properties/filters.js +2 -2
- package/dist/lang/ast/query-properties/nest.js +3 -3
- package/dist/lang/ast/source-elements/composite-source.js +5 -3
- package/dist/lang/ast/source-elements/named-source.js +4 -0
- package/dist/lang/ast/source-elements/sql-source.js +2 -2
- package/dist/lang/ast/source-elements/table-source.js +3 -1
- package/dist/lang/ast/source-properties/join.js +4 -4
- package/dist/lang/ast/source-query-elements/sq-reference.js +2 -1
- package/dist/lang/ast/statements/define-given.d.ts +23 -0
- package/dist/lang/ast/statements/define-given.js +163 -0
- package/dist/lang/ast/statements/import-statement.js +72 -9
- package/dist/lang/ast/typedesc-utils.d.ts +3 -1
- package/dist/lang/ast/typedesc-utils.js +4 -47
- package/dist/lang/ast/types/expr-value.js +2 -3
- package/dist/lang/ast/types/expression-def.d.ts +2 -2
- package/dist/lang/ast/types/expression-def.js +2 -2
- package/dist/lang/ast/types/malloy-element.d.ts +5 -15
- package/dist/lang/ast/types/malloy-element.js +113 -1
- package/dist/lang/ast/types/space-field.js +7 -9
- package/dist/lang/ast/view-elements/reference-view.js +6 -5
- package/dist/lang/ast/view-elements/refine-utils.js +1 -1
- package/dist/lang/composite-source-utils.d.ts +30 -15
- package/dist/lang/composite-source-utils.js +234 -64
- package/dist/lang/lib/Malloy/MalloyLexer.d.ts +171 -169
- package/dist/lang/lib/Malloy/MalloyLexer.js +1194 -1178
- package/dist/lang/lib/Malloy/MalloyParser.d.ts +408 -334
- package/dist/lang/lib/Malloy/MalloyParser.js +3062 -2561
- package/dist/lang/lib/Malloy/MalloyParserListener.d.ts +68 -0
- package/dist/lang/lib/Malloy/MalloyParserVisitor.d.ts +43 -0
- package/dist/lang/malloy-to-ast.d.ts +13 -1
- package/dist/lang/malloy-to-ast.js +90 -11
- package/dist/lang/parse-log.d.ts +8 -0
- package/dist/lang/prettify/filter-type.d.ts +3 -0
- package/dist/lang/prettify/filter-type.js +38 -0
- package/dist/lang/prettify/formatter.js +6 -0
- package/dist/lang/prettify/inline-renderer.js +20 -0
- package/dist/lang/prettify/rules.d.ts +1 -1
- package/dist/lang/prettify/rules.js +1 -0
- package/dist/lang/prettify/sections.js +2 -0
- package/dist/lang/prettify/tokens.js +2 -0
- package/dist/lang/test/expr-to-str.js +2 -0
- package/dist/lang/test/parse-expects.d.ts +1 -0
- package/dist/lang/test/parse-expects.js +27 -10
- package/dist/model/constant_expression_compiler.js +1 -0
- package/dist/model/expression_compiler.d.ts +2 -1
- package/dist/model/expression_compiler.js +41 -1
- package/dist/model/given_binding.d.ts +2 -0
- package/dist/model/given_binding.js +204 -0
- package/dist/model/index.d.ts +1 -1
- package/dist/model/index.js +2 -1
- package/dist/model/malloy_types.d.ts +163 -36
- package/dist/model/malloy_types.js +97 -0
- package/dist/model/query_model_contract.d.ts +2 -1
- package/dist/model/query_model_impl.d.ts +2 -1
- package/dist/model/query_model_impl.js +7 -0
- package/dist/model/query_node.d.ts +2 -1
- package/dist/model/source_def_utils.d.ts +2 -1
- package/dist/model/source_def_utils.js +4 -0
- package/dist/model/utils.d.ts +14 -1
- package/dist/model/utils.js +41 -0
- package/dist/to_stable.js +1 -1
- package/dist/util/closest_match.d.ts +9 -0
- package/dist/util/closest_match.js +47 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +4 -4
|
@@ -75,11 +75,21 @@ const refine_from_space_field_1 = require("./refine-from-space-field");
|
|
|
75
75
|
* created and paired when a QueryOperationSpace is created.
|
|
76
76
|
*/
|
|
77
77
|
class QueryOperationSpace extends refined_space_1.RefinedSpace {
|
|
78
|
-
get
|
|
79
|
-
if (this.
|
|
80
|
-
throw new Error('
|
|
78
|
+
get refSummary() {
|
|
79
|
+
if (!this._refSummaryComputed) {
|
|
80
|
+
throw new Error('Ref summary accessed before computed');
|
|
81
81
|
}
|
|
82
|
-
return this.
|
|
82
|
+
return this._refSummary;
|
|
83
|
+
}
|
|
84
|
+
set refSummary(rs) {
|
|
85
|
+
this._refSummary = rs;
|
|
86
|
+
this._refSummaryComputed = true;
|
|
87
|
+
}
|
|
88
|
+
get fieldUsage() {
|
|
89
|
+
return model.fieldUsageFrom(this.refSummary);
|
|
90
|
+
}
|
|
91
|
+
get givenUsage() {
|
|
92
|
+
return model.givenUsageFrom(this.refSummary);
|
|
83
93
|
}
|
|
84
94
|
constructor(queryInputSpace, refineThis, nestParent, astEl) {
|
|
85
95
|
super(queryInputSpace.emptyStructDef());
|
|
@@ -88,10 +98,13 @@ class QueryOperationSpace extends refined_space_1.RefinedSpace {
|
|
|
88
98
|
this.expandedWild = new Map();
|
|
89
99
|
this.drillDimensions = [];
|
|
90
100
|
this.compositeFieldUsers = [];
|
|
91
|
-
//
|
|
92
|
-
// (or `getPipeSegment` for index segments)
|
|
93
|
-
//
|
|
94
|
-
|
|
101
|
+
// Reference summary is not computed until `queryFieldDefs` is called
|
|
102
|
+
// (or `getPipeSegment` for index segments). Reading it before that throws;
|
|
103
|
+
// assigning to it (via the setter) flips the computed flag.
|
|
104
|
+
// `undefined` is a valid post-computation value, so the flag is what
|
|
105
|
+
// distinguishes "not yet computed" from "computed and empty".
|
|
106
|
+
this._refSummary = undefined;
|
|
107
|
+
this._refSummaryComputed = false;
|
|
95
108
|
this.exprSpace = new query_input_space_1.QueryInputSpace(queryInputSpace.structDef(), this, queryInputSpace.accessProtectionLevel());
|
|
96
109
|
if (refineThis)
|
|
97
110
|
this.addRefineFromFields(refineThis);
|
|
@@ -181,7 +194,7 @@ class QueryOperationSpace extends refined_space_1.RefinedSpace {
|
|
|
181
194
|
}
|
|
182
195
|
}
|
|
183
196
|
addFieldUserFromFilter(filter) {
|
|
184
|
-
if (filter.
|
|
197
|
+
if (filter.refSummary !== undefined) {
|
|
185
198
|
this.compositeFieldUsers.push({ type: 'filter', filter });
|
|
186
199
|
}
|
|
187
200
|
}
|
|
@@ -333,18 +346,15 @@ class QuerySpace extends QueryOperationSpace {
|
|
|
333
346
|
return sourceDef;
|
|
334
347
|
}
|
|
335
348
|
translateQueryFields() {
|
|
336
|
-
var _a;
|
|
337
349
|
if (this.translatedQueryFields) {
|
|
338
350
|
return this.translatedQueryFields;
|
|
339
351
|
}
|
|
340
352
|
const fields = [];
|
|
341
|
-
let
|
|
353
|
+
let refSummary = undefined;
|
|
342
354
|
for (const user of this.compositeFieldUsers) {
|
|
343
|
-
let
|
|
355
|
+
let nextRefSummary = undefined;
|
|
344
356
|
if (user.type === 'filter') {
|
|
345
|
-
|
|
346
|
-
nextFieldUsage = user.filter.fieldUsage;
|
|
347
|
-
}
|
|
357
|
+
nextRefSummary = user.filter.refSummary;
|
|
348
358
|
}
|
|
349
359
|
else {
|
|
350
360
|
const { name, field } = user;
|
|
@@ -359,13 +369,13 @@ class QuerySpace extends QueryOperationSpace {
|
|
|
359
369
|
},
|
|
360
370
|
typeDesc,
|
|
361
371
|
});
|
|
362
|
-
|
|
372
|
+
nextRefSummary = typeDesc.refSummary;
|
|
363
373
|
}
|
|
364
374
|
else {
|
|
365
375
|
const queryFieldDef = field.getQueryFieldDef(this.exprSpace);
|
|
366
376
|
if (queryFieldDef) {
|
|
367
377
|
const typeDesc = field.typeDesc();
|
|
368
|
-
|
|
378
|
+
nextRefSummary = typeDesc.refSummary;
|
|
369
379
|
// Filter out fields whose type is 'error', which means that a totally bad field
|
|
370
380
|
// isn't sent to the compiler, where it will wig out.
|
|
371
381
|
// TODO Figure out how to make errors generated by `canContain` go in the right place,
|
|
@@ -382,9 +392,9 @@ class QuerySpace extends QueryOperationSpace {
|
|
|
382
392
|
}
|
|
383
393
|
}
|
|
384
394
|
}
|
|
385
|
-
|
|
395
|
+
refSummary = (0, composite_source_utils_1.mergeRefSummaries)(refSummary, nextRefSummary);
|
|
386
396
|
}
|
|
387
|
-
this.
|
|
397
|
+
this.refSummary = refSummary;
|
|
388
398
|
for (const drillDimension of this.drillDimensions) {
|
|
389
399
|
if (!drillDimension.satisfied) {
|
|
390
400
|
drillDimension.firstDrill.logError('illegal-drill', `Must provide a value for all dimensions in a view when drilling: missing \`${drillDimension.dimensionPath.join('.')}\``);
|
|
@@ -139,7 +139,7 @@ class ReferenceField extends space_field_1.SpaceField {
|
|
|
139
139
|
};
|
|
140
140
|
this.memoTypeDesc = {
|
|
141
141
|
...typeDesc,
|
|
142
|
-
fieldUsage: [usage],
|
|
142
|
+
refSummary: { fieldUsage: [usage] },
|
|
143
143
|
requiresGroupBy: (_a = typeDesc.requiresGroupBy) === null || _a === void 0 ? void 0 : _a.map(gb => ({
|
|
144
144
|
...gb,
|
|
145
145
|
path: [...joinPath, ...gb.path],
|
|
@@ -7,5 +7,5 @@ export declare class RenameSpaceField extends SpaceField {
|
|
|
7
7
|
private note;
|
|
8
8
|
constructor(otherField: SpaceField, newName: string, location: DocumentLocation, note: Annotation | undefined);
|
|
9
9
|
fieldDef(): FieldDef | undefined;
|
|
10
|
-
typeDesc(): import("
|
|
10
|
+
typeDesc(): import("../../..").TypeDesc;
|
|
11
11
|
}
|
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
*/
|
|
24
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
25
|
exports.RenameSpaceField = void 0;
|
|
26
|
+
const malloy_types_1 = require("../../../model/malloy_types");
|
|
26
27
|
const space_field_1 = require("../types/space-field");
|
|
27
28
|
class RenameSpaceField extends space_field_1.SpaceField {
|
|
28
29
|
constructor(otherField, newName, location, note) {
|
|
@@ -33,7 +34,6 @@ class RenameSpaceField extends space_field_1.SpaceField {
|
|
|
33
34
|
this.note = note;
|
|
34
35
|
}
|
|
35
36
|
fieldDef() {
|
|
36
|
-
var _a;
|
|
37
37
|
const returnFieldDef = this.otherField.fieldDef();
|
|
38
38
|
if (returnFieldDef === undefined) {
|
|
39
39
|
return undefined;
|
|
@@ -53,7 +53,7 @@ class RenameSpaceField extends space_field_1.SpaceField {
|
|
|
53
53
|
...returnFieldDef,
|
|
54
54
|
as: this.newName,
|
|
55
55
|
location: this.location,
|
|
56
|
-
|
|
56
|
+
refSummary: (0, malloy_types_1.mapFieldUsage)(returnFieldDef.refSummary, u => {
|
|
57
57
|
var _a;
|
|
58
58
|
return ({
|
|
59
59
|
...u,
|
|
@@ -75,20 +75,19 @@ class StructSpaceFieldBase extends space_field_1.SpaceField {
|
|
|
75
75
|
};
|
|
76
76
|
}
|
|
77
77
|
typeDesc() {
|
|
78
|
-
var _a, _b;
|
|
79
78
|
if ((0, malloy_types_1.isSourceDef)(this.structDef)) {
|
|
80
79
|
return {
|
|
81
80
|
type: this.structDef.type,
|
|
82
81
|
evalSpace: 'input',
|
|
83
82
|
expressionType: 'scalar',
|
|
84
|
-
|
|
83
|
+
refSummary: this.structDef.refSummary,
|
|
85
84
|
};
|
|
86
85
|
}
|
|
87
86
|
return {
|
|
88
87
|
...TDU.atomicDef(this.structDef),
|
|
89
88
|
evalSpace: 'input',
|
|
90
89
|
expressionType: 'scalar',
|
|
91
|
-
|
|
90
|
+
refSummary: this.structDef.refSummary,
|
|
92
91
|
};
|
|
93
92
|
}
|
|
94
93
|
}
|
package/dist/lang/ast/index.d.ts
CHANGED
|
@@ -70,6 +70,8 @@ export * from './statements/import-statement';
|
|
|
70
70
|
export * from './query-properties/extend';
|
|
71
71
|
export * from './parameters/argument';
|
|
72
72
|
export * from './parameters/has-parameter';
|
|
73
|
+
export * from './statements/define-given';
|
|
74
|
+
export * from './expressions/expr-given';
|
|
73
75
|
export * from './query-elements/anonymous-query';
|
|
74
76
|
export * from './query-elements/query-refine';
|
|
75
77
|
export * from './query-elements/query-arrow';
|
package/dist/lang/ast/index.js
CHANGED
|
@@ -108,6 +108,8 @@ __exportStar(require("./statements/import-statement"), exports);
|
|
|
108
108
|
__exportStar(require("./query-properties/extend"), exports);
|
|
109
109
|
__exportStar(require("./parameters/argument"), exports);
|
|
110
110
|
__exportStar(require("./parameters/has-parameter"), exports);
|
|
111
|
+
__exportStar(require("./statements/define-given"), exports);
|
|
112
|
+
__exportStar(require("./expressions/expr-given"), exports);
|
|
111
113
|
__exportStar(require("./query-elements/anonymous-query"), exports);
|
|
112
114
|
__exportStar(require("./query-elements/query-refine"), exports);
|
|
113
115
|
__exportStar(require("./query-elements/query-arrow"), exports);
|
|
@@ -19,6 +19,6 @@ export declare class IndexBuilder implements QueryBuilder {
|
|
|
19
19
|
readonly type = "index";
|
|
20
20
|
constructor(inputFS: SourceFieldSpace, refineThis: PipeSegment | undefined, isNestIn: QueryOperationSpace | undefined, astEl: MalloyElement);
|
|
21
21
|
execute(qp: QueryProperty): void;
|
|
22
|
-
get fieldUsage(): FieldUsage
|
|
22
|
+
get fieldUsage(): FieldUsage;
|
|
23
23
|
finalize(from: PipeSegment | undefined): PipeSegment;
|
|
24
24
|
}
|
|
@@ -102,16 +102,17 @@ class IndexBuilder {
|
|
|
102
102
|
indexSegment.alwaysJoins = [...this.alwaysJoins];
|
|
103
103
|
}
|
|
104
104
|
const fromFieldUsage = from && from.type === 'index'
|
|
105
|
-
? (
|
|
105
|
+
? (0, malloy_types_1.fieldUsageFrom)(from.refSummary)
|
|
106
106
|
: (0, composite_source_utils_1.emptyFieldUsage)();
|
|
107
|
-
|
|
107
|
+
const fieldUsage = (_a = (0, composite_source_utils_1.mergeFieldUsage)(fromFieldUsage, this.fieldUsage)) !== null && _a !== void 0 ? _a : [];
|
|
108
108
|
// Index queries always compute an aggregate for weight (at minimum COUNT(*)).
|
|
109
109
|
// The compiler needs a uniqueKeyRequirement on the base path so that
|
|
110
110
|
// symmetric aggregation is enabled when joins are present.
|
|
111
|
-
|
|
111
|
+
fieldUsage.push({
|
|
112
112
|
path: [],
|
|
113
113
|
uniqueKeyRequirement: { isCount: true },
|
|
114
114
|
});
|
|
115
|
+
(0, malloy_types_1.setFieldUsage)(indexSegment, fieldUsage);
|
|
115
116
|
return indexSegment;
|
|
116
117
|
}
|
|
117
118
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { FilterCondition, PipeSegment, QuerySegment, RefSummary } from '../../../model/malloy_types';
|
|
2
2
|
import type { SourceFieldSpace } from '../types/field-space';
|
|
3
3
|
import { Ordering } from '../query-properties/ordering';
|
|
4
4
|
import type { QueryProperty } from '../types/query-property';
|
|
@@ -18,7 +18,7 @@ export declare abstract class QuerySegmentBuilder implements QueryBuilder {
|
|
|
18
18
|
filters: FilterCondition[];
|
|
19
19
|
execute(qp: QueryProperty): void;
|
|
20
20
|
abstract finalize(fromSeg: PipeSegment | undefined): PipeSegment;
|
|
21
|
-
get
|
|
21
|
+
get refSummary(): RefSummary | undefined;
|
|
22
22
|
refineFrom(from: PipeSegment | undefined, to: QuerySegment): void;
|
|
23
23
|
}
|
|
24
24
|
export declare class ReduceBuilder extends QuerySegmentBuilder implements QueryBuilder {
|
|
@@ -68,11 +68,10 @@ class QuerySegmentBuilder {
|
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
|
-
get
|
|
72
|
-
return this.resultFS.
|
|
71
|
+
get refSummary() {
|
|
72
|
+
return this.resultFS.refSummary;
|
|
73
73
|
}
|
|
74
74
|
refineFrom(from, to) {
|
|
75
|
-
var _a;
|
|
76
75
|
if (from && from.type !== 'index' && from.type !== 'raw') {
|
|
77
76
|
if (!this.limit && from.orderBy && !from.defaultOrderBy) {
|
|
78
77
|
to.orderBy = from.orderBy;
|
|
@@ -99,8 +98,8 @@ class QuerySegmentBuilder {
|
|
|
99
98
|
if (this.alwaysJoins.length > 0) {
|
|
100
99
|
to.alwaysJoins = [...this.alwaysJoins];
|
|
101
100
|
}
|
|
102
|
-
const
|
|
103
|
-
to.
|
|
101
|
+
const fromRefSummary = from && (0, malloy_types_1.isQuerySegment)(from) ? from.refSummary : undefined;
|
|
102
|
+
to.refSummary = (0, composite_source_utils_1.mergeRefSummaries)(fromRefSummary, this.refSummary);
|
|
104
103
|
}
|
|
105
104
|
}
|
|
106
105
|
exports.QuerySegmentBuilder = QuerySegmentBuilder;
|
|
@@ -89,9 +89,9 @@ class QueryArrow extends query_base_1.QueryBase {
|
|
|
89
89
|
const pipelineWithExpandedFieldUsage = [
|
|
90
90
|
// The base query (if it exists) will already have its `expandedFieldUsage` computed
|
|
91
91
|
...queryBase.pipeline,
|
|
92
|
-
...this.
|
|
92
|
+
...this.expandRefUsage(this.source instanceof source_1.Source
|
|
93
93
|
? // If `source ->` then use the composite resolved struct,
|
|
94
|
-
compositeResolvedSourceDef !== null && compositeResolvedSourceDef !== void 0 ? compositeResolvedSourceDef : inputStruct
|
|
94
|
+
(compositeResolvedSourceDef !== null && compositeResolvedSourceDef !== void 0 ? compositeResolvedSourceDef : inputStruct)
|
|
95
95
|
: // Otherwise just use the `inputStruct`
|
|
96
96
|
inputStruct, rhsPipeline),
|
|
97
97
|
];
|
|
@@ -100,6 +100,7 @@ class QueryArrow extends query_base_1.QueryBase {
|
|
|
100
100
|
...query,
|
|
101
101
|
compositeResolvedSourceDef,
|
|
102
102
|
pipeline: pipelineWithExpandedFieldUsage,
|
|
103
|
+
givenUsage: (0, composite_source_utils_1.computeQueryGivenUsage)(pipelineWithExpandedFieldUsage),
|
|
103
104
|
},
|
|
104
105
|
outputStruct,
|
|
105
106
|
inputStruct,
|
|
@@ -3,7 +3,7 @@ import { MalloyElement } from '../types/malloy-element';
|
|
|
3
3
|
import type { QueryComp } from '../types/query-comp';
|
|
4
4
|
export declare abstract class QueryBase extends MalloyElement {
|
|
5
5
|
abstract queryComp(isRefOk: boolean): QueryComp;
|
|
6
|
-
protected
|
|
6
|
+
protected expandRefUsage(inputSource: SourceDef, pipeline: PipeSegment[]): PipeSegment[];
|
|
7
7
|
protected resolveCompositeSource(inputSource: SourceDef, pipeline: PipeSegment[]): SourceDef | undefined;
|
|
8
8
|
query(isRefOk?: boolean): Query;
|
|
9
9
|
}
|
|
@@ -29,7 +29,7 @@ const error_factory_1 = require("../error-factory");
|
|
|
29
29
|
const query_utils_1 = require("../query-utils");
|
|
30
30
|
const malloy_element_1 = require("../types/malloy-element");
|
|
31
31
|
class QueryBase extends malloy_element_1.MalloyElement {
|
|
32
|
-
|
|
32
|
+
expandRefUsage(inputSource, pipeline) {
|
|
33
33
|
const ret = [];
|
|
34
34
|
let stageInput = inputSource;
|
|
35
35
|
for (const segment of pipeline) {
|
|
@@ -25,6 +25,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
25
25
|
exports.QueryRefine = void 0;
|
|
26
26
|
const static_space_1 = require("../field-space/static-space");
|
|
27
27
|
const query_base_1 = require("./query-base");
|
|
28
|
+
const composite_source_utils_1 = require("../../composite-source-utils");
|
|
28
29
|
/**
|
|
29
30
|
* A query operation that consists of an exisitng query with refinements.
|
|
30
31
|
*
|
|
@@ -46,12 +47,13 @@ class QueryRefine extends query_base_1.QueryBase {
|
|
|
46
47
|
pipeline,
|
|
47
48
|
};
|
|
48
49
|
const compositeResolvedSourceDef = this.resolveCompositeSource(q.inputStruct, pipeline);
|
|
49
|
-
const pipelineWithExpandedFieldUsage = this.
|
|
50
|
+
const pipelineWithExpandedFieldUsage = this.expandRefUsage(compositeResolvedSourceDef !== null && compositeResolvedSourceDef !== void 0 ? compositeResolvedSourceDef : q.inputStruct, pipeline);
|
|
50
51
|
return {
|
|
51
52
|
query: {
|
|
52
53
|
...query,
|
|
53
54
|
compositeResolvedSourceDef,
|
|
54
55
|
pipeline: pipelineWithExpandedFieldUsage,
|
|
56
|
+
givenUsage: (0, composite_source_utils_1.computeQueryGivenUsage)(pipelineWithExpandedFieldUsage),
|
|
55
57
|
},
|
|
56
58
|
// TODO bleh
|
|
57
59
|
outputStruct: pipeline[pipeline.length - 1].outputStruct,
|
|
@@ -118,7 +118,7 @@ class AtomicFieldDeclaration extends malloy_element_1.MalloyElement {
|
|
|
118
118
|
value: exprValue.value,
|
|
119
119
|
expressionType: exprValue.expressionType,
|
|
120
120
|
evalSpace: exprValue.evalSpace,
|
|
121
|
-
|
|
121
|
+
refSummary: exprValue.refSummary,
|
|
122
122
|
requiresGroupBy: exprValue.requiresGroupBy,
|
|
123
123
|
};
|
|
124
124
|
exprValue = nullAsNumber;
|
|
@@ -147,7 +147,7 @@ class AtomicFieldDeclaration extends malloy_element_1.MalloyElement {
|
|
|
147
147
|
ret.e = exprValue.value;
|
|
148
148
|
}
|
|
149
149
|
ret.drillExpression = this.expr.drillExpression();
|
|
150
|
-
ret.
|
|
150
|
+
ret.refSummary = exprValue.refSummary;
|
|
151
151
|
ret.ungroupings = exprValue.ungroupings;
|
|
152
152
|
ret.requiresGroupBy = exprValue.requiresGroupBy;
|
|
153
153
|
if (exprValue.expressionType) {
|
|
@@ -43,7 +43,7 @@ class Drill extends filters_1.Filter {
|
|
|
43
43
|
this.queryRefinementStage = query_property_interface_1.LegalRefinementStage.Head;
|
|
44
44
|
}
|
|
45
45
|
checkedDrillCondition(fs, filter, reference, value) {
|
|
46
|
-
var _a, _b
|
|
46
|
+
var _a, _b;
|
|
47
47
|
const permissiveFS = new permissive_space_1.PermissiveSpace(fs);
|
|
48
48
|
const normalLookup = fs.lookup(reference.list);
|
|
49
49
|
if (normalLookup.found) {
|
|
@@ -144,7 +144,7 @@ class Drill extends filters_1.Filter {
|
|
|
144
144
|
continue;
|
|
145
145
|
if (collectedWheres === undefined) {
|
|
146
146
|
collectedWheres = filter.e;
|
|
147
|
-
collectedWhereFieldUsage = filter.
|
|
147
|
+
collectedWhereFieldUsage = (0, malloy_types_1.fieldUsageFrom)(filter.refSummary);
|
|
148
148
|
}
|
|
149
149
|
else {
|
|
150
150
|
collectedWheres = {
|
|
@@ -154,7 +154,7 @@ class Drill extends filters_1.Filter {
|
|
|
154
154
|
right: filter.e,
|
|
155
155
|
},
|
|
156
156
|
};
|
|
157
|
-
collectedWhereFieldUsage = (0, composite_source_utils_1.mergeFieldUsage)(collectedWhereFieldUsage, filter.
|
|
157
|
+
collectedWhereFieldUsage = (0, composite_source_utils_1.mergeFieldUsage)(collectedWhereFieldUsage, (0, malloy_types_1.fieldUsageFrom)(filter.refSummary));
|
|
158
158
|
}
|
|
159
159
|
}
|
|
160
160
|
}
|
|
@@ -272,7 +272,7 @@ class Drill extends filters_1.Filter {
|
|
|
272
272
|
...fieldDef,
|
|
273
273
|
evalSpace: 'output',
|
|
274
274
|
expressionType: (_b = fieldDef.expressionType) !== null && _b !== void 0 ? _b : 'scalar',
|
|
275
|
-
|
|
275
|
+
refSummary: fieldDef.refSummary,
|
|
276
276
|
});
|
|
277
277
|
filter.has({ drillField });
|
|
278
278
|
const fExpression = new expr_compare_1.ExprCompare(drillField, '=', value);
|
|
@@ -290,7 +290,7 @@ class Drill extends filters_1.Filter {
|
|
|
290
290
|
kids: { left: collectedWheres, right: fExpr.value },
|
|
291
291
|
},
|
|
292
292
|
expressionType: fExpr.expressionType,
|
|
293
|
-
|
|
293
|
+
refSummary: (0, composite_source_utils_1.mergeRefSummaries)(fExpr.refSummary, (0, malloy_types_1.mkRefSummary)({ fieldUsage: collectedWhereFieldUsage })),
|
|
294
294
|
stableFilter: {
|
|
295
295
|
kind: 'literal_equality',
|
|
296
296
|
expression: {
|
|
@@ -364,7 +364,7 @@ function attachDrillPaths(pipeline, nestName) {
|
|
|
364
364
|
if (f.type === 'turtle') {
|
|
365
365
|
return updateNestedDrillPaths(f, nestName);
|
|
366
366
|
}
|
|
367
|
-
const fieldName = f.type === 'fieldref' ? f.path[f.path.length - 1] : (_a = f.as) !== null && _a !== void 0 ? _a : f.name;
|
|
367
|
+
const fieldName = f.type === 'fieldref' ? f.path[f.path.length - 1] : ((_a = f.as) !== null && _a !== void 0 ? _a : f.name);
|
|
368
368
|
return {
|
|
369
369
|
...f,
|
|
370
370
|
drillExpression: {
|
|
@@ -74,7 +74,7 @@ class FilterElement extends malloy_element_1.MalloyElement {
|
|
|
74
74
|
code: this.exprSrc,
|
|
75
75
|
e: { node: 'false' },
|
|
76
76
|
expressionType: 'scalar',
|
|
77
|
-
|
|
77
|
+
refSummary: exprVal.refSummary,
|
|
78
78
|
isSourceFilter: false,
|
|
79
79
|
};
|
|
80
80
|
}
|
|
@@ -84,7 +84,7 @@ class FilterElement extends malloy_element_1.MalloyElement {
|
|
|
84
84
|
code: this.exprSrc,
|
|
85
85
|
e: exprVal.value,
|
|
86
86
|
expressionType: exprVal.expressionType,
|
|
87
|
-
|
|
87
|
+
refSummary: exprVal.refSummary,
|
|
88
88
|
stableFilter,
|
|
89
89
|
isSourceFilter: false,
|
|
90
90
|
};
|
|
@@ -77,8 +77,8 @@ class NestFieldDeclaration extends view_field_declaration_1.ViewFieldDeclaration
|
|
|
77
77
|
return this.turtleDef;
|
|
78
78
|
if (fs.isQueryFieldSpace()) {
|
|
79
79
|
const { pipeline, annotation } = this.view.pipelineComp(fs, fs.outputSpace());
|
|
80
|
-
const
|
|
81
|
-
? pipeline[0].
|
|
80
|
+
const refSummary = pipeline[0] && model.isQuerySegment(pipeline[0])
|
|
81
|
+
? pipeline[0].refSummary
|
|
82
82
|
: undefined;
|
|
83
83
|
const checkedPipeline = (0, query_utils_1.detectAndRemovePartialStages)(pipeline, this);
|
|
84
84
|
const pipelineWithDrillPaths = (0, drill_1.attachDrillPaths)(checkedPipeline, this.name);
|
|
@@ -88,7 +88,7 @@ class NestFieldDeclaration extends view_field_declaration_1.ViewFieldDeclaration
|
|
|
88
88
|
pipeline: pipelineWithDrillPaths,
|
|
89
89
|
annotation: { ...this.note, inherits: annotation },
|
|
90
90
|
location: this.location,
|
|
91
|
-
|
|
91
|
+
refSummary,
|
|
92
92
|
};
|
|
93
93
|
return this.turtleDef;
|
|
94
94
|
}
|
|
@@ -92,9 +92,11 @@ function composeSources(sources, compositeCodeSource) {
|
|
|
92
92
|
name: fieldName,
|
|
93
93
|
as: undefined,
|
|
94
94
|
e: { node: 'compositeField' },
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
95
|
+
refSummary: {
|
|
96
|
+
fieldUsage: [
|
|
97
|
+
{ path: [fieldName], at: compositeCodeSource.codeLocation },
|
|
98
|
+
],
|
|
99
|
+
},
|
|
98
100
|
code: undefined,
|
|
99
101
|
location: compositeCodeSource.codeLocation,
|
|
100
102
|
// A composite field's grouping may differ from slice to slice
|
|
@@ -103,6 +103,10 @@ class NamedSource extends source_1.Source {
|
|
|
103
103
|
this.logError('invalid-source-from-user-type', `Cannot construct a source from a user type '${this.refName}'`);
|
|
104
104
|
return;
|
|
105
105
|
}
|
|
106
|
+
else if (entry.type === 'given') {
|
|
107
|
+
this.logError('invalid-source-from-given', `Cannot construct a source from given '${this.refName}'`);
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
106
110
|
else {
|
|
107
111
|
(_a = this.document()) === null || _a === void 0 ? void 0 : _a.checkExperimentalDialect(this, entry.dialect);
|
|
108
112
|
if ((0, malloy_types_1.isSourceDef)(entry)) {
|
|
@@ -125,7 +125,7 @@ class SQLSource extends source_1.Source {
|
|
|
125
125
|
}
|
|
126
126
|
else if (lookup.status === 'present') {
|
|
127
127
|
const location = this.select.location;
|
|
128
|
-
// Create a base struct with updated fields (adding location and
|
|
128
|
+
// Create a base struct with updated fields (adding location and refSummary)
|
|
129
129
|
const baseStruct = {
|
|
130
130
|
...lookup.value,
|
|
131
131
|
fields: lookup.value.fields.map(f => {
|
|
@@ -133,7 +133,7 @@ class SQLSource extends source_1.Source {
|
|
|
133
133
|
return ({
|
|
134
134
|
...f,
|
|
135
135
|
location,
|
|
136
|
-
fieldUsage: [{ path: [(_a = f.as) !== null && _a !== void 0 ? _a : f.name], at: location }],
|
|
136
|
+
refSummary: { fieldUsage: [{ path: [(_a = f.as) !== null && _a !== void 0 ? _a : f.name], at: location }] },
|
|
137
137
|
});
|
|
138
138
|
}),
|
|
139
139
|
location: this.location,
|
|
@@ -51,7 +51,9 @@ class TableSource extends source_1.Source {
|
|
|
51
51
|
return ({
|
|
52
52
|
...field,
|
|
53
53
|
location: this.location,
|
|
54
|
-
|
|
54
|
+
refSummary: {
|
|
55
|
+
fieldUsage: [{ path: [(_a = field.as) !== null && _a !== void 0 ? _a : field.name], at: this.location }],
|
|
56
|
+
},
|
|
55
57
|
});
|
|
56
58
|
}),
|
|
57
59
|
location: this.location,
|
|
@@ -101,9 +101,9 @@ class KeyJoin extends Join {
|
|
|
101
101
|
right: exprX.value,
|
|
102
102
|
},
|
|
103
103
|
};
|
|
104
|
-
inStruct.
|
|
105
|
-
{ path: keyPath },
|
|
106
|
-
|
|
104
|
+
inStruct.refSummary = (0, composite_source_utils_1.mergeRefSummaries)(exprX.refSummary, {
|
|
105
|
+
fieldUsage: [{ path: keyPath }],
|
|
106
|
+
});
|
|
107
107
|
return;
|
|
108
108
|
}
|
|
109
109
|
else {
|
|
@@ -146,7 +146,7 @@ class ExpressionJoin extends Join {
|
|
|
146
146
|
return;
|
|
147
147
|
}
|
|
148
148
|
inStruct.onExpression = exprX.value;
|
|
149
|
-
inStruct.
|
|
149
|
+
inStruct.refSummary = exprX.refSummary;
|
|
150
150
|
}
|
|
151
151
|
getStructDef(parameterSpace) {
|
|
152
152
|
var _a;
|
|
@@ -52,7 +52,8 @@ class SQReference extends source_query_element_1.SourceQueryElement {
|
|
|
52
52
|
return query;
|
|
53
53
|
}
|
|
54
54
|
else {
|
|
55
|
-
|
|
55
|
+
const label = entry.type === 'given' ? entry.name : entry.as || entry.name;
|
|
56
|
+
this.sqLog('cannot-use-as-query', `Illegal reference to '${label}', query expected`);
|
|
56
57
|
}
|
|
57
58
|
}
|
|
58
59
|
else {
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Annotation, GivenTypeDef } from '../../../model/malloy_types';
|
|
2
|
+
import type { ConstantExpression } from '../expressions/constant-expression';
|
|
3
|
+
import type { DocStatement, Document } from '../types/malloy-element';
|
|
4
|
+
import { DocStatementList, MalloyElement } from '../types/malloy-element';
|
|
5
|
+
import type { Noteable } from '../types/noteable';
|
|
6
|
+
import { extendNoteMethod } from '../types/noteable';
|
|
7
|
+
export declare class GivenDeclaration extends MalloyElement implements DocStatement, Noteable {
|
|
8
|
+
readonly name: string;
|
|
9
|
+
readonly typeDef: GivenTypeDef;
|
|
10
|
+
elementType: string;
|
|
11
|
+
readonly isNoteableObj = true;
|
|
12
|
+
extendNote: typeof extendNoteMethod;
|
|
13
|
+
note?: Annotation;
|
|
14
|
+
readonly default?: ConstantExpression;
|
|
15
|
+
constructor(name: string, typeDef: GivenTypeDef, defaultExpr?: ConstantExpression);
|
|
16
|
+
protected varInfo(): string;
|
|
17
|
+
execute(doc: Document): void;
|
|
18
|
+
}
|
|
19
|
+
export declare class DefineGivens extends DocStatementList {
|
|
20
|
+
elementType: string;
|
|
21
|
+
readonly givens: GivenDeclaration[];
|
|
22
|
+
constructor(givens: GivenDeclaration[]);
|
|
23
|
+
}
|