@malloydata/malloy-query-builder 0.0.281 → 0.0.283

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.
@@ -114,10 +114,22 @@ declare abstract class ASTNode<T> {
114
114
  * @internal
115
115
  */
116
116
  static schemaTryGet(schema: Malloy.Schema, name: string, path: string[] | undefined): Malloy.FieldInfo | undefined;
117
+ /**
118
+ * @internal
119
+ */
120
+ static schemaTryGetDrillField(schema: Malloy.Schema, name: string, path: string[] | undefined): Malloy.FieldInfo | undefined;
121
+ /**
122
+ * @internal
123
+ */
124
+ private static _schemaTryGet;
117
125
  /**
118
126
  * @internal
119
127
  */
120
128
  static schemaGet(schema: Malloy.Schema, name: string, path: string[] | undefined): Malloy.FieldInfo;
129
+ /**
130
+ * @internal
131
+ */
132
+ static schemaGetDrillField(schema: Malloy.Schema, name: string, path: string[] | undefined): Malloy.FieldInfo;
121
133
  /**
122
134
  * @internal
123
135
  */
@@ -424,6 +436,7 @@ export declare class ASTStringLiteralValue extends ASTObjectNode<Malloy.LiteralV
424
436
  node: Malloy.LiteralValueWithStringLiteral;
425
437
  readonly kind: Malloy.LiteralValueType;
426
438
  constructor(node: Malloy.LiteralValueWithStringLiteral);
439
+ get fieldType(): Malloy.AtomicType;
427
440
  }
428
441
  export declare class ASTNullLiteralValue extends ASTObjectNode<Malloy.LiteralValueWithNullLiteral, {
429
442
  kind: 'null_literal';
@@ -431,6 +444,7 @@ export declare class ASTNullLiteralValue extends ASTObjectNode<Malloy.LiteralVal
431
444
  node: Malloy.LiteralValueWithNullLiteral;
432
445
  readonly kind: Malloy.LiteralValueType;
433
446
  constructor(node: Malloy.LiteralValueWithNullLiteral);
447
+ get fieldType(): undefined;
434
448
  }
435
449
  export declare class ASTNumberLiteralValue extends ASTObjectNode<Malloy.LiteralValueWithNumberLiteral, {
436
450
  kind: 'number_literal';
@@ -439,6 +453,7 @@ export declare class ASTNumberLiteralValue extends ASTObjectNode<Malloy.LiteralV
439
453
  node: Malloy.LiteralValueWithNumberLiteral;
440
454
  readonly kind: Malloy.LiteralValueType;
441
455
  constructor(node: Malloy.LiteralValueWithNumberLiteral);
456
+ get fieldType(): Malloy.AtomicType;
442
457
  }
443
458
  export declare class ASTBooleanLiteralValue extends ASTObjectNode<Malloy.LiteralValueWithBooleanLiteral, {
444
459
  kind: 'boolean_literal';
@@ -447,6 +462,7 @@ export declare class ASTBooleanLiteralValue extends ASTObjectNode<Malloy.Literal
447
462
  node: Malloy.LiteralValueWithBooleanLiteral;
448
463
  readonly kind: Malloy.LiteralValueType;
449
464
  constructor(node: Malloy.LiteralValueWithBooleanLiteral);
465
+ get fieldType(): Malloy.AtomicType;
450
466
  }
451
467
  export declare class ASTDateLiteralValue extends ASTObjectNode<Malloy.LiteralValueWithDateLiteral, {
452
468
  kind: 'date_literal';
@@ -456,6 +472,7 @@ export declare class ASTDateLiteralValue extends ASTObjectNode<Malloy.LiteralVal
456
472
  node: Malloy.LiteralValueWithDateLiteral;
457
473
  readonly kind: Malloy.LiteralValueType;
458
474
  constructor(node: Malloy.LiteralValueWithDateLiteral);
475
+ get fieldType(): Malloy.AtomicType;
459
476
  }
460
477
  export declare class ASTTimestampLiteralValue extends ASTObjectNode<Malloy.LiteralValueWithTimestampLiteral, {
461
478
  kind: 'timestamp_literal';
@@ -465,6 +482,7 @@ export declare class ASTTimestampLiteralValue extends ASTObjectNode<Malloy.Liter
465
482
  node: Malloy.LiteralValueWithTimestampLiteral;
466
483
  readonly kind: Malloy.LiteralValueType;
467
484
  constructor(node: Malloy.LiteralValueWithTimestampLiteral);
485
+ get fieldType(): Malloy.AtomicType;
468
486
  }
469
487
  export declare class ASTFilterExpressionLiteralValue extends ASTObjectNode<Malloy.LiteralValueWithFilterExpressionLiteral, {
470
488
  kind: 'filter_expression_literal';
@@ -473,6 +491,7 @@ export declare class ASTFilterExpressionLiteralValue extends ASTObjectNode<Mallo
473
491
  node: Malloy.LiteralValueWithFilterExpressionLiteral;
474
492
  readonly kind: Malloy.LiteralValueType;
475
493
  constructor(node: Malloy.LiteralValueWithFilterExpressionLiteral);
494
+ get fieldType(): undefined;
476
495
  }
477
496
  export declare class ASTUnimplemented<T> extends ASTNode<T> {
478
497
  private readonly node;
@@ -902,6 +921,7 @@ export declare class ASTSegmentViewDefinition extends ASTObjectNode<Malloy.ViewD
902
921
  * @param path Join path for this dimension.
903
922
  */
904
923
  addGroupBy(name: string, path?: string[], rename?: string): ASTGroupByViewOperation;
924
+ addDrill(drill: Malloy.DrillOperation): ASTDrillViewOperation;
905
925
  addWhere(name: string, filter: ParsedFilter): ASTWhereViewOperation;
906
926
  addWhere(name: string, filterString: string): ASTWhereViewOperation;
907
927
  addWhere(name: string, path: string[], filter: ParsedFilter): ASTWhereViewOperation;
@@ -1010,7 +1030,7 @@ export declare class ASTViewOperationList extends ASTListNode<Malloy.ViewOperati
1010
1030
  */
1011
1031
  get segment(): ASTSegmentViewDefinition;
1012
1032
  }
1013
- export type ASTViewOperation = ASTGroupByViewOperation | ASTAggregateViewOperation | ASTOrderByViewOperation | ASTNestViewOperation | ASTLimitViewOperation | ASTWhereViewOperation | ASTHavingViewOperation;
1033
+ export type ASTViewOperation = ASTGroupByViewOperation | ASTAggregateViewOperation | ASTOrderByViewOperation | ASTNestViewOperation | ASTLimitViewOperation | ASTWhereViewOperation | ASTDrillViewOperation | ASTHavingViewOperation;
1014
1034
  export declare const ASTViewOperation: {
1015
1035
  from(value: Malloy.ViewOperation): ASTViewOperation;
1016
1036
  isLimit(x: ASTViewOperation): x is ASTLimitViewOperation;
@@ -1195,7 +1215,7 @@ export declare class ASTField extends ASTObjectNode<Malloy.Field, {
1195
1215
  constructor(node: Malloy.Field);
1196
1216
  get expression(): ASTExpression;
1197
1217
  set expression(expression: ASTExpression);
1198
- get name(): string;
1218
+ get name(): string | undefined;
1199
1219
  get type(): Malloy.AtomicType | {
1200
1220
  timeframe: Malloy.DateTimeframe;
1201
1221
  kind: "date_type";
@@ -1205,7 +1225,7 @@ export declare class ASTField extends ASTObjectNode<Malloy.Field, {
1205
1225
  };
1206
1226
  get annotations(): ASTAnnotationList | undefined;
1207
1227
  set annotations(annotations: ASTAnnotationList | undefined);
1208
- getReference(): Malloy.Reference;
1228
+ getReference(): Malloy.Reference | undefined;
1209
1229
  getOrAddAnnotations(): ASTAnnotationList;
1210
1230
  getInheritedTag(prefix?: RegExp | string): Tag;
1211
1231
  getIntrinsicTag(prefix?: RegExp | string): Tag;
@@ -1218,7 +1238,7 @@ export declare class ASTField extends ASTObjectNode<Malloy.Field, {
1218
1238
  get segment(): ASTSegmentViewDefinition;
1219
1239
  getInheritedAnnotations(): Malloy.Annotation[];
1220
1240
  }
1221
- export type ASTExpression = ASTReferenceExpression | ASTFilteredFieldExpression | ASTTimeTruncationExpression;
1241
+ export type ASTExpression = ASTReferenceExpression | ASTFilteredFieldExpression | ASTTimeTruncationExpression | ASTLiteralValueExpression;
1222
1242
  export declare const ASTExpression: {
1223
1243
  from(value: Malloy.Expression): ASTExpression;
1224
1244
  };
@@ -1274,11 +1294,23 @@ export declare class ASTTimeTruncationExpression extends ASTObjectNode<Malloy.Ex
1274
1294
  };
1275
1295
  getInheritedAnnotations(): Malloy.Annotation[];
1276
1296
  }
1297
+ export declare class ASTLiteralValueExpression extends ASTObjectNode<Malloy.ExpressionWithLiteralValue, {
1298
+ kind: 'literal_value';
1299
+ literal_value: ASTLiteralValue;
1300
+ }> {
1301
+ node: Malloy.ExpressionWithLiteralValue;
1302
+ readonly kind: Malloy.ExpressionType;
1303
+ constructor(node: Malloy.ExpressionWithLiteralValue);
1304
+ get name(): undefined;
1305
+ get literalValue(): ASTLiteralValue;
1306
+ get fieldType(): Malloy.AtomicType | undefined;
1307
+ getInheritedAnnotations(): Malloy.Annotation[];
1308
+ }
1277
1309
  export declare class ASTFilterOperation extends ASTObjectNode<Malloy.FilterOperation, {
1278
1310
  filter: ASTFilter;
1279
1311
  }> {
1280
1312
  constructor(node: Malloy.FilterOperation);
1281
- get filter(): ASTFilterWithFilterString;
1313
+ get filter(): ASTFilter;
1282
1314
  get list(): ASTFilterOperationList;
1283
1315
  delete(): void;
1284
1316
  }
@@ -1387,7 +1419,21 @@ export declare class ASTWhereViewOperation extends ASTObjectNode<Malloy.ViewOper
1387
1419
  node: Malloy.ViewOperationWithWhere;
1388
1420
  readonly kind: Malloy.ViewOperationType;
1389
1421
  constructor(node: Malloy.ViewOperationWithWhere);
1390
- get filter(): ASTFilterWithFilterString;
1422
+ get filter(): ASTFilter;
1423
+ /**
1424
+ * @internal
1425
+ */
1426
+ get list(): ASTViewOperationList;
1427
+ delete(): void;
1428
+ }
1429
+ export declare class ASTDrillViewOperation extends ASTObjectNode<Malloy.ViewOperationWithDrill, {
1430
+ kind: 'drill';
1431
+ filter: ASTFilter;
1432
+ }> {
1433
+ node: Malloy.ViewOperationWithDrill;
1434
+ readonly kind: Malloy.ViewOperationType;
1435
+ constructor(node: Malloy.ViewOperationWithDrill);
1436
+ get filter(): ASTFilter;
1391
1437
  /**
1392
1438
  * @internal
1393
1439
  */
@@ -1401,16 +1447,16 @@ export declare class ASTHavingViewOperation extends ASTObjectNode<Malloy.ViewOpe
1401
1447
  node: Malloy.ViewOperationWithHaving;
1402
1448
  readonly kind: Malloy.ViewOperationType;
1403
1449
  constructor(node: Malloy.ViewOperationWithHaving);
1404
- get filter(): ASTFilterWithFilterString;
1450
+ get filter(): ASTFilter;
1405
1451
  /**
1406
1452
  * @internal
1407
1453
  */
1408
1454
  get list(): ASTViewOperationList;
1409
1455
  delete(): void;
1410
1456
  }
1411
- export type ASTFilter = ASTFilterWithFilterString;
1457
+ export type ASTFilter = ASTFilterWithFilterString | ASTFilterWithLiteralEquality;
1412
1458
  export declare const ASTFilter: {
1413
- from(filter: Malloy.Filter): ASTFilterWithFilterString;
1459
+ from(filter: Malloy.Filter): ASTFilterWithFilterString | ASTFilterWithLiteralEquality;
1414
1460
  };
1415
1461
  export declare class ASTFilterWithFilterString extends ASTObjectNode<Malloy.FilterWithFilterString, {
1416
1462
  kind: 'filter_string';
@@ -1429,6 +1475,17 @@ export declare class ASTFilterWithFilterString extends ASTObjectNode<Malloy.Filt
1429
1475
  setFilter(filter: ParsedFilter): void;
1430
1476
  getFilter(): ParsedFilter;
1431
1477
  }
1478
+ export declare class ASTFilterWithLiteralEquality extends ASTObjectNode<Malloy.FilterWithLiteralEquality, {
1479
+ kind: 'literal_equality';
1480
+ field_reference: ASTFieldReference;
1481
+ value: ASTLiteralValue;
1482
+ }> {
1483
+ node: Malloy.FilterWithLiteralEquality;
1484
+ readonly kind: Malloy.FilterType;
1485
+ constructor(node: Malloy.FilterWithLiteralEquality);
1486
+ get fieldReference(): ASTFieldReference;
1487
+ get value(): ASTLiteralValue;
1488
+ }
1432
1489
  export declare class ASTView extends ASTObjectNode<Malloy.View, {
1433
1490
  definition: ASTViewDefinition;
1434
1491
  annotations?: ASTAnnotationList;
package/dist/query-ast.js CHANGED
@@ -33,7 +33,7 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.ASTAnnotation = exports.ASTAnnotationList = exports.ASTLimitViewOperation = exports.ASTView = exports.ASTFilterWithFilterString = exports.ASTFilter = exports.ASTHavingViewOperation = exports.ASTWhereViewOperation = exports.ASTNestViewOperation = exports.ASTFilteredFieldExpression = exports.ASTFilterOperationList = exports.ASTFilterOperation = exports.ASTTimeTruncationExpression = exports.ASTReferenceExpression = exports.ASTExpression = exports.ASTField = exports.ASTAggregateViewOperation = exports.ASTGroupByViewOperation = exports.ASTOrderByViewOperation = exports.ASTViewOperation = exports.ASTViewOperationList = exports.ASTSegmentViewDefinition = exports.ASTRefinementViewDefinition = exports.ASTArrowViewDefinition = exports.ASTReferenceViewDefinition = exports.ASTReferenceQueryArrowSource = exports.ASTReferenceQueryDefinition = exports.ASTRefinementQueryDefinition = exports.ASTArrowQueryDefinition = exports.ASTQueryDefinition = exports.ASTQueryArrowSource = exports.ASTUnimplemented = exports.ASTFilterExpressionLiteralValue = exports.ASTTimestampLiteralValue = exports.ASTDateLiteralValue = exports.ASTBooleanLiteralValue = exports.ASTNumberLiteralValue = exports.ASTNullLiteralValue = exports.ASTStringLiteralValue = exports.ASTLiteralValue = exports.ASTParameterValue = exports.ASTParameterValueList = exports.ASTFieldReference = exports.ASTReference = exports.ASTQuery = void 0;
36
+ exports.ASTAnnotation = exports.ASTAnnotationList = exports.ASTLimitViewOperation = exports.ASTView = exports.ASTFilterWithLiteralEquality = exports.ASTFilterWithFilterString = exports.ASTFilter = exports.ASTHavingViewOperation = exports.ASTDrillViewOperation = exports.ASTWhereViewOperation = exports.ASTNestViewOperation = exports.ASTFilteredFieldExpression = exports.ASTFilterOperationList = exports.ASTFilterOperation = exports.ASTLiteralValueExpression = exports.ASTTimeTruncationExpression = exports.ASTReferenceExpression = exports.ASTExpression = exports.ASTField = exports.ASTAggregateViewOperation = exports.ASTGroupByViewOperation = exports.ASTOrderByViewOperation = exports.ASTViewOperation = exports.ASTViewOperationList = exports.ASTSegmentViewDefinition = exports.ASTRefinementViewDefinition = exports.ASTArrowViewDefinition = exports.ASTReferenceViewDefinition = exports.ASTReferenceQueryArrowSource = exports.ASTReferenceQueryDefinition = exports.ASTRefinementQueryDefinition = exports.ASTArrowQueryDefinition = exports.ASTQueryDefinition = exports.ASTQueryArrowSource = exports.ASTUnimplemented = exports.ASTFilterExpressionLiteralValue = exports.ASTTimestampLiteralValue = exports.ASTDateLiteralValue = exports.ASTBooleanLiteralValue = exports.ASTNumberLiteralValue = exports.ASTNullLiteralValue = exports.ASTStringLiteralValue = exports.ASTLiteralValue = exports.ASTParameterValue = exports.ASTParameterValueList = exports.ASTFieldReference = exports.ASTReference = exports.ASTQuery = void 0;
37
37
  /*
38
38
  * Copyright (c) Meta Platforms, Inc. and affiliates.
39
39
  *
@@ -306,13 +306,25 @@ class ASTNode {
306
306
  * @internal
307
307
  */
308
308
  static schemaTryGet(schema, name, path) {
309
+ return ASTNode._schemaTryGet(schema, name, path, false);
310
+ }
311
+ /**
312
+ * @internal
313
+ */
314
+ static schemaTryGetDrillField(schema, name, path) {
315
+ return ASTNode._schemaTryGet(schema, name, path, true);
316
+ }
317
+ /**
318
+ * @internal
319
+ */
320
+ static _schemaTryGet(schema, name, path, isDrill) {
309
321
  let current = schema.fields;
310
322
  for (const part of path !== null && path !== void 0 ? path : []) {
311
323
  const field = current.find(f => f.name === part);
312
324
  if (field === undefined) {
313
325
  throw new Error(`${part} not found`);
314
326
  }
315
- if (field.kind === 'join') {
327
+ if (field.kind === 'join' || (isDrill && field.kind === 'view')) {
316
328
  current = field.schema.fields;
317
329
  continue;
318
330
  }
@@ -348,6 +360,16 @@ class ASTNode {
348
360
  }
349
361
  return field;
350
362
  }
363
+ /**
364
+ * @internal
365
+ */
366
+ static schemaGetDrillField(schema, name, path) {
367
+ const field = ASTNode.schemaTryGetDrillField(schema, name, path);
368
+ if (field === undefined) {
369
+ throw new Error(`${name} not found`);
370
+ }
371
+ return field;
372
+ }
351
373
  /**
352
374
  * @internal
353
375
  */
@@ -910,7 +932,8 @@ class ASTFieldReference extends ASTReference {
910
932
  parent instanceof ASTTimeTruncationExpression) {
911
933
  return parent.field.segment;
912
934
  }
913
- else if (parent instanceof ASTFilterWithFilterString) {
935
+ else if (parent instanceof ASTFilterWithFilterString ||
936
+ parent instanceof ASTFilterWithLiteralEquality) {
914
937
  const grand = parent.parent;
915
938
  if (grand instanceof ASTFilterOperation) {
916
939
  return grand.list.expression.field.segment;
@@ -931,7 +954,14 @@ class ASTFieldReference extends ASTReference {
931
954
  }
932
955
  getFieldInfo() {
933
956
  const schema = this.getReferenceSchema();
934
- return ASTNode.schemaGet(schema, this.name, this.path);
957
+ const isDrill = this.parent instanceof ASTFilterWithLiteralEquality &&
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
+ }
935
965
  }
936
966
  }
937
967
  exports.ASTFieldReference = ASTFieldReference;
@@ -1045,6 +1075,11 @@ class ASTStringLiteralValue extends ASTObjectNode {
1045
1075
  this.node = node;
1046
1076
  this.kind = 'string_literal';
1047
1077
  }
1078
+ get fieldType() {
1079
+ return {
1080
+ kind: 'string_type',
1081
+ };
1082
+ }
1048
1083
  }
1049
1084
  exports.ASTStringLiteralValue = ASTStringLiteralValue;
1050
1085
  class ASTNullLiteralValue extends ASTObjectNode {
@@ -1055,6 +1090,9 @@ class ASTNullLiteralValue extends ASTObjectNode {
1055
1090
  this.node = node;
1056
1091
  this.kind = 'null_literal';
1057
1092
  }
1093
+ get fieldType() {
1094
+ return undefined;
1095
+ }
1058
1096
  }
1059
1097
  exports.ASTNullLiteralValue = ASTNullLiteralValue;
1060
1098
  class ASTNumberLiteralValue extends ASTObjectNode {
@@ -1066,6 +1104,14 @@ class ASTNumberLiteralValue extends ASTObjectNode {
1066
1104
  this.node = node;
1067
1105
  this.kind = 'number_literal';
1068
1106
  }
1107
+ get fieldType() {
1108
+ return {
1109
+ kind: 'number_type',
1110
+ subtype: Number.isInteger(this.children.number_value)
1111
+ ? 'integer'
1112
+ : 'decimal',
1113
+ };
1114
+ }
1069
1115
  }
1070
1116
  exports.ASTNumberLiteralValue = ASTNumberLiteralValue;
1071
1117
  class ASTBooleanLiteralValue extends ASTObjectNode {
@@ -1077,6 +1123,11 @@ class ASTBooleanLiteralValue extends ASTObjectNode {
1077
1123
  this.node = node;
1078
1124
  this.kind = 'boolean_literal';
1079
1125
  }
1126
+ get fieldType() {
1127
+ return {
1128
+ kind: 'boolean_type',
1129
+ };
1130
+ }
1080
1131
  }
1081
1132
  exports.ASTBooleanLiteralValue = ASTBooleanLiteralValue;
1082
1133
  class ASTDateLiteralValue extends ASTObjectNode {
@@ -1089,6 +1140,12 @@ class ASTDateLiteralValue extends ASTObjectNode {
1089
1140
  this.node = node;
1090
1141
  this.kind = 'date_literal';
1091
1142
  }
1143
+ get fieldType() {
1144
+ return {
1145
+ kind: 'date_type',
1146
+ timeframe: this.children.granularity,
1147
+ };
1148
+ }
1092
1149
  }
1093
1150
  exports.ASTDateLiteralValue = ASTDateLiteralValue;
1094
1151
  class ASTTimestampLiteralValue extends ASTObjectNode {
@@ -1101,6 +1158,12 @@ class ASTTimestampLiteralValue extends ASTObjectNode {
1101
1158
  this.node = node;
1102
1159
  this.kind = 'timestamp_literal';
1103
1160
  }
1161
+ get fieldType() {
1162
+ return {
1163
+ kind: 'timestamp_type',
1164
+ timeframe: this.children.granularity,
1165
+ };
1166
+ }
1104
1167
  }
1105
1168
  exports.ASTTimestampLiteralValue = ASTTimestampLiteralValue;
1106
1169
  class ASTFilterExpressionLiteralValue extends ASTObjectNode {
@@ -1112,6 +1175,9 @@ class ASTFilterExpressionLiteralValue extends ASTObjectNode {
1112
1175
  this.node = node;
1113
1176
  this.kind = 'filter_expression_literal';
1114
1177
  }
1178
+ get fieldType() {
1179
+ return undefined;
1180
+ }
1115
1181
  }
1116
1182
  exports.ASTFilterExpressionLiteralValue = ASTFilterExpressionLiteralValue;
1117
1183
  class ASTUnimplemented extends ASTNode {
@@ -1840,6 +1906,7 @@ class ASTSegmentViewDefinition extends ASTObjectNode {
1840
1906
  this.DEFAULT_INSERTION_ORDER = [
1841
1907
  'group_by',
1842
1908
  'aggregate',
1909
+ 'drill',
1843
1910
  'where',
1844
1911
  'having',
1845
1912
  'nest',
@@ -2104,7 +2171,9 @@ class ASTSegmentViewDefinition extends ASTObjectNode {
2104
2171
  if (operation instanceof ASTGroupByViewOperation ||
2105
2172
  operation instanceof ASTAggregateViewOperation) {
2106
2173
  const reference = operation.field.getReference();
2107
- if (reference.name === name && pathsMatch(reference.path, path)) {
2174
+ if (reference &&
2175
+ reference.name === name &&
2176
+ pathsMatch(reference.path, path)) {
2108
2177
  return operation;
2109
2178
  }
2110
2179
  }
@@ -2203,6 +2272,14 @@ class ASTSegmentViewDefinition extends ASTObjectNode {
2203
2272
  this.addOperation(item);
2204
2273
  return item;
2205
2274
  }
2275
+ addDrill(drill) {
2276
+ const item = new ASTDrillViewOperation({
2277
+ kind: 'drill',
2278
+ ...drill,
2279
+ });
2280
+ this.addOperation(item);
2281
+ return item;
2282
+ }
2206
2283
  addWhere(name, arg2, arg3) {
2207
2284
  const path = Array.isArray(arg2) ? arg2 : [];
2208
2285
  const filter = arg3 === undefined ? arg2 : arg3;
@@ -2485,6 +2562,8 @@ exports.ASTViewOperation = {
2485
2562
  return new ASTLimitViewOperation(value);
2486
2563
  case 'where':
2487
2564
  return new ASTWhereViewOperation(value);
2565
+ case 'drill':
2566
+ return new ASTDrillViewOperation(value);
2488
2567
  case 'having':
2489
2568
  return new ASTHavingViewOperation(value);
2490
2569
  }
@@ -2551,7 +2630,11 @@ class ASTGroupByViewOperation extends ASTObjectNode {
2551
2630
  }
2552
2631
  get name() {
2553
2632
  var _a;
2554
- return (_a = this.children.name) !== null && _a !== void 0 ? _a : this.field.name;
2633
+ const name = (_a = this.children.name) !== null && _a !== void 0 ? _a : this.field.name;
2634
+ if (name === undefined) {
2635
+ throw new Error('Group by does not have a name');
2636
+ }
2637
+ return name;
2555
2638
  }
2556
2639
  set name(name) {
2557
2640
  if (this.name === name)
@@ -2705,7 +2788,11 @@ class ASTAggregateViewOperation extends ASTObjectNode {
2705
2788
  }
2706
2789
  get name() {
2707
2790
  var _a;
2708
- return (_a = this.children.name) !== null && _a !== void 0 ? _a : this.field.name;
2791
+ const name = (_a = this.children.name) !== null && _a !== void 0 ? _a : this.field.name;
2792
+ if (name === undefined) {
2793
+ throw new Error('Aggregate does not have a name');
2794
+ }
2795
+ return name;
2709
2796
  }
2710
2797
  set name(name) {
2711
2798
  if (this.name === name)
@@ -2873,7 +2960,11 @@ class ASTField extends ASTObjectNode {
2873
2960
  return this.expression.name;
2874
2961
  }
2875
2962
  get type() {
2876
- return this.expression.fieldType;
2963
+ const type = this.expression.fieldType;
2964
+ if (type === undefined) {
2965
+ throw new Error('Field expression does not have a type');
2966
+ }
2967
+ return type;
2877
2968
  }
2878
2969
  get annotations() {
2879
2970
  return this.children.annotations;
@@ -2884,6 +2975,9 @@ class ASTField extends ASTObjectNode {
2884
2975
  }
2885
2976
  // Returns a Malloy reference that this field points to
2886
2977
  getReference() {
2978
+ if (this.expression instanceof ASTLiteralValueExpression) {
2979
+ return undefined;
2980
+ }
2887
2981
  return this.expression.getReference();
2888
2982
  }
2889
2983
  getOrAddAnnotations() {
@@ -2936,6 +3030,8 @@ exports.ASTExpression = {
2936
3030
  return new ASTFilteredFieldExpression(value);
2937
3031
  case 'time_truncation':
2938
3032
  return new ASTTimeTruncationExpression(value);
3033
+ case 'literal_value':
3034
+ return new ASTLiteralValueExpression(value);
2939
3035
  }
2940
3036
  },
2941
3037
  };
@@ -3060,6 +3156,29 @@ class ASTTimeTruncationExpression extends ASTObjectNode {
3060
3156
  }
3061
3157
  }
3062
3158
  exports.ASTTimeTruncationExpression = ASTTimeTruncationExpression;
3159
+ class ASTLiteralValueExpression extends ASTObjectNode {
3160
+ constructor(node) {
3161
+ super(node, {
3162
+ kind: node.kind,
3163
+ literal_value: exports.ASTLiteralValue.from(node.literal_value),
3164
+ });
3165
+ this.node = node;
3166
+ this.kind = 'time_truncation';
3167
+ }
3168
+ get name() {
3169
+ return undefined;
3170
+ }
3171
+ get literalValue() {
3172
+ return this.children.literal_value;
3173
+ }
3174
+ get fieldType() {
3175
+ return this.literalValue.fieldType;
3176
+ }
3177
+ getInheritedAnnotations() {
3178
+ return [];
3179
+ }
3180
+ }
3181
+ exports.ASTLiteralValueExpression = ASTLiteralValueExpression;
3063
3182
  class ASTFilterOperation extends ASTObjectNode {
3064
3183
  constructor(node) {
3065
3184
  super(node, {
@@ -3306,6 +3425,29 @@ class ASTWhereViewOperation extends ASTObjectNode {
3306
3425
  }
3307
3426
  }
3308
3427
  exports.ASTWhereViewOperation = ASTWhereViewOperation;
3428
+ class ASTDrillViewOperation extends ASTObjectNode {
3429
+ constructor(node) {
3430
+ super(node, {
3431
+ kind: 'drill',
3432
+ filter: exports.ASTFilter.from(node.filter),
3433
+ });
3434
+ this.node = node;
3435
+ this.kind = 'drill';
3436
+ }
3437
+ get filter() {
3438
+ return this.children.filter;
3439
+ }
3440
+ /**
3441
+ * @internal
3442
+ */
3443
+ get list() {
3444
+ return this.parent.as.ViewOperationList();
3445
+ }
3446
+ delete() {
3447
+ this.list.remove(this);
3448
+ }
3449
+ }
3450
+ exports.ASTDrillViewOperation = ASTDrillViewOperation;
3309
3451
  class ASTHavingViewOperation extends ASTObjectNode {
3310
3452
  constructor(node) {
3311
3453
  super(node, {
@@ -3331,7 +3473,12 @@ class ASTHavingViewOperation extends ASTObjectNode {
3331
3473
  exports.ASTHavingViewOperation = ASTHavingViewOperation;
3332
3474
  exports.ASTFilter = {
3333
3475
  from(filter) {
3334
- return new ASTFilterWithFilterString(filter);
3476
+ switch (filter.kind) {
3477
+ case 'filter_string':
3478
+ return new ASTFilterWithFilterString(filter);
3479
+ case 'literal_equality':
3480
+ return new ASTFilterWithLiteralEquality(filter);
3481
+ }
3335
3482
  },
3336
3483
  };
3337
3484
  class ASTFilterWithFilterString extends ASTObjectNode {
@@ -3383,6 +3530,24 @@ class ASTFilterWithFilterString extends ASTObjectNode {
3383
3530
  }
3384
3531
  }
3385
3532
  exports.ASTFilterWithFilterString = ASTFilterWithFilterString;
3533
+ class ASTFilterWithLiteralEquality extends ASTObjectNode {
3534
+ constructor(node) {
3535
+ super(node, {
3536
+ kind: 'literal_equality',
3537
+ field_reference: new ASTFieldReference(node.field_reference),
3538
+ value: exports.ASTLiteralValue.from(node.value),
3539
+ });
3540
+ this.node = node;
3541
+ this.kind = 'literal_equality';
3542
+ }
3543
+ get fieldReference() {
3544
+ return this.children.field_reference;
3545
+ }
3546
+ get value() {
3547
+ return this.children.value;
3548
+ }
3549
+ }
3550
+ exports.ASTFilterWithLiteralEquality = ASTFilterWithLiteralEquality;
3386
3551
  class ASTView extends ASTObjectNode {
3387
3552
  constructor(node) {
3388
3553
  super(node, {