@malloydata/malloy 0.0.195-dev241003204819 → 0.0.195-dev241007154000

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 (146) hide show
  1. package/dist/connection/base_connection.d.ts +21 -7
  2. package/dist/connection/base_connection.js +62 -0
  3. package/dist/connection/types.d.ts +5 -5
  4. package/dist/dialect/dialect.d.ts +5 -3
  5. package/dist/dialect/dialect.js +15 -0
  6. package/dist/dialect/duckdb/duckdb.d.ts +3 -3
  7. package/dist/dialect/duckdb/duckdb.js +8 -3
  8. package/dist/dialect/postgres/postgres.d.ts +3 -3
  9. package/dist/dialect/postgres/postgres.js +5 -2
  10. package/dist/dialect/snowflake/snowflake.d.ts +3 -3
  11. package/dist/dialect/snowflake/snowflake.js +4 -1
  12. package/dist/dialect/standardsql/standardsql.d.ts +3 -3
  13. package/dist/dialect/standardsql/standardsql.js +5 -2
  14. package/dist/dialect/trino/trino.d.ts +3 -3
  15. package/dist/dialect/trino/trino.js +35 -3
  16. package/dist/index.d.ts +4 -4
  17. package/dist/index.js +6 -2
  18. package/dist/lang/ast/error-factory.d.ts +4 -3
  19. package/dist/lang/ast/error-factory.js +27 -17
  20. package/dist/lang/ast/expressions/constant-expression.d.ts +1 -0
  21. package/dist/lang/ast/expressions/constant-expression.js +3 -0
  22. package/dist/lang/ast/expressions/expr-aggregate-function.d.ts +3 -7
  23. package/dist/lang/ast/expressions/expr-aggregate-function.js +50 -54
  24. package/dist/lang/ast/expressions/expr-cast.js +2 -4
  25. package/dist/lang/ast/expressions/expr-func.js +1 -1
  26. package/dist/lang/ast/expressions/expr-granular-time.js +1 -1
  27. package/dist/lang/ast/expressions/expr-record-literal.d.ts +16 -0
  28. package/dist/lang/ast/expressions/expr-record-literal.js +57 -0
  29. package/dist/lang/ast/expressions/expr-time-extract.js +3 -3
  30. package/dist/lang/ast/expressions/expr-time.d.ts +3 -3
  31. package/dist/lang/ast/expressions/expr-time.js +1 -1
  32. package/dist/lang/ast/expressions/time-literal.d.ts +6 -6
  33. package/dist/lang/ast/expressions/time-literal.js +1 -1
  34. package/dist/lang/ast/field-space/column-space-field.d.ts +6 -5
  35. package/dist/lang/ast/field-space/column-space-field.js +7 -4
  36. package/dist/lang/ast/field-space/dynamic-space.d.ts +8 -6
  37. package/dist/lang/ast/field-space/dynamic-space.js +35 -11
  38. package/dist/lang/ast/field-space/index-field-space.js +6 -3
  39. package/dist/lang/ast/field-space/ir-view-field.d.ts +1 -0
  40. package/dist/lang/ast/field-space/ir-view-field.js +3 -1
  41. package/dist/lang/ast/field-space/join-space-field.d.ts +2 -2
  42. package/dist/lang/ast/field-space/join-space-field.js +2 -2
  43. package/dist/lang/ast/field-space/parameter-space.d.ts +1 -0
  44. package/dist/lang/ast/field-space/parameter-space.js +4 -1
  45. package/dist/lang/ast/field-space/query-input-space.d.ts +4 -4
  46. package/dist/lang/ast/field-space/query-input-space.js +3 -5
  47. package/dist/lang/ast/field-space/query-spaces.d.ts +4 -4
  48. package/dist/lang/ast/field-space/query-spaces.js +1 -1
  49. package/dist/lang/ast/field-space/reference-field.js +10 -8
  50. package/dist/lang/ast/field-space/refined-space.d.ts +2 -2
  51. package/dist/lang/ast/field-space/static-space.d.ts +14 -5
  52. package/dist/lang/ast/field-space/static-space.js +45 -20
  53. package/dist/lang/ast/field-space/struct-space-field-base.d.ts +6 -5
  54. package/dist/lang/ast/field-space/struct-space-field-base.js +12 -4
  55. package/dist/lang/ast/index.d.ts +2 -1
  56. package/dist/lang/ast/index.js +2 -1
  57. package/dist/lang/ast/query-builders/index-builder.d.ts +2 -2
  58. package/dist/lang/ast/query-builders/project-builder.d.ts +2 -2
  59. package/dist/lang/ast/query-builders/reduce-builder.d.ts +2 -2
  60. package/dist/lang/ast/query-elements/query-arrow.js +2 -2
  61. package/dist/lang/ast/query-elements/query-head-struct.d.ts +2 -2
  62. package/dist/lang/ast/query-elements/query-head-struct.js +2 -2
  63. package/dist/lang/ast/query-elements/query-raw.js +2 -2
  64. package/dist/lang/ast/query-elements/query-reference.js +1 -1
  65. package/dist/lang/ast/query-items/field-declaration.d.ts +8 -6
  66. package/dist/lang/ast/query-items/field-declaration.js +66 -24
  67. package/dist/lang/ast/query-properties/qop-desc.d.ts +2 -2
  68. package/dist/lang/ast/query-properties/qop-desc.js +1 -1
  69. package/dist/lang/ast/source-elements/named-source.d.ts +4 -4
  70. package/dist/lang/ast/source-elements/named-source.js +16 -8
  71. package/dist/lang/ast/source-elements/query-source.d.ts +3 -3
  72. package/dist/lang/ast/source-elements/query-source.js +5 -2
  73. package/dist/lang/ast/source-elements/refined-source.d.ts +3 -3
  74. package/dist/lang/ast/source-elements/refined-source.js +4 -4
  75. package/dist/lang/ast/source-elements/source.d.ts +2 -2
  76. package/dist/lang/ast/source-elements/source.js +2 -2
  77. package/dist/lang/ast/source-elements/sql-source.d.ts +4 -4
  78. package/dist/lang/ast/source-elements/sql-source.js +6 -6
  79. package/dist/lang/ast/source-elements/table-source.d.ts +2 -2
  80. package/dist/lang/ast/source-elements/table-source.js +1 -1
  81. package/dist/lang/ast/source-properties/{joins.d.ts → join.d.ts} +11 -14
  82. package/dist/lang/ast/source-properties/{joins.js → join.js} +35 -52
  83. package/dist/lang/ast/source-query-elements/sq-reference.js +6 -5
  84. package/dist/lang/ast/sql-elements/sql-string.d.ts +2 -2
  85. package/dist/lang/ast/statements/define-source.js +1 -1
  86. package/dist/lang/ast/struct-utils.d.ts +3 -3
  87. package/dist/lang/ast/struct-utils.js +12 -3
  88. package/dist/lang/ast/time-utils.d.ts +3 -3
  89. package/dist/lang/ast/types/document-compile-result.d.ts +2 -2
  90. package/dist/lang/ast/types/expression-def.js +4 -4
  91. package/dist/lang/ast/types/field-space.d.ts +8 -3
  92. package/dist/lang/ast/types/lookup-result.d.ts +8 -5
  93. package/dist/lang/ast/types/malloy-element.d.ts +3 -3
  94. package/dist/lang/ast/types/malloy-element.js +10 -21
  95. package/dist/lang/ast/types/op-desc.d.ts +2 -2
  96. package/dist/lang/ast/types/pipeline-comp.d.ts +2 -2
  97. package/dist/lang/ast/types/query-comp.d.ts +3 -3
  98. package/dist/lang/ast/types/query-extend-property.d.ts +1 -2
  99. package/dist/lang/ast/types/query-extend-property.js +4 -2
  100. package/dist/lang/ast/types/source-property.d.ts +2 -2
  101. package/dist/lang/ast/types/source-property.js +2 -2
  102. package/dist/lang/ast/types/space-field.d.ts +10 -3
  103. package/dist/lang/ast/types/space-field.js +11 -2
  104. package/dist/lang/ast/types/time-result.d.ts +2 -2
  105. package/dist/lang/ast/view-elements/qop-desc-view.d.ts +3 -3
  106. package/dist/lang/ast/view-elements/qop-desc-view.js +1 -1
  107. package/dist/lang/ast/view-elements/reference-view.d.ts +4 -4
  108. package/dist/lang/ast/view-elements/reference-view.js +2 -6
  109. package/dist/lang/ast/view-elements/view-refine.d.ts +2 -2
  110. package/dist/lang/index.d.ts +1 -1
  111. package/dist/lang/lib/Malloy/MalloyParser.d.ts +54 -21
  112. package/dist/lang/lib/Malloy/MalloyParser.js +1647 -1457
  113. package/dist/lang/lib/Malloy/MalloyParserListener.d.ts +57 -9
  114. package/dist/lang/lib/Malloy/MalloyParserVisitor.d.ts +35 -5
  115. package/dist/lang/malloy-to-ast.d.ts +4 -4
  116. package/dist/lang/malloy-to-ast.js +32 -4
  117. package/dist/lang/parse-log.d.ts +5 -9
  118. package/dist/lang/parse-malloy.d.ts +10 -10
  119. package/dist/lang/parse-malloy.js +2 -1
  120. package/dist/lang/test/annotation.spec.js +7 -1
  121. package/dist/lang/test/field-symbols.spec.js +21 -25
  122. package/dist/lang/test/imports.spec.js +12 -10
  123. package/dist/lang/test/lenses.spec.js +2 -2
  124. package/dist/lang/test/model_serialization.spec.d.ts +4 -4
  125. package/dist/lang/test/model_serialization.spec.js +19 -31
  126. package/dist/lang/test/parse.spec.js +3 -4
  127. package/dist/lang/test/query.spec.js +3 -2
  128. package/dist/lang/test/source.spec.js +7 -0
  129. package/dist/lang/test/sql-block.spec.js +8 -19
  130. package/dist/lang/test/test-translator.d.ts +4 -4
  131. package/dist/lang/test/test-translator.js +53 -61
  132. package/dist/lang/translate-response.d.ts +3 -3
  133. package/dist/malloy.d.ts +31 -149
  134. package/dist/malloy.js +111 -269
  135. package/dist/model/malloy_query.d.ts +25 -23
  136. package/dist/model/malloy_query.js +262 -323
  137. package/dist/model/malloy_types.d.ts +145 -155
  138. package/dist/model/malloy_types.js +81 -84
  139. package/dist/model/sql_block.d.ts +4 -4
  140. package/dist/model/sql_block.js +9 -12
  141. package/dist/tags.js +2 -2
  142. package/dist/version.d.ts +1 -0
  143. package/dist/version.js +6 -0
  144. package/package.json +3 -2
  145. package/dist/lang/ast/space-seed.d.ts +0 -16
  146. package/dist/lang/ast/space-seed.js +0 -59
@@ -27,7 +27,6 @@ const malloy_types_1 = require("../../../model/malloy_types");
27
27
  const utils_1 = require("../../../model/utils");
28
28
  const ast_utils_1 = require("../ast-utils");
29
29
  const static_space_1 = require("../field-space/static-space");
30
- const struct_space_field_base_1 = require("../field-space/struct-space-field-base");
31
30
  const fragtype_utils_1 = require("../fragtype-utils");
32
31
  const field_references_1 = require("../query-items/field-references");
33
32
  const expression_def_1 = require("../types/expression-def");
@@ -60,34 +59,34 @@ class ExprAggregateFunction extends expression_def_1.ExpressionDef {
60
59
  if (this.source) {
61
60
  const result = this.source.getField(inputFS);
62
61
  if (result.found) {
63
- sourceRelationship = result.relationship;
62
+ sourceRelationship = result.joinPath;
64
63
  const sourceFoot = result.found;
65
64
  const footType = sourceFoot.typeDesc();
66
- if ((0, malloy_types_1.isAtomicFieldType)(footType.dataType)) {
67
- expr = this.source;
68
- exprVal = {
69
- dataType: footType.dataType,
70
- expressionType: footType.expressionType,
71
- value: footType.evalSpace === 'output'
72
- ? { node: 'outputField', name: this.source.refString }
73
- : { node: 'field', path: this.source.path },
74
- evalSpace: footType.evalSpace,
75
- };
76
- structPath = this.source.path;
77
- // Here we handle a special case where you write `foo.agg()` and `foo` is a
78
- // dimension which uses only one distinct join path; in this case, we set the
79
- // locality to be that join path
80
- const joinUsage = this.getJoinUsage(inputFS);
81
- const allUsagesSame = joinUsage.length === 1 ||
82
- (joinUsage.length > 1 &&
83
- joinUsage.slice(1).every(p => joinPathEq(p, joinUsage[0])));
84
- if (allUsagesSame) {
85
- structPath = joinUsage[0].map(p => p.name);
86
- sourceRelationship = joinUsage[0];
65
+ if (!(sourceFoot instanceof static_space_1.StructSpaceField)) {
66
+ if ((0, malloy_types_1.isAtomicFieldType)(footType.dataType)) {
67
+ expr = this.source;
68
+ exprVal = {
69
+ dataType: footType.dataType,
70
+ expressionType: footType.expressionType,
71
+ value: footType.evalSpace === 'output'
72
+ ? { node: 'outputField', name: this.source.refString }
73
+ : { node: 'field', path: this.source.path },
74
+ evalSpace: footType.evalSpace,
75
+ };
76
+ structPath = this.source.path;
77
+ // Here we handle a special case where you write `foo.agg()` and `foo` is a
78
+ // dimension which uses only one distinct join path; in this case, we set the
79
+ // locality to be that join path
80
+ const joinUsage = this.getJoinUsage(inputFS);
81
+ const allUsagesSame = joinUsage.length === 1 ||
82
+ (joinUsage.length > 1 &&
83
+ joinUsage.slice(1).every(p => joinPathEq(p, joinUsage[0])));
84
+ if (allUsagesSame) {
85
+ structPath = joinUsage[0].map(p => p.name);
86
+ sourceRelationship = joinUsage[0];
87
+ }
87
88
  }
88
- }
89
- else {
90
- if (!(sourceFoot instanceof struct_space_field_base_1.StructSpaceFieldBase)) {
89
+ else {
91
90
  return this.loggedErrorExpr('invalid-aggregate-source', `Aggregate source cannot be a ${footType.dataType}`);
92
91
  }
93
92
  }
@@ -185,7 +184,7 @@ function joinPathEq(a1, a2) {
185
184
  }
186
185
  function getJoinUsage(fs, expr) {
187
186
  const result = [];
188
- const lookup = (fs, path) => {
187
+ const lookupWithPath = (fs, path) => {
189
188
  const head = path[0];
190
189
  const rest = path.slice(1);
191
190
  const def = fs.entry(head);
@@ -193,13 +192,10 @@ function getJoinUsage(fs, expr) {
193
192
  throw new Error(`Invalid field lookup ${head}`);
194
193
  }
195
194
  if (def instanceof static_space_1.StructSpaceField && rest.length > 0) {
196
- const restDef = lookup(def.fieldSpace, rest);
195
+ const restDef = lookupWithPath(def.fieldSpace, rest);
197
196
  return {
198
197
  ...restDef,
199
- relationship: [
200
- { name: head, structRelationship: def.structRelationship },
201
- ...restDef.relationship,
202
- ],
198
+ joinPath: [{ ...def.joinPathElement, name: head }, ...restDef.joinPath],
203
199
  };
204
200
  }
205
201
  else if (def instanceof space_field_1.SpaceField) {
@@ -211,7 +207,7 @@ function getJoinUsage(fs, expr) {
211
207
  return {
212
208
  fs,
213
209
  def: fieldDef,
214
- relationship: [],
210
+ joinPath: [],
215
211
  };
216
212
  }
217
213
  throw new Error('No field def');
@@ -222,21 +218,22 @@ function getJoinUsage(fs, expr) {
222
218
  };
223
219
  for (const frag of (0, utils_1.exprWalk)(expr)) {
224
220
  if (frag.node === 'field') {
225
- const def = lookup(fs, frag.path);
226
- if (def.def.type !== 'struct' && def.def.type !== 'turtle') {
227
- if (def.def.e) {
228
- const defUsage = getJoinUsage(def.fs, def.def.e);
229
- result.push(...defUsage.map(r => [...def.relationship, ...r]));
221
+ const def = lookupWithPath(fs, frag.path);
222
+ const field = def.def;
223
+ if ((0, malloy_types_1.isAtomic)(field) && !(0, malloy_types_1.isJoined)(field)) {
224
+ if ((0, malloy_types_1.hasExpression)(field)) {
225
+ const defUsage = getJoinUsage(def.fs, field.e);
226
+ result.push(...defUsage.map(r => [...def.joinPath, ...r]));
230
227
  }
231
228
  else {
232
- result.push(def.relationship);
229
+ result.push(def.joinPath);
233
230
  }
234
231
  }
235
232
  }
236
233
  else if (frag.node === 'source-reference') {
237
234
  if (frag.path) {
238
- const def = lookup(fs, frag.path);
239
- result.push(def.relationship);
235
+ const def = lookupWithPath(fs, frag.path);
236
+ result.push(def.joinPath);
240
237
  }
241
238
  else {
242
239
  result.push([]);
@@ -245,19 +242,19 @@ function getJoinUsage(fs, expr) {
245
242
  }
246
243
  return result;
247
244
  }
248
- function getJoinUsagePaths(sourceRelationship, joinUsage) {
245
+ function getJoinUsagePaths(joinPath, joinUsage) {
249
246
  const sourceToUsagePaths = [];
250
247
  for (const usage of joinUsage) {
251
248
  let overlap = 0;
252
- for (let i = 0; i < sourceRelationship.length && i < usage.length; i++) {
253
- if (sourceRelationship[i].name === usage[i].name) {
249
+ for (let i = 0; i < joinPath.length && i < usage.length; i++) {
250
+ if (joinPath[i].name === usage[i].name) {
254
251
  overlap = i + 1;
255
252
  }
256
253
  else {
257
254
  break;
258
255
  }
259
256
  }
260
- const nonOverlapSource = sourceRelationship.slice(overlap);
257
+ const nonOverlapSource = joinPath.slice(overlap);
261
258
  const nonOverlapUsage = usage.slice(overlap);
262
259
  const sourceToUsagePath = [
263
260
  ...nonOverlapSource.map(r => ({ ...r, reverse: true })),
@@ -270,22 +267,22 @@ function getJoinUsagePaths(sourceRelationship, joinUsage) {
270
267
  function validateUsagePaths(functionName, usagePaths) {
271
268
  for (const path of usagePaths) {
272
269
  for (const step of path) {
273
- if (step.structRelationship.type === 'cross') {
270
+ if (step.joinType === 'cross') {
274
271
  return {
275
272
  code: 'aggregate-traverses-join-cross',
276
273
  message: `Cannot compute \`${functionName}\` across \`join_cross\` relationship \`${step.name}\``,
277
274
  };
278
275
  }
279
- else if (step.structRelationship.type === 'many' && !step.reverse) {
276
+ else if (step.joinElementType === 'array' && !step.reverse) {
280
277
  return {
281
- code: 'aggregate-traverses-join-many',
282
- message: `Cannot compute \`${functionName}\` across \`join_many\` relationship \`${step.name}\``,
278
+ code: 'aggregate-traverses-repeated-relationship',
279
+ message: `Cannot compute \`${functionName}\` across repeated relationship \`${step.name}\``,
283
280
  };
284
281
  }
285
- else if (step.structRelationship.type === 'nested' && !step.reverse) {
282
+ else if (step.joinType === 'many' && !step.reverse) {
286
283
  return {
287
- code: 'aggregate-traverses-repeated-relationship',
288
- message: `Cannot compute \`${functionName}\` across repeated relationship \`${step.name}\``,
284
+ code: 'aggregate-traverses-join-many',
285
+ message: `Cannot compute \`${functionName}\` across \`join_many\` relationship \`${step.name}\``,
289
286
  };
290
287
  }
291
288
  }
@@ -313,8 +310,7 @@ function suggestNewVersion(joinError, joinUsage, expr, func) {
313
310
  const indexFromEndOfLastMany = longestOverlap
314
311
  .slice()
315
312
  .reverse()
316
- .findIndex(x => x.structRelationship.type === 'many' ||
317
- x.structRelationship.type === 'cross');
313
+ .findIndex(x => x.joinType === 'many' || x.joinType === 'cross');
318
314
  const numJoinsToLastMany = indexFromEndOfLastMany === -1
319
315
  ? 0
320
316
  : longestOverlap.length - indexFromEndOfLastMany;
@@ -34,9 +34,8 @@ class ExprCast extends expression_def_1.ExpressionDef {
34
34
  this.elementType = 'cast';
35
35
  }
36
36
  getExpression(fs) {
37
- var _a, _b, _c;
38
37
  const expr = this.expr.getExpression(fs);
39
- let dataType = 'sql native';
38
+ let dataType = 'error';
40
39
  if (typeof this.castType === 'string') {
41
40
  dataType = this.castType;
42
41
  }
@@ -46,8 +45,7 @@ class ExprCast extends expression_def_1.ExpressionDef {
46
45
  if (dialect.validateTypeName(this.castType.raw)) {
47
46
  // TODO theoretically `sqlTypeToMalloyType` can get number subtypes,
48
47
  // but `TypeDesc` does not support them.
49
- dataType =
50
- (_c = (_b = (_a = fs.dialectObj()) === null || _a === void 0 ? void 0 : _a.sqlTypeToMalloyType(this.castType.raw)) === null || _b === void 0 ? void 0 : _b.type) !== null && _c !== void 0 ? _c : 'sql native';
48
+ dataType = dialect.sqlTypeToMalloyType(this.castType.raw).type;
51
49
  }
52
50
  else {
53
51
  this.logError('invalid-sql-native-type', `Cast type \`${this.castType.raw}\` is invalid for ${dialect.name} dialect`);
@@ -66,7 +66,7 @@ class ExprFunc extends expression_def_1.ExpressionDef {
66
66
  return { found: undefined, error: 'unknown function' };
67
67
  }
68
68
  else if (func.type !== 'function') {
69
- this.logError(`${func.type}-not-callable`, `Cannot call '${this.name}', which is of type ${func.type}`);
69
+ this.logError('call-of-non-function', `'${this.name}' (with type ${func.type}) is not a function`);
70
70
  return { found: undefined, error: 'called non function' };
71
71
  }
72
72
  if (func.name !== this.name) {
@@ -52,7 +52,7 @@ class ExprGranularTime extends expression_def_1.ExpressionDef {
52
52
  getExpression(fs) {
53
53
  const timeframe = this.units;
54
54
  const exprVal = this.expr.getExpression(fs);
55
- if ((0, malloy_types_1.isTimeFieldType)(exprVal.dataType)) {
55
+ if ((0, malloy_types_1.isTemporalField)(exprVal.dataType)) {
56
56
  const tsVal = {
57
57
  ...exprVal,
58
58
  dataType: exprVal.dataType,
@@ -0,0 +1,16 @@
1
+ import { ExprValue } from '../types/expr-value';
2
+ import { ExpressionDef } from '../types/expression-def';
3
+ import { FieldSpace } from '../types/field-space';
4
+ import { MalloyElement } from '../types/malloy-element';
5
+ export declare class RecordElement extends MalloyElement {
6
+ readonly key: string;
7
+ readonly value: ExpressionDef;
8
+ elementType: string;
9
+ constructor(key: string, value: ExpressionDef);
10
+ }
11
+ export declare class RecordLiteral extends ExpressionDef {
12
+ readonly pairs: RecordElement[];
13
+ elementType: string;
14
+ constructor(pairs: RecordElement[]);
15
+ getExpression(fs: FieldSpace): ExprValue;
16
+ }
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.RecordLiteral = exports.RecordElement = void 0;
10
+ const model_1 = require("../../../model");
11
+ const expression_def_1 = require("../types/expression-def");
12
+ const malloy_element_1 = require("../types/malloy-element");
13
+ class RecordElement extends malloy_element_1.MalloyElement {
14
+ constructor(key, value) {
15
+ super();
16
+ this.key = key;
17
+ this.value = value;
18
+ this.elementType = 'record element';
19
+ this.has({ value });
20
+ }
21
+ }
22
+ exports.RecordElement = RecordElement;
23
+ class RecordLiteral extends expression_def_1.ExpressionDef {
24
+ constructor(pairs) {
25
+ super();
26
+ this.pairs = pairs;
27
+ this.elementType = 'record literal';
28
+ this.has({ pairs });
29
+ }
30
+ getExpression(fs) {
31
+ const recLit = {
32
+ node: 'recordLiteral',
33
+ kids: {},
34
+ };
35
+ let resultExprType = 'scalar';
36
+ for (const el of this.pairs) {
37
+ const xVal = el.value.getExpression(fs);
38
+ const expr = { dataType: 'error', ...xVal.value };
39
+ if (expr.dataType === 'error' && (0, model_1.isAtomicFieldType)(xVal.dataType)) {
40
+ expr.dataType = xVal.dataType;
41
+ }
42
+ if (expr.dataType === 'error' && xVal.dataType !== 'error') {
43
+ this.logError('illegal-record-property-type', `Type '${xVal.dataType}' not a legal record value`);
44
+ }
45
+ recLit.kids[el.key] = expr;
46
+ resultExprType = (0, model_1.maxExpressionType)(xVal.expressionType, resultExprType);
47
+ }
48
+ return {
49
+ dataType: 'record',
50
+ value: recLit,
51
+ expressionType: resultExprType,
52
+ evalSpace: 'literal',
53
+ };
54
+ }
55
+ }
56
+ exports.RecordLiteral = RecordLiteral;
57
+ //# sourceMappingURL=expr-record-literal.js.map
@@ -63,10 +63,10 @@ class ExprTimeExtract extends expression_def_1.ExpressionDef {
63
63
  value: (0, ast_utils_1.errorFor)('extract from error').value,
64
64
  };
65
65
  }
66
- if (!(0, malloy_types_1.isTimeFieldType)(first.dataType)) {
66
+ if (!(0, malloy_types_1.isTemporalField)(first.dataType)) {
67
67
  return from.first.loggedErrorExpr('invalid-type-for-time-extraction', `Can't extract ${extractTo} from '${first.dataType}'`);
68
68
  }
69
- if (!(0, malloy_types_1.isTimeFieldType)(last.dataType)) {
69
+ if (!(0, malloy_types_1.isTemporalField)(last.dataType)) {
70
70
  return from.last.loggedErrorExpr('invalid-type-for-time-extraction', `Cannot extract ${extractTo} from '${last.dataType}'`);
71
71
  }
72
72
  let valueType = first.dataType;
@@ -113,7 +113,7 @@ class ExprTimeExtract extends expression_def_1.ExpressionDef {
113
113
  }
114
114
  else {
115
115
  const argV = from.getExpression(fs);
116
- if ((0, malloy_types_1.isTimeFieldType)(argV.dataType)) {
116
+ if ((0, malloy_types_1.isTemporalField)(argV.dataType)) {
117
117
  return {
118
118
  dataType: 'number',
119
119
  expressionType: argV.expressionType,
@@ -1,11 +1,11 @@
1
- import { Expr, ExpressionType, TimeFieldType } from '../../../model/malloy_types';
1
+ import { Expr, ExpressionType, TemporalFieldType } from '../../../model/malloy_types';
2
2
  import { FieldSpace } from '../types/field-space';
3
3
  import { ExprValue } from '../types/expr-value';
4
4
  import { ExpressionDef } from '../types/expression-def';
5
5
  export declare class ExprTime extends ExpressionDef {
6
6
  elementType: string;
7
7
  readonly translationValue: ExprValue;
8
- constructor(timeType: TimeFieldType, value: Expr, expressionType?: ExpressionType);
8
+ constructor(timeType: TemporalFieldType, value: Expr, expressionType?: ExpressionType);
9
9
  getExpression(_fs: FieldSpace): ExprValue;
10
- static fromValue(timeType: TimeFieldType, expr: ExprValue): ExprTime;
10
+ static fromValue(timeType: TemporalFieldType, expr: ExprValue): ExprTime;
11
11
  }
@@ -49,7 +49,7 @@ class ExprTime extends expression_def_1.ExpressionDef {
49
49
  dstType: timeType,
50
50
  e: expr.value,
51
51
  };
52
- if ((0, malloy_types_1.isTimeFieldType)(expr.dataType)) {
52
+ if ((0, malloy_types_1.isTemporalField)(expr.dataType)) {
53
53
  toTs.srcType = expr.dataType;
54
54
  }
55
55
  value = toTs;
@@ -1,4 +1,4 @@
1
- import { TimeFieldType, TimestampUnit, TimeLiteralNode } from '../../../model/malloy_types';
1
+ import { TemporalFieldType, TimestampUnit, TimeLiteralNode } from '../../../model/malloy_types';
2
2
  import { ExprValue } from '../types/expr-value';
3
3
  import { FieldSpace } from '../types/field-space';
4
4
  import { ExpressionDef } from '../types/expression-def';
@@ -15,13 +15,13 @@ interface TimeText {
15
15
  */
16
16
  declare abstract class TimeLiteral extends ExpressionDef {
17
17
  readonly units: TimestampUnit | undefined;
18
- readonly timeType: TimeFieldType;
18
+ readonly timeType: TemporalFieldType;
19
19
  literalPart: string;
20
20
  nextLit?: string;
21
21
  timeZone?: string;
22
- constructor(tm: TimeText, units: TimestampUnit | undefined, timeType: TimeFieldType);
23
- protected makeLiteral(val: string, typ: TimeFieldType): TimeLiteralNode;
24
- protected makeValue(val: string, dataType: TimeFieldType): TimeResult;
22
+ constructor(tm: TimeText, units: TimestampUnit | undefined, timeType: TemporalFieldType);
23
+ protected makeLiteral(val: string, typ: TemporalFieldType): TimeLiteralNode;
24
+ protected makeValue(val: string, dataType: TemporalFieldType): TimeResult;
25
25
  getExpression(_fs: FieldSpace): ExprValue;
26
26
  getNext(): ExprValue | undefined;
27
27
  granular(): boolean;
@@ -38,7 +38,7 @@ export declare class LiteralTimestamp extends TimeLiteral {
38
38
  declare class GranularLiteral extends TimeLiteral {
39
39
  readonly nextLit: string;
40
40
  elementType: string;
41
- constructor(tm: TimeText, units: TimestampUnit | undefined, timeType: TimeFieldType, nextLit: string);
41
+ constructor(tm: TimeText, units: TimestampUnit | undefined, timeType: TemporalFieldType, nextLit: string);
42
42
  apply(fs: FieldSpace, op: BinaryMalloyOperator, left: ExpressionDef): ExprValue;
43
43
  }
44
44
  export declare class LiteralHour extends GranularLiteral {
@@ -171,7 +171,7 @@ class GranularLiteral extends TimeLiteral {
171
171
  return super.apply(fs, op, left);
172
172
  }
173
173
  }
174
- if ((0, malloy_types_1.isTimeFieldType)(testValue.dataType)) {
174
+ if ((0, malloy_types_1.isTemporalField)(testValue.dataType)) {
175
175
  const rangeType = testValue.dataType;
176
176
  const range = new range_1.Range(new expr_time_1.ExprTime(rangeType, rangeStart.value), new expr_time_1.ExprTime(rangeType, rangeEnd.value));
177
177
  return range.apply(fs, op, left);
@@ -1,8 +1,9 @@
1
- import { FieldDef, FieldTypeDef, TypeDesc } from '../../../model/malloy_types';
1
+ import { TypeDesc, AtomicFieldDef } from '../../../model/malloy_types';
2
2
  import { SpaceField } from '../types/space-field';
3
- export declare class ColumnSpaceField extends SpaceField {
4
- haveFieldDef: FieldDef;
5
- constructor(def: FieldTypeDef);
6
- fieldDef(): FieldDef;
3
+ export declare class ColumnSpaceField<T extends AtomicFieldDef> extends SpaceField {
4
+ sourceFieldDef: T;
5
+ constructor(sourceFieldDef: T);
6
+ fieldDef(): T;
7
7
  typeDesc(): TypeDesc;
8
+ constructorFieldDef(): T;
8
9
  }
@@ -25,15 +25,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
25
25
  exports.ColumnSpaceField = void 0;
26
26
  const space_field_1 = require("../types/space-field");
27
27
  class ColumnSpaceField extends space_field_1.SpaceField {
28
- constructor(def) {
28
+ constructor(sourceFieldDef) {
29
29
  super();
30
- this.haveFieldDef = def;
30
+ this.sourceFieldDef = sourceFieldDef;
31
31
  }
32
32
  fieldDef() {
33
- return this.haveFieldDef;
33
+ return this.sourceFieldDef;
34
34
  }
35
35
  typeDesc() {
36
- return this.fieldTypeFromFieldDef(this.haveFieldDef);
36
+ return this.fieldTypeFromFieldDef(this.sourceFieldDef);
37
+ }
38
+ constructorFieldDef() {
39
+ return this.sourceFieldDef;
37
40
  }
38
41
  }
39
42
  exports.ColumnSpaceField = ColumnSpaceField;
@@ -2,17 +2,18 @@ import * as model from '../../../model/malloy_types';
2
2
  import { SpaceEntry } from '../types/space-entry';
3
3
  import { HasParameter } from '../parameters/has-parameter';
4
4
  import { MalloyElement } from '../types/malloy-element';
5
- import { SourceSpec, SpaceSeed } from '../space-seed';
6
5
  import { StaticSpace } from './static-space';
7
6
  import { ParameterSpace } from './parameter-space';
8
- export declare abstract class DynamicSpace extends StaticSpace {
9
- protected final: model.StructDef | undefined;
10
- protected source: SpaceSeed;
7
+ import { SourceDef } from '../../../model/malloy_types';
8
+ import { SourceFieldSpace } from '../types/field-space';
9
+ export declare abstract class DynamicSpace extends StaticSpace implements SourceFieldSpace {
10
+ protected final: model.SourceDef | undefined;
11
+ protected fromSource: model.SourceDef;
11
12
  completions: (() => void)[];
12
13
  private complete;
13
14
  private parameters;
14
15
  protected newTimezone?: string;
15
- constructor(extending: SourceSpec);
16
+ constructor(extending: SourceDef);
16
17
  isComplete(): void;
17
18
  protected setEntry(name: string, value: SpaceEntry): void;
18
19
  addParameters(parameters: HasParameter[]): DynamicSpace;
@@ -21,5 +22,6 @@ export declare abstract class DynamicSpace extends StaticSpace {
21
22
  renameEntry(oldName: string, newName: string, entry: SpaceEntry): void;
22
23
  addFieldDef(fd: model.FieldDef): void;
23
24
  setTimezone(tz: string): void;
24
- structDef(): model.StructDef;
25
+ structDef(): model.SourceDef;
26
+ emptyStructDef(): SourceDef;
25
27
  }
@@ -21,27 +21,49 @@
21
21
  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
22
  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
23
  */
24
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
25
+ if (k2 === undefined) k2 = k;
26
+ var desc = Object.getOwnPropertyDescriptor(m, k);
27
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
28
+ desc = { enumerable: true, get: function() { return m[k]; } };
29
+ }
30
+ Object.defineProperty(o, k2, desc);
31
+ }) : (function(o, m, k, k2) {
32
+ if (k2 === undefined) k2 = k;
33
+ o[k2] = m[k];
34
+ }));
35
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
36
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
37
+ }) : function(o, v) {
38
+ o["default"] = v;
39
+ });
40
+ var __importStar = (this && this.__importStar) || function (mod) {
41
+ if (mod && mod.__esModule) return mod;
42
+ var result = {};
43
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
44
+ __setModuleDefault(result, mod);
45
+ return result;
46
+ };
24
47
  Object.defineProperty(exports, "__esModule", { value: true });
25
48
  exports.DynamicSpace = void 0;
49
+ const model = __importStar(require("../../../model/malloy_types"));
26
50
  const field_utils_1 = require("../../field-utils");
27
51
  const error_factory_1 = require("../error-factory");
28
52
  const space_field_1 = require("../types/space-field");
29
53
  const join_space_field_1 = require("./join-space-field");
30
54
  const view_field_1 = require("./view-field");
31
55
  const space_param_1 = require("../types/space-param");
32
- const space_seed_1 = require("../space-seed");
33
56
  const static_space_1 = require("./static-space");
34
57
  const struct_space_field_base_1 = require("./struct-space-field-base");
35
58
  const parameter_space_1 = require("./parameter-space");
36
59
  class DynamicSpace extends static_space_1.StaticSpace {
37
60
  constructor(extending) {
38
- const source = new space_seed_1.SpaceSeed(extending);
39
- super(structuredClone(source.structDef));
61
+ super(structuredClone(extending));
40
62
  this.completions = [];
41
63
  this.complete = false;
42
64
  this.parameters = [];
65
+ this.fromSource = extending;
43
66
  this.final = undefined;
44
- this.source = source;
45
67
  }
46
68
  isComplete() {
47
69
  this.complete = true;
@@ -91,11 +113,8 @@ class DynamicSpace extends static_space_1.StaticSpace {
91
113
  parameters[name] = entry.parameter();
92
114
  }
93
115
  }
94
- this.final = {
95
- ...this.fromStruct,
96
- fields: [],
97
- parameters,
98
- };
116
+ this.final = { ...this.fromSource, fields: [] };
117
+ this.final.parameters = parameters;
99
118
  // Need to process the entities in specific order
100
119
  const fields = [];
101
120
  const joins = [];
@@ -117,7 +136,7 @@ class DynamicSpace extends static_space_1.StaticSpace {
117
136
  for (const [, field] of reorderFields) {
118
137
  if (field instanceof join_space_field_1.JoinSpaceField) {
119
138
  const joinStruct = field.join.structDef(parameterSpace);
120
- if (!error_factory_1.ErrorFactory.isErrorStructDef(joinStruct)) {
139
+ if (!error_factory_1.ErrorFactory.didCreate(joinStruct)) {
121
140
  this.final.fields.push(joinStruct);
122
141
  fixupJoins.push([field.join, joinStruct]);
123
142
  }
@@ -139,12 +158,17 @@ class DynamicSpace extends static_space_1.StaticSpace {
139
158
  join.fixupJoinOn(this, missingOn);
140
159
  }
141
160
  }
142
- if (this.newTimezone) {
161
+ if (this.newTimezone && model.isSourceDef(this.final)) {
143
162
  this.final.queryTimezone = this.newTimezone;
144
163
  }
145
164
  this.isComplete();
146
165
  return this.final;
147
166
  }
167
+ emptyStructDef() {
168
+ const ret = { ...this.fromSource };
169
+ ret.fields = [];
170
+ return ret;
171
+ }
148
172
  }
149
173
  exports.DynamicSpace = DynamicSpace;
150
174
  //# sourceMappingURL=dynamic-space.js.map
@@ -119,9 +119,12 @@ class IndexFieldSpace extends query_spaces_1.QueryOperationSpace {
119
119
  wild.logError('name-conflict-in-wildcard-expansion', `Cannot expand '${name}' in '${wild.refString}' because a field with that name already exists${conflict ? ` (conflicts with ${conflict})` : ''}`);
120
120
  }
121
121
  else {
122
- const eType = entry.typeDesc();
123
- if ((0, malloy_types_1.isAtomicFieldType)(eType.dataType) &&
124
- (0, malloy_types_1.expressionIsScalar)(eType.expressionType) &&
122
+ const eTypeDesc = entry.typeDesc();
123
+ const eType = eTypeDesc.dataType;
124
+ // Don't index arrays and records
125
+ const canIndex = (0, malloy_types_1.isAtomicFieldType)(eType) && eType !== 'record' && eType !== 'array';
126
+ if (canIndex &&
127
+ (0, malloy_types_1.expressionIsScalar)(eTypeDesc.expressionType) &&
125
128
  (dialect === undefined || !dialect.ignoreInProject(name))) {
126
129
  expandEntries.push({ name: indexName, entry });
127
130
  this.expandedWild[indexName] = joinPath.concat(name);
@@ -6,5 +6,6 @@ export declare class IRViewField extends ViewField {
6
6
  constructor(fs: FieldSpace, turtleDef: TurtleDef);
7
7
  rename(name: string): void;
8
8
  fieldDef(): TurtleDef;
9
+ constructorFieldDef(): TurtleDef;
9
10
  getQueryFieldDef(_fs: FieldSpace): QueryFieldDef | undefined;
10
11
  }
@@ -28,7 +28,6 @@ class IRViewField extends view_field_1.ViewField {
28
28
  constructor(fs, turtleDef) {
29
29
  super(fs);
30
30
  this.turtleDef = turtleDef;
31
- this.haveFieldDef = turtleDef;
32
31
  }
33
32
  rename(name) {
34
33
  this.turtleDef = {
@@ -39,6 +38,9 @@ class IRViewField extends view_field_1.ViewField {
39
38
  fieldDef() {
40
39
  return this.turtleDef;
41
40
  }
41
+ constructorFieldDef() {
42
+ return this.turtleDef;
43
+ }
42
44
  getQueryFieldDef(_fs) {
43
45
  return this.fieldDef();
44
46
  }
@@ -1,8 +1,8 @@
1
- import { Join } from '../source-properties/joins';
1
+ import { Join } from '../source-properties/join';
2
2
  import { ParameterSpace } from './parameter-space';
3
3
  import { StructSpaceField } from './static-space';
4
4
  export declare class JoinSpaceField extends StructSpaceField {
5
5
  readonly parameterSpace: ParameterSpace;
6
6
  readonly join: Join;
7
- constructor(parameterSpace: ParameterSpace, join: Join);
7
+ constructor(parameterSpace: ParameterSpace, join: Join, parentDialect: string);
8
8
  }
@@ -25,8 +25,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
25
25
  exports.JoinSpaceField = void 0;
26
26
  const static_space_1 = require("./static-space");
27
27
  class JoinSpaceField extends static_space_1.StructSpaceField {
28
- constructor(parameterSpace, join) {
29
- super(join.structDef(parameterSpace));
28
+ constructor(parameterSpace, join, parentDialect) {
29
+ super(join.structDef(parameterSpace), parentDialect);
30
30
  this.parameterSpace = parameterSpace;
31
31
  this.join = join;
32
32
  }