@malloydata/malloy 0.0.22-dev230207182613 → 0.0.22-dev230207183024

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.
Files changed (155) hide show
  1. package/dist/connection_utils.js +7 -7
  2. package/dist/dialect/dialect.d.ts +1 -1
  3. package/dist/dialect/duckdb.d.ts +1 -1
  4. package/dist/dialect/duckdb.js +9 -9
  5. package/dist/dialect/postgres.d.ts +1 -1
  6. package/dist/dialect/postgres.js +16 -16
  7. package/dist/dialect/standardsql.d.ts +1 -1
  8. package/dist/dialect/standardsql.js +8 -8
  9. package/dist/index.d.ts +6 -6
  10. package/dist/lang/ast/ast-utils.js +3 -3
  11. package/dist/lang/ast/elements/define-query.js +4 -4
  12. package/dist/lang/ast/elements/define-source.d.ts +1 -1
  13. package/dist/lang/ast/elements/define-source.js +8 -8
  14. package/dist/lang/ast/elements/import-statement.js +2 -2
  15. package/dist/lang/ast/elements/pipeline-desc.d.ts +1 -1
  16. package/dist/lang/ast/elements/pipeline-desc.js +7 -7
  17. package/dist/lang/ast/elements/refined-source.d.ts +1 -1
  18. package/dist/lang/ast/elements/refined-source.js +5 -5
  19. package/dist/lang/ast/elements/source.js +1 -1
  20. package/dist/lang/ast/error-factory.js +16 -13
  21. package/dist/lang/ast/expressions/binary-boolean.d.ts +1 -1
  22. package/dist/lang/ast/expressions/binary-boolean.js +4 -4
  23. package/dist/lang/ast/expressions/binary-numeric.d.ts +1 -1
  24. package/dist/lang/ast/expressions/binary-numeric.js +1 -1
  25. package/dist/lang/ast/expressions/boolean.js +1 -1
  26. package/dist/lang/ast/expressions/constant-sub-expression.js +7 -7
  27. package/dist/lang/ast/expressions/expr-aggregate-function.d.ts +3 -3
  28. package/dist/lang/ast/expressions/expr-aggregate-function.js +12 -12
  29. package/dist/lang/ast/expressions/expr-alternation-tree.js +3 -3
  30. package/dist/lang/ast/expressions/expr-asymmetric.d.ts +1 -1
  31. package/dist/lang/ast/expressions/expr-asymmetric.js +1 -1
  32. package/dist/lang/ast/expressions/expr-avg.d.ts +1 -1
  33. package/dist/lang/ast/expressions/expr-avg.js +1 -1
  34. package/dist/lang/ast/expressions/expr-cast.d.ts +1 -1
  35. package/dist/lang/ast/expressions/expr-cast.js +26 -4
  36. package/dist/lang/ast/expressions/expr-compare.d.ts +1 -1
  37. package/dist/lang/ast/expressions/expr-compare.js +3 -3
  38. package/dist/lang/ast/expressions/expr-count.js +6 -6
  39. package/dist/lang/ast/expressions/expr-filter.d.ts +2 -2
  40. package/dist/lang/ast/expressions/expr-filter.js +8 -8
  41. package/dist/lang/ast/expressions/expr-func.d.ts +1 -1
  42. package/dist/lang/ast/expressions/expr-func.js +3 -3
  43. package/dist/lang/ast/expressions/expr-granular-time.js +7 -7
  44. package/dist/lang/ast/expressions/expr-id-reference.js +11 -11
  45. package/dist/lang/ast/expressions/expr-logical-op.js +1 -1
  46. package/dist/lang/ast/expressions/expr-minus.d.ts +1 -1
  47. package/dist/lang/ast/expressions/expr-minus.js +3 -3
  48. package/dist/lang/ast/expressions/expr-not.js +2 -2
  49. package/dist/lang/ast/expressions/expr-now.js +7 -7
  50. package/dist/lang/ast/expressions/expr-null.js +3 -3
  51. package/dist/lang/ast/expressions/expr-number.js +1 -1
  52. package/dist/lang/ast/expressions/expr-parens.js +2 -2
  53. package/dist/lang/ast/expressions/expr-regex.js +3 -3
  54. package/dist/lang/ast/expressions/expr-string.js +6 -6
  55. package/dist/lang/ast/expressions/expr-sum.d.ts +1 -1
  56. package/dist/lang/ast/expressions/expr-sum.js +1 -1
  57. package/dist/lang/ast/expressions/expr-time-extract.d.ts +1 -1
  58. package/dist/lang/ast/expressions/expr-time-extract.js +29 -29
  59. package/dist/lang/ast/expressions/expr-time.js +7 -7
  60. package/dist/lang/ast/expressions/expr-ungroup.d.ts +2 -2
  61. package/dist/lang/ast/expressions/expr-ungroup.js +11 -8
  62. package/dist/lang/ast/expressions/for-range.d.ts +1 -1
  63. package/dist/lang/ast/expressions/for-range.js +1 -1
  64. package/dist/lang/ast/expressions/granular-literal.js +12 -12
  65. package/dist/lang/ast/expressions/partial-compare.d.ts +1 -1
  66. package/dist/lang/ast/expressions/partial-compare.js +1 -1
  67. package/dist/lang/ast/expressions/pick-when.d.ts +1 -1
  68. package/dist/lang/ast/expressions/pick-when.js +11 -11
  69. package/dist/lang/ast/expressions/range.js +4 -4
  70. package/dist/lang/ast/expressions/top-by.d.ts +1 -1
  71. package/dist/lang/ast/expressions/top-by.js +4 -4
  72. package/dist/lang/ast/expressions/unary.js +1 -1
  73. package/dist/lang/ast/field-space/dynamic-space.d.ts +1 -1
  74. package/dist/lang/ast/field-space/dynamic-space.js +1 -1
  75. package/dist/lang/ast/field-space/index-field-space.js +2 -2
  76. package/dist/lang/ast/field-space/query-field-struct.js +1 -1
  77. package/dist/lang/ast/field-space/query-space-field.js +1 -1
  78. package/dist/lang/ast/field-space/query-spaces.js +2 -2
  79. package/dist/lang/ast/field-space/reference-field.js +1 -1
  80. package/dist/lang/ast/field-space/rename-space-field.js +2 -2
  81. package/dist/lang/ast/field-space/static-space.js +8 -8
  82. package/dist/lang/ast/field-space/struct-space-field-base.js +1 -1
  83. package/dist/lang/ast/fragtype-utils.js +2 -2
  84. package/dist/lang/ast/parameters/constant-parameter.js +9 -9
  85. package/dist/lang/ast/parameters/has-parameter.js +5 -5
  86. package/dist/lang/ast/query-elements/anonymous-query.js +1 -1
  87. package/dist/lang/ast/query-elements/existing-query.d.ts +1 -1
  88. package/dist/lang/ast/query-elements/existing-query.js +11 -11
  89. package/dist/lang/ast/query-elements/full-query.js +11 -11
  90. package/dist/lang/ast/query-elements/query-head-struct.js +1 -1
  91. package/dist/lang/ast/query-items/field-declaration.d.ts +1 -1
  92. package/dist/lang/ast/query-items/field-declaration.js +11 -11
  93. package/dist/lang/ast/query-items/field-references.d.ts +1 -1
  94. package/dist/lang/ast/query-items/field-references.js +1 -1
  95. package/dist/lang/ast/query-properties/filters.d.ts +1 -1
  96. package/dist/lang/ast/query-properties/filters.js +7 -7
  97. package/dist/lang/ast/query-properties/indexing.d.ts +1 -1
  98. package/dist/lang/ast/query-properties/indexing.js +2 -2
  99. package/dist/lang/ast/query-properties/joins.d.ts +1 -1
  100. package/dist/lang/ast/query-properties/joins.js +17 -14
  101. package/dist/lang/ast/query-properties/nest.js +4 -4
  102. package/dist/lang/ast/query-properties/ordering.js +2 -2
  103. package/dist/lang/ast/query-properties/qop-desc.js +1 -1
  104. package/dist/lang/ast/query-properties/top.js +3 -3
  105. package/dist/lang/ast/source-properties/field-list-edit.js +1 -1
  106. package/dist/lang/ast/source-properties/primary-key.js +1 -1
  107. package/dist/lang/ast/source-properties/renames.js +1 -1
  108. package/dist/lang/ast/sources/named-source.d.ts +2 -2
  109. package/dist/lang/ast/sources/named-source.js +6 -6
  110. package/dist/lang/ast/sources/query-source.d.ts +1 -1
  111. package/dist/lang/ast/sources/query-source.js +2 -2
  112. package/dist/lang/ast/sources/table-source.js +7 -5
  113. package/dist/lang/ast/space-seed.d.ts +1 -1
  114. package/dist/lang/ast/sql-elements/sql-statement.js +5 -5
  115. package/dist/lang/ast/sql-elements/sql-string.js +1 -1
  116. package/dist/lang/ast/struct-utils.js +2 -2
  117. package/dist/lang/ast/time-utils.js +32 -32
  118. package/dist/lang/ast/types/expression-def.js +34 -34
  119. package/dist/lang/ast/types/malloy-element.d.ts +4 -4
  120. package/dist/lang/ast/types/malloy-element.js +27 -27
  121. package/dist/lang/ast/types/query-comp.d.ts +1 -1
  122. package/dist/lang/ast/types/space-field.js +1 -1
  123. package/dist/lang/ast/types/space-param.js +2 -2
  124. package/dist/lang/ast/types/turtle-headed-pipe.d.ts +1 -1
  125. package/dist/lang/ast/types/turtle-headed-pipe.js +1 -1
  126. package/dist/lang/ast/types/type-desc.d.ts +1 -1
  127. package/dist/lang/field-utils.d.ts +1 -1
  128. package/dist/lang/index.d.ts +1 -1
  129. package/dist/lang/malloy-to-ast.d.ts +1 -1
  130. package/dist/lang/malloy-to-ast.js +11 -11
  131. package/dist/lang/parse-error-handler.js +4 -4
  132. package/dist/lang/parse-malloy.d.ts +4 -4
  133. package/dist/lang/parse-malloy.js +61 -61
  134. package/dist/lang/parse-tree-walkers/document-completion-walker.js +16 -16
  135. package/dist/lang/parse-tree-walkers/document-help-context-walker.js +10 -10
  136. package/dist/lang/parse-tree-walkers/document-highlight-walker.js +85 -82
  137. package/dist/lang/parse-tree-walkers/document-symbol-walker.js +40 -40
  138. package/dist/lang/parse-tree-walkers/find-external-references.d.ts +1 -1
  139. package/dist/lang/parse-tree-walkers/find-external-references.js +2 -2
  140. package/dist/lang/reference-list.d.ts +1 -1
  141. package/dist/lang/test/document-help-context-walker.spec.js +6 -6
  142. package/dist/lang/test/document-symbol-walker.spec.js +3 -3
  143. package/dist/lang/test/field-symbols.spec.js +62 -58
  144. package/dist/lang/test/parse.spec.js +262 -260
  145. package/dist/lang/test/test-translator.d.ts +1 -1
  146. package/dist/lang/test/test-translator.js +139 -139
  147. package/dist/lang/translate-response.d.ts +1 -1
  148. package/dist/lang/zone.js +5 -5
  149. package/dist/malloy.d.ts +5 -5
  150. package/dist/malloy.js +72 -72
  151. package/dist/model/malloy_query.d.ts +2 -2
  152. package/dist/model/malloy_query.js +179 -176
  153. package/dist/model/malloy_types.js +41 -41
  154. package/dist/model/sql_block.js +2 -2
  155. package/package.json +1 -1
@@ -24,8 +24,8 @@
24
24
  Object.defineProperty(exports, "__esModule", { value: true });
25
25
  exports.flattenQuery = exports.QueryModel = exports.Segment = void 0;
26
26
  const lodash_1 = require("lodash");
27
- const standardsql_1 = require("../dialect/standardsql");
28
27
  const dialect_1 = require("../dialect");
28
+ const standardsql_1 = require("../dialect/standardsql");
29
29
  const malloy_types_1 = require("./malloy_types");
30
30
  const utils_1 = require("./utils");
31
31
  // quote a string for SQL use. Perhaps should be in dialect.
@@ -84,7 +84,7 @@ class StageWriter {
84
84
  // return SQL and the last stage name
85
85
  combineStages(includeLastStage) {
86
86
  if (!this.useCTE) {
87
- return { sql: this.withs[0], lastStageName: this.withs[0] };
87
+ return { "sql": this.withs[0], "lastStageName": this.withs[0] };
88
88
  }
89
89
  let lastStageName = this.getName(0);
90
90
  let prefix = `WITH `;
@@ -98,7 +98,7 @@ class StageWriter {
98
98
  w += `${prefix}${lastStageName} AS (\n${(0, utils_1.indent)(sql)})\n`;
99
99
  prefix = ", ";
100
100
  }
101
- return { sql: w, lastStageName };
101
+ return { "sql": w, lastStageName };
102
102
  }
103
103
  /** emit the SQL for all the stages. */
104
104
  generateSQLStages() {
@@ -362,16 +362,15 @@ class QueryField extends QueryNode {
362
362
  for (const ordering of orderByDef) {
363
363
  if (typeof ordering.field === "string") {
364
364
  orderingField = {
365
- name: ordering.field,
366
- fif: resultStruct.getField(ordering.field),
365
+ "name": ordering.field,
366
+ "fif": resultStruct.getField(ordering.field)
367
367
  };
368
368
  }
369
369
  else {
370
370
  orderingField = resultStruct.getFieldByNumber(ordering.field);
371
371
  }
372
372
  if (resultStruct.firstSegment.type === "reduce") {
373
- obSQL.push(" " +
374
- orderingField.fif.getSQL() +
373
+ obSQL.push(` ${orderingField.fif.getSQL()}` +
375
374
  // this.parent.dialect.sqlMaybeQuoteIdentifier(
376
375
  // `${orderingField.name}__${resultStruct.groupSet}`
377
376
  // ) +
@@ -481,7 +480,7 @@ class QueryField extends QueryNode {
481
480
  this.parent.fieldDef.structSource.type === "inline" ||
482
481
  (this.parent.fieldDef.structSource.type === "sql" &&
483
482
  this.parent.fieldDef.structSource.method === "nested"), this.parent.fieldDef.structRelationship.type === "nested" &&
484
- this.parent.fieldDef.structRelationship.isArray),
483
+ this.parent.fieldDef.structRelationship.isArray)
485
484
  ];
486
485
  }
487
486
  generateExpression(resultSet) {
@@ -532,17 +531,17 @@ class QueryFieldStruct extends QueryAtomicField {
532
531
  getAsJoinedStructDef(foreignKeyName) {
533
532
  return {
534
533
  ...this.parent.fieldDef,
535
- structRelationship: {
536
- type: "one",
537
- onExpression: [
534
+ "structRelationship": {
535
+ "type": "one",
536
+ "onExpression": [
538
537
  {
539
- type: "field",
540
- path: this.primaryKey,
538
+ "type": "field",
539
+ "path": this.primaryKey
541
540
  },
542
541
  "=",
543
- { type: "field", path: foreignKeyName },
544
- ],
545
- },
542
+ { "type": "field", "path": foreignKeyName }
543
+ ]
544
+ }
546
545
  };
547
546
  }
548
547
  }
@@ -553,7 +552,7 @@ class QueryFieldDate extends QueryAtomicField {
553
552
  return super.generateExpression(resultSet);
554
553
  }
555
554
  else {
556
- const truncated = this.parent.dialect.sqlTrunc({ value: this.getExpr(), valueType: "date" }, fd.timeframe);
555
+ const truncated = this.parent.dialect.sqlTrunc({ "value": this.getExpr(), "valueType": "date" }, fd.timeframe);
557
556
  return this.generateExpressionFromExpr(resultSet, this.parent, truncated);
558
557
  }
559
558
  }
@@ -561,8 +560,8 @@ class QueryFieldDate extends QueryAtomicField {
561
560
  getChildByName(name) {
562
561
  const fieldDef = {
563
562
  ...this.fieldDef,
564
- as: `${this.getIdentifier()}_${name}`,
565
- timeframe: name,
563
+ "as": `${this.getIdentifier()}_${name}`,
564
+ "timeframe": name
566
565
  };
567
566
  return new QueryFieldDate(fieldDef, this.parent);
568
567
  }
@@ -572,8 +571,8 @@ class QueryFieldTimestamp extends QueryAtomicField {
572
571
  getChildByName(name) {
573
572
  const fieldDef = {
574
573
  ...this.fieldDef,
575
- as: `${this.getIdentifier()}_${name}`,
576
- timeframe: name,
574
+ "as": `${this.getIdentifier()}_${name}`,
575
+ "timeframe": name
577
576
  };
578
577
  return new QueryFieldTimestamp(fieldDef, this.parent);
579
578
  }
@@ -709,7 +708,7 @@ class FieldInstanceResult {
709
708
  if (fi instanceof FieldInstanceField) {
710
709
  if (fi.fieldUsage.type === "result" &&
711
710
  fi.fieldUsage.resultIndex === index) {
712
- return { name, fif: fi };
711
+ return { name, "fif": fi };
713
712
  }
714
713
  }
715
714
  }
@@ -818,16 +817,16 @@ class FieldInstanceResult {
818
817
  if (fi.fieldUsage.type === "result") {
819
818
  firstField || (firstField = fi.fieldUsage.resultIndex);
820
819
  if (["date", "timestamp"].indexOf(fi.f.fieldDef.type) > -1) {
821
- return [{ dir: "desc", field: fi.fieldUsage.resultIndex }];
820
+ return [{ "dir": "desc", "field": fi.fieldUsage.resultIndex }];
822
821
  }
823
822
  else if (isCalculatedField(fi.f)) {
824
- return [{ dir: "desc", field: fi.fieldUsage.resultIndex }];
823
+ return [{ "dir": "desc", "field": fi.fieldUsage.resultIndex }];
825
824
  }
826
825
  }
827
826
  }
828
827
  }
829
828
  if (firstField) {
830
- return [{ dir: "asc", field: firstField }];
829
+ return [{ "dir": "asc", "field": firstField }];
831
830
  }
832
831
  return [];
833
832
  }
@@ -859,7 +858,7 @@ class FieldInstanceResult {
859
858
  joinStack.indexOf(name) === -1) {
860
859
  query.addDependantExpr(this, qs.parent, sr.onExpression, [
861
860
  ...joinStack,
862
- name,
861
+ name
863
862
  ]);
864
863
  }
865
864
  if (!(join = this.root().joins.get(name))) {
@@ -1030,9 +1029,9 @@ class JoinInstance {
1030
1029
  this.joinFilterConditions = [];
1031
1030
  for (const filter of this.queryStruct.fieldDef.filterList) {
1032
1031
  const qf = new QueryFieldBoolean({
1033
- type: "boolean",
1034
- name: "ignoreme",
1035
- e: filter.expression,
1032
+ "type": "boolean",
1033
+ "name": "ignoreme",
1034
+ "e": filter.expression
1036
1035
  }, this.queryStruct);
1037
1036
  this.joinFilterConditions.push(qf);
1038
1037
  }
@@ -1062,9 +1061,9 @@ class JoinInstance {
1062
1061
  const dialectFieldList = [];
1063
1062
  for (const f of this.queryStruct.fieldDef.fields.filter(malloy_types_1.isPhysical)) {
1064
1063
  dialectFieldList.push({
1065
- type: f.type,
1066
- sqlExpression: (0, malloy_types_1.getIdentifier)(f),
1067
- sqlOutputName: (0, malloy_types_1.getIdentifier)(f),
1064
+ "type": f.type,
1065
+ "sqlExpression": (0, malloy_types_1.getIdentifier)(f),
1066
+ "sqlOutputName": (0, malloy_types_1.getIdentifier)(f)
1068
1067
  });
1069
1068
  }
1070
1069
  return dialectFieldList;
@@ -1082,12 +1081,12 @@ class Segment {
1082
1081
  // static nextStructDef(s: StructDef, q: AnonymousQueryDef): StructDef
1083
1082
  static nextStructDef(structDef, segment) {
1084
1083
  const qs = new QueryStruct(structDef, {
1085
- model: new QueryModel(undefined),
1084
+ "model": new QueryModel(undefined)
1086
1085
  });
1087
1086
  const turtleDef = {
1088
- type: "turtle",
1089
- name: "ignoreme",
1090
- pipeline: [segment],
1087
+ "type": "turtle",
1088
+ "name": "ignoreme",
1089
+ "pipeline": [segment]
1091
1090
  };
1092
1091
  const queryQueryQuery = QueryQuery.makeQuery(turtleDef, qs, new StageWriter(true, undefined) // stage write indicates we want to get a result.
1093
1092
  );
@@ -1121,17 +1120,20 @@ class QueryQuery extends QueryField {
1121
1120
  firstStage.extendSource !== undefined) {
1122
1121
  parent = new QueryStruct({
1123
1122
  ...parentStruct.fieldDef,
1124
- fields: [...parentStruct.fieldDef.fields, ...firstStage.extendSource],
1125
- }, parent.parent ? { struct: parent } : { model: parent.model });
1123
+ "fields": [
1124
+ ...parentStruct.fieldDef.fields,
1125
+ ...firstStage.extendSource
1126
+ ]
1127
+ }, parent.parent ? { "struct": parent } : { "model": parent.model });
1126
1128
  flatTurtleDef = {
1127
1129
  ...flatTurtleDef,
1128
- pipeline: [
1130
+ "pipeline": [
1129
1131
  {
1130
1132
  ...firstStage,
1131
- extendSource: undefined,
1133
+ "extendSource": undefined
1132
1134
  },
1133
- ...flatTurtleDef.pipeline.slice(1),
1134
- ],
1135
+ ...flatTurtleDef.pipeline.slice(1)
1136
+ ]
1135
1137
  };
1136
1138
  }
1137
1139
  switch (firstStage.type) {
@@ -1299,9 +1301,9 @@ class QueryQuery extends QueryField {
1299
1301
  const key = expr.fields.sort().join("|") + expr.type;
1300
1302
  if (resultStruct.ungroupedSets.get(key) === undefined) {
1301
1303
  resultStruct.ungroupedSets.set(key, {
1302
- type: expr.type,
1303
- fields: expr.fields,
1304
- groupSet: -1,
1304
+ "type": expr.type,
1305
+ "fields": expr.fields,
1306
+ "groupSet": -1
1305
1307
  });
1306
1308
  }
1307
1309
  }
@@ -1395,7 +1397,7 @@ class QueryQuery extends QueryField {
1395
1397
  else if (field instanceof QueryAtomicField) {
1396
1398
  resultStruct.addField(as, field, {
1397
1399
  resultIndex,
1398
- type: "result",
1400
+ "type": "result"
1399
1401
  });
1400
1402
  this.addDependancies(resultStruct, field);
1401
1403
  if (isCalculatedField(field)) {
@@ -1478,7 +1480,8 @@ class QueryQuery extends QueryField {
1478
1480
  if (fi.fieldUsage.type === "result") {
1479
1481
  const fieldDef = fi.f.fieldDef;
1480
1482
  let filterList;
1481
- const sourceField = fi.f.parent.getFullOutputName() + (fieldDef.name || fieldDef.as);
1483
+ const sourceField = fi.f.parent.getFullOutputName() +
1484
+ (fieldDef.name || fieldDef.as || "undefined");
1482
1485
  const sourceExpression = fieldDef.code;
1483
1486
  const sourceClasses = [sourceField];
1484
1487
  if (isCalculatedField(fi.f)) {
@@ -1488,7 +1491,7 @@ class QueryQuery extends QueryField {
1488
1491
  sourceExpression,
1489
1492
  filterList,
1490
1493
  sourceClasses,
1491
- fieldKind: "measure",
1494
+ "fieldKind": "measure"
1492
1495
  };
1493
1496
  }
1494
1497
  if (isScalarField(fi.f)) {
@@ -1497,7 +1500,7 @@ class QueryQuery extends QueryField {
1497
1500
  sourceExpression,
1498
1501
  filterList,
1499
1502
  sourceClasses,
1500
- fieldKind: "dimension",
1503
+ "fieldKind": "dimension"
1501
1504
  };
1502
1505
  }
1503
1506
  else {
@@ -1516,8 +1519,8 @@ class QueryQuery extends QueryField {
1516
1519
  sourceField,
1517
1520
  filterList,
1518
1521
  sourceClasses,
1519
- fieldKind: "struct",
1520
- limit,
1522
+ "fieldKind": "struct",
1523
+ limit
1521
1524
  };
1522
1525
  }
1523
1526
  }
@@ -1538,11 +1541,11 @@ class QueryQuery extends QueryField {
1538
1541
  const resultType = fi.getRepeatedResultType() === "nested" ? "nested" : "inline";
1539
1542
  structDef.name = name;
1540
1543
  structDef.structRelationship = {
1541
- field: name,
1542
- type: resultType,
1543
- isArray: false,
1544
+ "field": name,
1545
+ "type": resultType,
1546
+ "isArray": false
1544
1547
  };
1545
- structDef.structSource = { type: resultType };
1548
+ structDef.structSource = { "type": resultType };
1546
1549
  structDef.resultMetadata = resultMetadata;
1547
1550
  fields.push(structDef);
1548
1551
  }
@@ -1570,9 +1573,9 @@ class QueryQuery extends QueryField {
1570
1573
  case "string":
1571
1574
  fields.push({
1572
1575
  name,
1573
- type: fi.f.fieldDef.type,
1576
+ "type": fi.f.fieldDef.type,
1574
1577
  resultMetadata,
1575
- location,
1578
+ location
1576
1579
  });
1577
1580
  break;
1578
1581
  case "timestamp": {
@@ -1585,10 +1588,10 @@ class QueryQuery extends QueryField {
1585
1588
  case "day":
1586
1589
  fields.push({
1587
1590
  name,
1588
- type: "date",
1591
+ "type": "date",
1589
1592
  timeframe,
1590
1593
  resultMetadata,
1591
- location,
1594
+ location
1592
1595
  });
1593
1596
  break;
1594
1597
  case "second":
@@ -1596,18 +1599,18 @@ class QueryQuery extends QueryField {
1596
1599
  case "hour":
1597
1600
  fields.push({
1598
1601
  name,
1599
- type: "timestamp",
1602
+ "type": "timestamp",
1600
1603
  timeframe,
1601
1604
  resultMetadata,
1602
- location,
1605
+ location
1603
1606
  });
1604
1607
  break;
1605
1608
  default:
1606
1609
  fields.push({
1607
1610
  name,
1608
- type: "timestamp",
1611
+ "type": "timestamp",
1609
1612
  resultMetadata,
1610
- location,
1613
+ location
1611
1614
  });
1612
1615
  break;
1613
1616
  }
@@ -1616,20 +1619,20 @@ class QueryQuery extends QueryField {
1616
1619
  case "date": {
1617
1620
  fields.push({
1618
1621
  name,
1619
- type: fi.f.fieldDef.type,
1620
- timeframe: fi.f.fieldDef.timeframe,
1622
+ "type": fi.f.fieldDef.type,
1623
+ "timeframe": fi.f.fieldDef.timeframe,
1621
1624
  resultMetadata,
1622
- location,
1625
+ location
1623
1626
  });
1624
1627
  break;
1625
1628
  }
1626
1629
  case "number":
1627
1630
  fields.push({
1628
1631
  name,
1629
- numberType: fi.f.fieldDef.numberType,
1630
- type: "number",
1632
+ "numberType": fi.f.fieldDef.numberType,
1633
+ "type": "number",
1631
1634
  resultMetadata,
1632
- location,
1635
+ location
1633
1636
  });
1634
1637
  break;
1635
1638
  default:
@@ -1640,16 +1643,16 @@ class QueryQuery extends QueryField {
1640
1643
  }
1641
1644
  return {
1642
1645
  fields,
1643
- name: this.resultStage || "result",
1644
- dialect: this.parent.dialect.name,
1646
+ "name": this.resultStage || "result",
1647
+ "dialect": this.parent.dialect.name,
1645
1648
  primaryKey,
1646
- structRelationship: {
1647
- type: "basetable",
1648
- connectionName: this.parent.connectionName,
1649
+ "structRelationship": {
1650
+ "type": "basetable",
1651
+ "connectionName": this.parent.connectionName
1649
1652
  },
1650
- structSource: { type: "query_result" },
1651
- resultMetadata: this.getResultMetadata(this.rootResult),
1652
- type: "struct",
1653
+ "structSource": { "type": "query_result" },
1654
+ "resultMetadata": this.getResultMetadata(this.rootResult),
1655
+ "type": "struct"
1653
1656
  };
1654
1657
  }
1655
1658
  generateSQLJoinBlock(stageWriter, ji) {
@@ -1667,9 +1670,9 @@ class QueryQuery extends QueryField {
1667
1670
  }
1668
1671
  if (structRelationship.onExpression) {
1669
1672
  onCondition = new QueryFieldBoolean({
1670
- type: "boolean",
1671
- name: "ignoreme",
1672
- e: structRelationship.onExpression,
1673
+ "type": "boolean",
1674
+ "name": "ignoreme",
1675
+ "e": structRelationship.onExpression
1673
1676
  }, qs.parent).generateExpression(this.rootResult);
1674
1677
  }
1675
1678
  else {
@@ -1951,12 +1954,12 @@ class QueryQuery extends QueryField {
1951
1954
  let from = this.generateSQLJoins(stageWriter);
1952
1955
  const wheres = this.generateSQLWhereTurtled();
1953
1956
  const f = {
1954
- dimensionIndexes: [1],
1955
- fieldIndex: 2,
1956
- sql: ["group_set"],
1957
- lateralJoinSQLExpressions: [],
1958
- groupsAggregated: [],
1959
- outputPipelinedSQL: [],
1957
+ "dimensionIndexes": [1],
1958
+ "fieldIndex": 2,
1959
+ "sql": ["group_set"],
1960
+ "lateralJoinSQLExpressions": [],
1961
+ "groupsAggregated": [],
1962
+ "outputPipelinedSQL": []
1960
1963
  };
1961
1964
  this.generateStage0Fields(this.rootResult, f, stageWriter);
1962
1965
  if (this.firstSegment.type === "project") {
@@ -2003,8 +2006,8 @@ class QueryQuery extends QueryField {
2003
2006
  else if (fi.depth === depth) {
2004
2007
  const s = this.generateTurtleSQL(fi, stageWriter, sqlFieldName, output.outputPipelinedSQL);
2005
2008
  output.groupsAggregated.push({
2006
- fromGroup: fi.groupSet,
2007
- toGroup: resultSet.groupSet,
2009
+ "fromGroup": fi.groupSet,
2010
+ "toGroup": resultSet.groupSet
2008
2011
  });
2009
2012
  groupsToMap.push(fi.groupSet);
2010
2013
  output.sql.push(`${s} as ${sqlFieldName}`);
@@ -2026,12 +2029,12 @@ class QueryQuery extends QueryField {
2026
2029
  generateSQLDepthN(depth, stageWriter, stageName) {
2027
2030
  let s = "SELECT \n";
2028
2031
  const f = {
2029
- dimensionIndexes: [1],
2030
- fieldIndex: 2,
2031
- sql: ["group_set"],
2032
- lateralJoinSQLExpressions: [],
2033
- groupsAggregated: [],
2034
- outputPipelinedSQL: [],
2032
+ "dimensionIndexes": [1],
2033
+ "fieldIndex": 2,
2034
+ "sql": ["group_set"],
2035
+ "lateralJoinSQLExpressions": [],
2036
+ "groupsAggregated": [],
2037
+ "outputPipelinedSQL": []
2035
2038
  };
2036
2039
  this.generateDepthNFields(depth, this.rootResult, f, stageWriter);
2037
2040
  s += (0, utils_1.indent)(f.sql.join(",\n")) + "\n";
@@ -2109,8 +2112,8 @@ class QueryQuery extends QueryField {
2109
2112
  for (const ordering of orderByDef) {
2110
2113
  if (typeof ordering.field === "string") {
2111
2114
  orderingField = {
2112
- name: ordering.field,
2113
- fif: resultStruct.getField(ordering.field),
2115
+ "name": ordering.field,
2116
+ "fif": resultStruct.getField(ordering.field)
2114
2117
  };
2115
2118
  }
2116
2119
  else {
@@ -2138,11 +2141,11 @@ class QueryQuery extends QueryField {
2138
2141
  // fieldsSQL.push(`${name}__${resultStruct.groupSet} as ${sqlName}`);
2139
2142
  // outputFieldNames.push(name);
2140
2143
  dialectFieldList.push({
2141
- type: field instanceof FieldInstanceField
2144
+ "type": field instanceof FieldInstanceField
2142
2145
  ? field.f.fieldDef.type
2143
2146
  : "struct",
2144
- sqlExpression: this.parent.dialect.sqlMaybeQuoteIdentifier(`${name}__${resultStruct.groupSet}`),
2145
- sqlOutputName: sqlName,
2147
+ "sqlExpression": this.parent.dialect.sqlMaybeQuoteIdentifier(`${name}__${resultStruct.groupSet}`),
2148
+ "sqlOutputName": sqlName
2146
2149
  });
2147
2150
  }
2148
2151
  else if (resultStruct.firstSegment.type === "project" &&
@@ -2152,9 +2155,9 @@ class QueryQuery extends QueryField {
2152
2155
  // `${field.f.generateExpression(resultStruct)} as ${sqlName}`
2153
2156
  // );
2154
2157
  dialectFieldList.push({
2155
- type: field.type,
2156
- sqlExpression: field.f.generateExpression(resultStruct),
2157
- sqlOutputName: sqlName,
2158
+ "type": field.type,
2159
+ "sqlExpression": field.f.generateExpression(resultStruct),
2160
+ "sqlOutputName": sqlName
2158
2161
  });
2159
2162
  }
2160
2163
  }
@@ -2183,7 +2186,7 @@ class QueryQuery extends QueryField {
2183
2186
  else {
2184
2187
  outputPipelinedSQL.push({
2185
2188
  sqlFieldName,
2186
- pipelineSQL: `(${sql})`,
2189
+ "pipelineSQL": `(${sql})`
2187
2190
  });
2188
2191
  }
2189
2192
  }
@@ -2201,14 +2204,14 @@ class QueryQuery extends QueryField {
2201
2204
  const pipeline = [...fi.turtleDef.pipeline];
2202
2205
  pipeline.shift();
2203
2206
  const newTurtle = {
2204
- type: "turtle",
2205
- name: "starthere",
2206
- pipeline,
2207
+ "type": "turtle",
2208
+ "name": "starthere",
2209
+ pipeline
2207
2210
  };
2208
2211
  structDef.name = this.parent.dialect.sqlUnnestPipelineHead(repeatedResultType === "inline_all_numbers", sourceSQLExpression);
2209
- structDef.structSource = { type: "sql", method: "nested" };
2212
+ structDef.structSource = { "type": "sql", "method": "nested" };
2210
2213
  const qs = new QueryStruct(structDef, {
2211
- model: this.parent.getModel(),
2214
+ "model": this.parent.getModel()
2212
2215
  });
2213
2216
  const q = QueryQuery.makeQuery(newTurtle, qs, stageWriter);
2214
2217
  pipeOut = q.generateSQLFromPipeline(stageWriter);
@@ -2217,7 +2220,7 @@ class QueryQuery extends QueryField {
2217
2220
  }
2218
2221
  return {
2219
2222
  structDef,
2220
- pipeOut,
2223
+ pipeOut
2221
2224
  };
2222
2225
  }
2223
2226
  generateComplexSQL(stageWriter) {
@@ -2260,20 +2263,20 @@ class QueryQuery extends QueryField {
2260
2263
  const pipeline = [...this.fieldDef.pipeline];
2261
2264
  let structDef = {
2262
2265
  ...outputStruct,
2263
- structSource: { type: "sql", method: "lastStage" },
2266
+ "structSource": { "type": "sql", "method": "lastStage" }
2264
2267
  };
2265
2268
  pipeline.shift();
2266
2269
  for (const transform of pipeline) {
2267
2270
  const s = new QueryStruct(structDef, {
2268
- model: this.parent.getModel(),
2271
+ "model": this.parent.getModel()
2269
2272
  });
2270
- const q = QueryQuery.makeQuery({ type: "turtle", name: "ignoreme", pipeline: [transform] }, s, stageWriter);
2273
+ const q = QueryQuery.makeQuery({ "type": "turtle", "name": "ignoreme", "pipeline": [transform] }, s, stageWriter);
2271
2274
  q.prepare(stageWriter);
2272
2275
  lastStageName = q.generateSQL(stageWriter);
2273
2276
  outputStruct = q.getResultStructDef();
2274
2277
  structDef = {
2275
2278
  ...outputStruct,
2276
- structSource: { type: "sql", method: "lastStage" },
2279
+ "structSource": { "type": "sql", "method": "lastStage" }
2277
2280
  };
2278
2281
  }
2279
2282
  }
@@ -2295,7 +2298,7 @@ class QueryQueryIndexStage extends QueryQuery {
2295
2298
  // get a field ref and expand it.
2296
2299
  expandField(f) {
2297
2300
  const field = this.parent.getFieldByName(f);
2298
- return { as: f, field };
2301
+ return { "as": f, field };
2299
2302
  }
2300
2303
  expandFields(resultStruct) {
2301
2304
  let resultIndex = 1;
@@ -2306,7 +2309,7 @@ class QueryQueryIndexStage extends QueryQuery {
2306
2309
  const { as, field } = this.expandField(f);
2307
2310
  resultStruct.addField(as, field, {
2308
2311
  resultIndex,
2309
- type: "result",
2312
+ "type": "result"
2310
2313
  });
2311
2314
  if (field instanceof QueryAtomicField) {
2312
2315
  this.addDependancies(resultStruct, field);
@@ -2318,7 +2321,7 @@ class QueryQueryIndexStage extends QueryQuery {
2318
2321
  const f = this.parent.getFieldByName(measure);
2319
2322
  resultStruct.addField(measure, f, {
2320
2323
  resultIndex,
2321
- type: "result",
2324
+ "type": "result"
2322
2325
  });
2323
2326
  this.addDependancies(resultStruct, f);
2324
2327
  }
@@ -2342,7 +2345,7 @@ class QueryQueryIndexStage extends QueryQuery {
2342
2345
  const fi = field;
2343
2346
  if (fi.fieldUsage.type === "result" && isScalarField(fi.f)) {
2344
2347
  const expression = fi.f.generateExpression(this.rootResult);
2345
- fields.push({ name, type: fi.f.fieldDef.type, expression });
2348
+ fields.push({ name, "type": fi.f.fieldDef.type, expression });
2346
2349
  }
2347
2350
  }
2348
2351
  let s = `SELECT\n group_set,\n`;
@@ -2484,12 +2487,12 @@ class QueryQueryIndex extends QueryQuery {
2484
2487
  for (const fields of stages) {
2485
2488
  const q = new QueryQueryIndexStage({
2486
2489
  ...this.fieldDef,
2487
- pipeline: [
2490
+ "pipeline": [
2488
2491
  {
2489
2492
  ...this.fieldDef.pipeline[0],
2490
- fields: fields,
2491
- },
2492
- ],
2493
+ "fields": fields
2494
+ }
2495
+ ]
2493
2496
  }, this.parent, stageWriter);
2494
2497
  q.prepare(stageWriter);
2495
2498
  const lastStageName = q.generateSQL(stageWriter);
@@ -2508,20 +2511,20 @@ class QueryQueryIndex extends QueryQuery {
2508
2511
  /** All Indexes have the same output schema */
2509
2512
  getResultStructDef() {
2510
2513
  return {
2511
- type: "struct",
2512
- name: this.resultStage || "result",
2513
- dialect: this.parent.fieldDef.dialect,
2514
- fields: [
2515
- { type: "string", name: "fieldName" },
2516
- { type: "string", name: "fieldValue" },
2517
- { type: "string", name: "fieldType" },
2518
- { type: "number", name: "weight", numberType: "integer" },
2514
+ "type": "struct",
2515
+ "name": this.resultStage || "result",
2516
+ "dialect": this.parent.fieldDef.dialect,
2517
+ "fields": [
2518
+ { "type": "string", "name": "fieldName" },
2519
+ { "type": "string", "name": "fieldValue" },
2520
+ { "type": "string", "name": "fieldType" },
2521
+ { "type": "number", "name": "weight", "numberType": "integer" }
2519
2522
  ],
2520
- structRelationship: {
2521
- type: "basetable",
2522
- connectionName: this.parent.connectionName,
2523
+ "structRelationship": {
2524
+ "type": "basetable",
2525
+ "connectionName": this.parent.connectionName
2523
2526
  },
2524
- structSource: { type: "query_result" },
2527
+ "structSource": { "type": "query_result" }
2525
2528
  };
2526
2529
  }
2527
2530
  }
@@ -2560,7 +2563,7 @@ class QueryStruct extends QueryNode {
2560
2563
  switch (field.type) {
2561
2564
  case "struct": {
2562
2565
  this.addFieldToNameMap(as, new QueryStruct(field, {
2563
- struct: this,
2566
+ "struct": this
2564
2567
  }));
2565
2568
  break;
2566
2569
  }
@@ -2577,7 +2580,7 @@ class QueryStruct extends QueryNode {
2577
2580
  }
2578
2581
  // if we don't have distinct key yet for this struct, add it.
2579
2582
  if (!this.nameMap.has("__distinct_key")) {
2580
- this.addFieldToNameMap("__distinct_key", new QueryFieldDistinctKey({ type: "string", name: "__distinct_key" }, this));
2583
+ this.addFieldToNameMap("__distinct_key", new QueryFieldDistinctKey({ "type": "string", "name": "__distinct_key" }, this));
2581
2584
  }
2582
2585
  }
2583
2586
  // generate unique string for the alias.
@@ -2624,15 +2627,15 @@ class QueryStruct extends QueryNode {
2624
2627
  const aliasName = (0, malloy_types_1.getIdentifier)(this.fieldDef);
2625
2628
  const pkName = this.fieldDef.primaryKey;
2626
2629
  const fieldDef = {
2627
- type: pkType,
2628
- name: `${aliasName}_id`,
2629
- e: [
2630
+ "type": pkType,
2631
+ "name": `${aliasName}_id`,
2632
+ "e": [
2630
2633
  {
2631
- type: "field",
2634
+ "type": "field",
2632
2635
  // path: pkField.getFullOutputName(),
2633
- path: pkField.getIdentifier(),
2634
- },
2635
- ],
2636
+ "path": pkField.getIdentifier()
2637
+ }
2638
+ ]
2636
2639
  };
2637
2640
  return new QueryFieldStruct(fieldDef, this, `${aliasName}.${pkName}`);
2638
2641
  }
@@ -2957,10 +2960,10 @@ class QueryStruct extends QueryNode {
2957
2960
  pipeline = (0, lodash_1.cloneDeep)(pipeline);
2958
2961
  pipeline[0].filterList = addedFilters.concat(pipeline[0].filterList || [], this.fieldDef.filterList || []);
2959
2962
  const flatTurtleDef = {
2960
- type: "turtle",
2961
- name: turtleDef.name,
2963
+ "type": "turtle",
2964
+ "name": turtleDef.name,
2962
2965
  pipeline,
2963
- location: turtleDef.location,
2966
+ "location": turtleDef.location
2964
2967
  };
2965
2968
  return flatTurtleDef;
2966
2969
  }
@@ -2983,7 +2986,7 @@ class QueryModel {
2983
2986
  for (const s of Object.values(this.modelDef.contents)) {
2984
2987
  let qs;
2985
2988
  if (s.type === "struct") {
2986
- qs = new QueryStruct(s, { model: this });
2989
+ qs = new QueryStruct(s, { "model": this });
2987
2990
  this.structs.set((0, malloy_types_1.getIdentifier)(s), qs);
2988
2991
  qs.resolveQueryFields();
2989
2992
  }
@@ -3005,7 +3008,7 @@ class QueryModel {
3005
3008
  else {
3006
3009
  throw new Error(`No query specified in Struct '${path[0]}'`);
3007
3010
  }
3008
- return { queryName: path.join("."), struct };
3011
+ return { "queryName": path.join("."), struct };
3009
3012
  }
3010
3013
  else {
3011
3014
  throw new Error(`Cannot find Struct '${path[0]}' Model`);
@@ -3031,7 +3034,7 @@ class QueryModel {
3031
3034
  else {
3032
3035
  throw new Error("Broken for now");
3033
3036
  }
3034
- return new QueryStruct(structDef, { model: this });
3037
+ return new QueryStruct(structDef, { "model": this });
3035
3038
  }
3036
3039
  loadQuery(query, stageWriter, emitFinalStage = false) {
3037
3040
  const malloy = "";
@@ -3039,11 +3042,11 @@ class QueryModel {
3039
3042
  stageWriter = new StageWriter(true, undefined);
3040
3043
  }
3041
3044
  const turtleDef = {
3042
- type: "turtle",
3043
- name: "ignoreme",
3044
- pipeHead: query.pipeHead,
3045
- pipeline: query.pipeline,
3046
- filterList: query.filterList,
3045
+ "type": "turtle",
3046
+ "name": "ignoreme",
3047
+ "pipeHead": query.pipeHead,
3048
+ "pipeline": query.pipeline,
3049
+ "filterList": query.filterList
3047
3050
  };
3048
3051
  const q = QueryQuery.makeQuery(turtleDef, this.getStructFromRef(query.structRef), stageWriter);
3049
3052
  const ret = q.generateSQLFromPipeline(stageWriter);
@@ -3056,11 +3059,11 @@ class QueryModel {
3056
3059
  ret.lastStageName = stageWriter.addStage(q.parent.dialect.sqlFinalStage(ret.lastStageName, fieldNames));
3057
3060
  }
3058
3061
  return {
3059
- lastStageName: ret.lastStageName,
3062
+ "lastStageName": ret.lastStageName,
3060
3063
  malloy,
3061
3064
  stageWriter,
3062
- structs: [ret.outputStruct],
3063
- connectionName: q.parent.connectionName,
3065
+ "structs": [ret.outputStruct],
3066
+ "connectionName": q.parent.connectionName
3064
3067
  };
3065
3068
  }
3066
3069
  compileQuery(query, finalize = true) {
@@ -3081,16 +3084,16 @@ class QueryModel {
3081
3084
  this.dialect.sqlFinalStage(ret.lastStageName, []));
3082
3085
  }
3083
3086
  return {
3084
- lastStageName: ret.lastStageName,
3085
- malloy: ret.malloy,
3086
- sql: ret.stageWriter.generateSQLStages(),
3087
- structs: ret.structs,
3087
+ "lastStageName": ret.lastStageName,
3088
+ "malloy": ret.malloy,
3089
+ "sql": ret.stageWriter.generateSQLStages(),
3090
+ "structs": ret.structs,
3088
3091
  sourceExplore,
3089
- sourceFilters: query.filterList,
3090
- queryName: query.pipeHead && query.pipeline.length === 0
3092
+ "sourceFilters": query.filterList,
3093
+ "queryName": query.pipeHead && query.pipeline.length === 0
3091
3094
  ? query.pipeHead.name
3092
3095
  : undefined,
3093
- connectionName: ret.connectionName,
3096
+ "connectionName": ret.connectionName
3094
3097
  };
3095
3098
  }
3096
3099
  async searchIndex(connection, explore, searchValue, limit = 1000, searchField = undefined) {
@@ -3102,21 +3105,21 @@ class QueryModel {
3102
3105
  let indexQuery;
3103
3106
  if (!struct.nameMap.get("search_index")) {
3104
3107
  indexQuery = {
3105
- structRef: explore,
3106
- pipeline: [
3108
+ "structRef": explore,
3109
+ "pipeline": [
3107
3110
  {
3108
- type: "index",
3109
- fields: ["*"],
3110
- sample: struct.dialect.defaultSampling,
3111
- },
3112
- ],
3111
+ "type": "index",
3112
+ "fields": ["*"],
3113
+ "sample": struct.dialect.defaultSampling
3114
+ }
3115
+ ]
3113
3116
  };
3114
3117
  }
3115
3118
  else {
3116
3119
  indexQuery = {
3117
- structRef: explore,
3118
- pipeHead: { name: "search_index" },
3119
- pipeline: [],
3120
+ "structRef": explore,
3121
+ "pipeHead": { "name": "search_index" },
3122
+ "pipeline": []
3120
3123
  };
3121
3124
  }
3122
3125
  const fieldNameColumn = struct.dialect.sqlMaybeQuoteIdentifier("fieldName");
@@ -3147,11 +3150,11 @@ class QueryModel {
3147
3150
  fieldValueColumn,
3148
3151
  fieldTypeColumn,
3149
3152
  "weight",
3150
- "match_first",
3153
+ "match_first"
3151
3154
  ])}`;
3152
3155
  }
3153
3156
  const result = await connection.runSQL(query, {
3154
- rowLimit: 1000,
3157
+ "rowLimit": 1000
3155
3158
  });
3156
3159
  return result.rows;
3157
3160
  }
@@ -3166,7 +3169,7 @@ function flattenQuery(model, query) {
3166
3169
  const queryStruct = queryModel.getStructByName(structRef);
3167
3170
  const turtleDef = queryStruct.flattenTurtleDef({
3168
3171
  ...query,
3169
- type: "turtle",
3172
+ "type": "turtle"
3170
3173
  });
3171
3174
  return turtleDef;
3172
3175
  }