@malloydata/malloy-query-builder 0.0.293 → 0.0.295
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/query-ast.d.ts +9 -5
- package/dist/query-ast.js +62 -30
- package/dist/query-ast.js.map +1 -1
- package/dist/query-ast.spec.js +76 -21
- package/dist/query-ast.spec.js.map +1 -1
- package/package.json +4 -4
- package/src/query-ast.spec.ts +76 -21
- package/src/query-ast.ts +73 -35
package/dist/query-ast.d.ts
CHANGED
|
@@ -1257,7 +1257,7 @@ export declare class ASTReferenceExpression extends ASTObjectNode<Malloy.Express
|
|
|
1257
1257
|
/**
|
|
1258
1258
|
* @internal
|
|
1259
1259
|
*/
|
|
1260
|
-
get
|
|
1260
|
+
get segment(): ASTSegmentViewDefinition;
|
|
1261
1261
|
get path(): string[] | undefined;
|
|
1262
1262
|
getReference(): Malloy.ExpressionWithFieldReference;
|
|
1263
1263
|
getFieldInfo(): Malloy.FieldInfoWithDimension | Malloy.FieldInfoWithMeasure;
|
|
@@ -1305,6 +1305,7 @@ export declare class ASTLiteralValueExpression extends ASTObjectNode<Malloy.Expr
|
|
|
1305
1305
|
get literalValue(): ASTLiteralValue;
|
|
1306
1306
|
get fieldType(): Malloy.AtomicType | undefined;
|
|
1307
1307
|
getInheritedAnnotations(): Malloy.Annotation[];
|
|
1308
|
+
getFieldInfo(): undefined;
|
|
1308
1309
|
}
|
|
1309
1310
|
export declare class ASTFilterOperation extends ASTObjectNode<Malloy.FilterOperation, {
|
|
1310
1311
|
filter: ASTFilter;
|
|
@@ -1457,19 +1458,21 @@ export declare class ASTHavingViewOperation extends ASTObjectNode<Malloy.ViewOpe
|
|
|
1457
1458
|
export type ASTFilter = ASTFilterWithFilterString | ASTFilterWithLiteralEquality;
|
|
1458
1459
|
export declare const ASTFilter: {
|
|
1459
1460
|
from(filter: Malloy.Filter): ASTFilterWithFilterString | ASTFilterWithLiteralEquality;
|
|
1461
|
+
getSegment(filter: ASTFilter): ASTSegmentViewDefinition;
|
|
1460
1462
|
};
|
|
1461
1463
|
export declare class ASTFilterWithFilterString extends ASTObjectNode<Malloy.FilterWithFilterString, {
|
|
1462
1464
|
kind: 'filter_string';
|
|
1463
|
-
|
|
1465
|
+
expression: ASTExpression;
|
|
1464
1466
|
filter: string;
|
|
1465
1467
|
}> {
|
|
1466
1468
|
node: Malloy.FilterWithFilterString;
|
|
1467
1469
|
readonly kind: Malloy.FilterType;
|
|
1468
1470
|
constructor(node: Malloy.FilterWithFilterString);
|
|
1469
|
-
get
|
|
1471
|
+
get expression(): ASTExpression;
|
|
1470
1472
|
get filterString(): string;
|
|
1471
1473
|
set filterString(filter: string);
|
|
1472
1474
|
setFilterString(filterString: string): void;
|
|
1475
|
+
get segment(): ASTSegmentViewDefinition;
|
|
1473
1476
|
getFieldInfo(): Malloy.FieldInfoWithDimension | Malloy.FieldInfoWithMeasure;
|
|
1474
1477
|
getFilterType(): Filter.FilterableType | 'other';
|
|
1475
1478
|
setFilter(filter: ParsedFilter): void;
|
|
@@ -1477,14 +1480,15 @@ export declare class ASTFilterWithFilterString extends ASTObjectNode<Malloy.Filt
|
|
|
1477
1480
|
}
|
|
1478
1481
|
export declare class ASTFilterWithLiteralEquality extends ASTObjectNode<Malloy.FilterWithLiteralEquality, {
|
|
1479
1482
|
kind: 'literal_equality';
|
|
1480
|
-
|
|
1483
|
+
expression: ASTExpression;
|
|
1481
1484
|
value: ASTLiteralValue;
|
|
1482
1485
|
}> {
|
|
1483
1486
|
node: Malloy.FilterWithLiteralEquality;
|
|
1484
1487
|
readonly kind: Malloy.FilterType;
|
|
1485
1488
|
constructor(node: Malloy.FilterWithLiteralEquality);
|
|
1486
|
-
get
|
|
1489
|
+
get expression(): ASTExpression;
|
|
1487
1490
|
get value(): ASTLiteralValue;
|
|
1491
|
+
get segment(): ASTSegmentViewDefinition;
|
|
1488
1492
|
}
|
|
1489
1493
|
export declare class ASTView extends ASTObjectNode<Malloy.View, {
|
|
1490
1494
|
definition: ASTViewDefinition;
|
package/dist/query-ast.js
CHANGED
|
@@ -934,13 +934,7 @@ class ASTFieldReference extends ASTReference {
|
|
|
934
934
|
}
|
|
935
935
|
else if (parent instanceof ASTFilterWithFilterString ||
|
|
936
936
|
parent instanceof ASTFilterWithLiteralEquality) {
|
|
937
|
-
|
|
938
|
-
if (grand instanceof ASTFilterOperation) {
|
|
939
|
-
return grand.list.expression.field.segment;
|
|
940
|
-
}
|
|
941
|
-
else {
|
|
942
|
-
return grand.list.segment;
|
|
943
|
-
}
|
|
937
|
+
return parent.segment;
|
|
944
938
|
}
|
|
945
939
|
else {
|
|
946
940
|
return parent.list.segment;
|
|
@@ -954,14 +948,7 @@ class ASTFieldReference extends ASTReference {
|
|
|
954
948
|
}
|
|
955
949
|
getFieldInfo() {
|
|
956
950
|
const schema = this.getReferenceSchema();
|
|
957
|
-
|
|
958
|
-
this.parent.parent instanceof ASTDrillViewOperation;
|
|
959
|
-
if (isDrill) {
|
|
960
|
-
return ASTNode.schemaGetDrillField(schema, this.name, this.path);
|
|
961
|
-
}
|
|
962
|
-
else {
|
|
963
|
-
return ASTNode.schemaGet(schema, this.name, this.path);
|
|
964
|
-
}
|
|
951
|
+
return ASTNode.schemaGet(schema, this.name, this.path);
|
|
965
952
|
}
|
|
966
953
|
}
|
|
967
954
|
exports.ASTFieldReference = ASTFieldReference;
|
|
@@ -2293,7 +2280,11 @@ class ASTSegmentViewDefinition extends ASTObjectNode {
|
|
|
2293
2280
|
kind: 'where',
|
|
2294
2281
|
filter: {
|
|
2295
2282
|
kind: 'filter_string',
|
|
2296
|
-
|
|
2283
|
+
expression: {
|
|
2284
|
+
kind: 'field_reference',
|
|
2285
|
+
name,
|
|
2286
|
+
path,
|
|
2287
|
+
},
|
|
2297
2288
|
filter: filterString,
|
|
2298
2289
|
},
|
|
2299
2290
|
});
|
|
@@ -2313,7 +2304,11 @@ class ASTSegmentViewDefinition extends ASTObjectNode {
|
|
|
2313
2304
|
kind: 'having',
|
|
2314
2305
|
filter: {
|
|
2315
2306
|
kind: 'filter_string',
|
|
2316
|
-
|
|
2307
|
+
expression: {
|
|
2308
|
+
kind: 'field_reference',
|
|
2309
|
+
name,
|
|
2310
|
+
path,
|
|
2311
|
+
},
|
|
2317
2312
|
filter: filterString,
|
|
2318
2313
|
},
|
|
2319
2314
|
});
|
|
@@ -2897,7 +2892,11 @@ class ASTAggregateViewOperation extends ASTObjectNode {
|
|
|
2897
2892
|
const where = {
|
|
2898
2893
|
filter: {
|
|
2899
2894
|
kind: 'filter_string',
|
|
2900
|
-
|
|
2895
|
+
expression: {
|
|
2896
|
+
kind: 'field_reference',
|
|
2897
|
+
name,
|
|
2898
|
+
path,
|
|
2899
|
+
},
|
|
2901
2900
|
filter: filterString,
|
|
2902
2901
|
},
|
|
2903
2902
|
};
|
|
@@ -3060,8 +3059,18 @@ class ASTReferenceExpression extends ASTObjectNode {
|
|
|
3060
3059
|
/**
|
|
3061
3060
|
* @internal
|
|
3062
3061
|
*/
|
|
3063
|
-
get
|
|
3064
|
-
|
|
3062
|
+
get segment() {
|
|
3063
|
+
const parent = this.parent;
|
|
3064
|
+
if (parent instanceof ASTField) {
|
|
3065
|
+
return parent.segment;
|
|
3066
|
+
}
|
|
3067
|
+
else if (parent instanceof ASTFilterWithFilterString ||
|
|
3068
|
+
parent instanceof ASTFilterWithLiteralEquality) {
|
|
3069
|
+
return parent.segment;
|
|
3070
|
+
}
|
|
3071
|
+
else {
|
|
3072
|
+
throw new Error('Invalid expression parent');
|
|
3073
|
+
}
|
|
3065
3074
|
}
|
|
3066
3075
|
get path() {
|
|
3067
3076
|
return this.children.path;
|
|
@@ -3070,8 +3079,12 @@ class ASTReferenceExpression extends ASTObjectNode {
|
|
|
3070
3079
|
return this.build();
|
|
3071
3080
|
}
|
|
3072
3081
|
getFieldInfo() {
|
|
3073
|
-
const schema = this.
|
|
3074
|
-
const
|
|
3082
|
+
const schema = this.segment.getInputSchema();
|
|
3083
|
+
const isDrill = this.parent instanceof ASTFilterWithLiteralEquality &&
|
|
3084
|
+
this.parent.parent instanceof ASTDrillViewOperation;
|
|
3085
|
+
const def = isDrill
|
|
3086
|
+
? ASTNode.schemaGetDrillField(schema, this.name, this.path)
|
|
3087
|
+
: ASTNode.schemaGet(schema, this.name, this.path);
|
|
3075
3088
|
if (def.kind !== 'dimension' && def.kind !== 'measure') {
|
|
3076
3089
|
throw new Error('Invalid field for ASTReferenceExpression');
|
|
3077
3090
|
}
|
|
@@ -3177,6 +3190,9 @@ class ASTLiteralValueExpression extends ASTObjectNode {
|
|
|
3177
3190
|
getInheritedAnnotations() {
|
|
3178
3191
|
return [];
|
|
3179
3192
|
}
|
|
3193
|
+
getFieldInfo() {
|
|
3194
|
+
return undefined;
|
|
3195
|
+
}
|
|
3180
3196
|
}
|
|
3181
3197
|
exports.ASTLiteralValueExpression = ASTLiteralValueExpression;
|
|
3182
3198
|
class ASTFilterOperation extends ASTObjectNode {
|
|
@@ -3480,19 +3496,28 @@ exports.ASTFilter = {
|
|
|
3480
3496
|
return new ASTFilterWithLiteralEquality(filter);
|
|
3481
3497
|
}
|
|
3482
3498
|
},
|
|
3499
|
+
getSegment(filter) {
|
|
3500
|
+
const grand = filter.parent;
|
|
3501
|
+
if (grand instanceof ASTFilterOperation) {
|
|
3502
|
+
return grand.list.expression.field.segment;
|
|
3503
|
+
}
|
|
3504
|
+
else {
|
|
3505
|
+
return grand.list.segment;
|
|
3506
|
+
}
|
|
3507
|
+
},
|
|
3483
3508
|
};
|
|
3484
3509
|
class ASTFilterWithFilterString extends ASTObjectNode {
|
|
3485
3510
|
constructor(node) {
|
|
3486
3511
|
super(node, {
|
|
3487
3512
|
kind: 'filter_string',
|
|
3488
|
-
|
|
3513
|
+
expression: exports.ASTExpression.from(node.expression),
|
|
3489
3514
|
filter: node.filter,
|
|
3490
3515
|
});
|
|
3491
3516
|
this.node = node;
|
|
3492
3517
|
this.kind = 'filter_string';
|
|
3493
3518
|
}
|
|
3494
|
-
get
|
|
3495
|
-
return this.children.
|
|
3519
|
+
get expression() {
|
|
3520
|
+
return this.children.expression;
|
|
3496
3521
|
}
|
|
3497
3522
|
get filterString() {
|
|
3498
3523
|
return this.children.filter;
|
|
@@ -3506,9 +3531,13 @@ class ASTFilterWithFilterString extends ASTObjectNode {
|
|
|
3506
3531
|
parseFilter(this.filterString, kind);
|
|
3507
3532
|
this.filterString = filterString;
|
|
3508
3533
|
}
|
|
3534
|
+
get segment() {
|
|
3535
|
+
return exports.ASTFilter.getSegment(this);
|
|
3536
|
+
}
|
|
3509
3537
|
getFieldInfo() {
|
|
3510
|
-
const field = this.
|
|
3511
|
-
if (field
|
|
3538
|
+
const field = this.expression.getFieldInfo();
|
|
3539
|
+
if (field === undefined ||
|
|
3540
|
+
(field.kind !== 'dimension' && field.kind !== 'measure')) {
|
|
3512
3541
|
throw new Error('Invalid field type for filter with filter string');
|
|
3513
3542
|
}
|
|
3514
3543
|
return field;
|
|
@@ -3534,18 +3563,21 @@ class ASTFilterWithLiteralEquality extends ASTObjectNode {
|
|
|
3534
3563
|
constructor(node) {
|
|
3535
3564
|
super(node, {
|
|
3536
3565
|
kind: 'literal_equality',
|
|
3537
|
-
|
|
3566
|
+
expression: exports.ASTExpression.from(node.expression),
|
|
3538
3567
|
value: exports.ASTLiteralValue.from(node.value),
|
|
3539
3568
|
});
|
|
3540
3569
|
this.node = node;
|
|
3541
3570
|
this.kind = 'literal_equality';
|
|
3542
3571
|
}
|
|
3543
|
-
get
|
|
3544
|
-
return this.children.
|
|
3572
|
+
get expression() {
|
|
3573
|
+
return this.children.expression;
|
|
3545
3574
|
}
|
|
3546
3575
|
get value() {
|
|
3547
3576
|
return this.children.value;
|
|
3548
3577
|
}
|
|
3578
|
+
get segment() {
|
|
3579
|
+
return exports.ASTFilter.getSegment(this);
|
|
3580
|
+
}
|
|
3549
3581
|
}
|
|
3550
3582
|
exports.ASTFilterWithLiteralEquality = ASTFilterWithLiteralEquality;
|
|
3551
3583
|
class ASTView extends ASTObjectNode {
|