@malloydata/malloy 0.0.219 → 0.0.220-dev241204170603

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 (71) hide show
  1. package/dist/connection/base_connection.js +1 -1
  2. package/dist/dialect/dialect.d.ts +6 -3
  3. package/dist/dialect/dialect.js +4 -11
  4. package/dist/dialect/duckdb/dialect_functions.js +1 -1
  5. package/dist/dialect/duckdb/duckdb.d.ts +4 -4
  6. package/dist/dialect/duckdb/duckdb.js +10 -16
  7. package/dist/dialect/duckdb/function_overrides.js +1 -1
  8. package/dist/dialect/functions/malloy_standard_functions.js +1 -1
  9. package/dist/dialect/index.d.ts +3 -1
  10. package/dist/dialect/index.js +3 -1
  11. package/dist/dialect/mysql/dialect_functions.js +1 -1
  12. package/dist/dialect/mysql/function_overrides.js +1 -1
  13. package/dist/dialect/mysql/index.js +1 -1
  14. package/dist/dialect/mysql/mysql.d.ts +9 -6
  15. package/dist/dialect/mysql/mysql.js +36 -25
  16. package/dist/dialect/pg_impl.d.ts +4 -1
  17. package/dist/dialect/pg_impl.js +11 -1
  18. package/dist/dialect/postgres/dialect_functions.js +1 -1
  19. package/dist/dialect/postgres/function_overrides.js +1 -1
  20. package/dist/dialect/postgres/postgres.d.ts +6 -4
  21. package/dist/dialect/postgres/postgres.js +27 -12
  22. package/dist/dialect/snowflake/dialect_functions.js +1 -1
  23. package/dist/dialect/snowflake/function_overrides.js +1 -1
  24. package/dist/dialect/snowflake/snowflake.d.ts +5 -3
  25. package/dist/dialect/snowflake/snowflake.js +76 -20
  26. package/dist/dialect/standardsql/dialect_functions.js +1 -1
  27. package/dist/dialect/standardsql/function_overrides.js +1 -1
  28. package/dist/dialect/standardsql/standardsql.d.ts +5 -3
  29. package/dist/dialect/standardsql/standardsql.js +16 -101
  30. package/dist/dialect/tiny_parser.d.ts +41 -0
  31. package/dist/dialect/tiny_parser.js +126 -0
  32. package/dist/dialect/trino/dialect_functions.js +1 -1
  33. package/dist/dialect/trino/function_overrides.js +1 -1
  34. package/dist/dialect/trino/trino.d.ts +3 -3
  35. package/dist/dialect/trino/trino.js +40 -16
  36. package/dist/index.d.ts +3 -3
  37. package/dist/index.js +3 -2
  38. package/dist/lang/ast/expressions/case.js +1 -1
  39. package/dist/lang/ast/expressions/expr-array-literal.d.ts +9 -0
  40. package/dist/lang/ast/expressions/expr-array-literal.js +93 -0
  41. package/dist/lang/ast/expressions/expr-record-literal.d.ts +1 -1
  42. package/dist/lang/ast/expressions/expr-record-literal.js +56 -28
  43. package/dist/lang/ast/field-space/join-space-field.d.ts +1 -1
  44. package/dist/lang/ast/field-space/join-space-field.js +2 -2
  45. package/dist/lang/ast/field-space/project-field-space.js +1 -1
  46. package/dist/lang/ast/field-space/reference-field.js +1 -1
  47. package/dist/lang/ast/field-space/static-space.d.ts +1 -2
  48. package/dist/lang/ast/field-space/static-space.js +15 -5
  49. package/dist/lang/ast/field-space/view-field.d.ts +2 -2
  50. package/dist/lang/ast/index.d.ts +1 -0
  51. package/dist/lang/ast/index.js +1 -0
  52. package/dist/lang/ast/query-items/field-declaration.js +25 -11
  53. package/dist/lang/ast/query-properties/filters.js +0 -2
  54. package/dist/lang/ast/source-properties/join.js +1 -1
  55. package/dist/lang/ast/types/binary_operators.js +1 -1
  56. package/dist/lang/ast/types/dialect-name-space.js +1 -1
  57. package/dist/lang/lib/Malloy/MalloyParser.d.ts +1 -1
  58. package/dist/lang/lib/Malloy/MalloyParser.js +12 -16
  59. package/dist/lang/malloy-to-ast.d.ts +1 -1
  60. package/dist/lang/malloy-to-ast.js +3 -3
  61. package/dist/lang/parse-log.d.ts +1 -0
  62. package/dist/lang/test/query.spec.js +6 -0
  63. package/dist/lang/test/test-translator.js +11 -2
  64. package/dist/model/malloy_query.d.ts +29 -24
  65. package/dist/model/malloy_query.js +261 -146
  66. package/dist/model/malloy_types.d.ts +12 -15
  67. package/dist/model/malloy_types.js +2 -7
  68. package/dist/model/materialization/utils.js +1 -1
  69. package/dist/version.d.ts +1 -1
  70. package/dist/version.js +1 -1
  71. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.JoinRelationship = exports.MalloyError = exports.FixedConnectionMap = exports.InMemoryURLReader = exports.EmptyURLReader = exports.SingleConnectionRuntime = exports.ConnectionRuntime = exports.AtomicFieldType = exports.Runtime = exports.Malloy = exports.Model = exports.MalloyTranslator = exports.composeSQLExpr = exports.indent = exports.expressionIsUngroupedAggregate = exports.expressionIsScalar = exports.expressionIsCalculation = exports.expressionIsAnalytic = exports.expressionIsAggregate = exports.isSamplingRows = exports.isSamplingPercent = exports.isSamplingEnable = exports.isJoinedSource = exports.isJoined = exports.isLeafAtomic = exports.Segment = exports.isSourceDef = exports.isRepeatedRecord = exports.arrayEachFields = exports.Dialect = exports.spread = exports.literal = exports.variadicParam = exports.param = exports.makeParam = exports.sql = exports.maxScalar = exports.minAggregate = exports.anyExprType = exports.minScalar = exports.overload = exports.qtz = exports.arg = exports.registerDialect = exports.MySQLDialect = exports.SnowflakeDialect = exports.PostgresDialect = exports.TrinoDialect = exports.StandardSQLDialect = exports.DuckDBDialect = void 0;
4
- exports.Tag = exports.toAsyncGenerator = exports.Explore = exports.DataWriter = exports.Parse = exports.JSONWriter = exports.CSVWriter = exports.QueryMaterializer = exports.Result = exports.PreparedResult = exports.TimestampTimeframe = exports.DateTimeframe = exports.SourceRelationship = void 0;
3
+ exports.MalloyError = exports.FixedConnectionMap = exports.InMemoryURLReader = exports.EmptyURLReader = exports.SingleConnectionRuntime = exports.ConnectionRuntime = exports.AtomicFieldType = exports.Runtime = exports.Malloy = exports.Model = exports.MalloyTranslator = exports.composeSQLExpr = exports.indent = exports.expressionIsUngroupedAggregate = exports.expressionIsScalar = exports.expressionIsCalculation = exports.expressionIsAnalytic = exports.expressionIsAggregate = exports.isSamplingRows = exports.isSamplingPercent = exports.isSamplingEnable = exports.isJoinedSource = exports.isJoined = exports.isLeafAtomic = exports.Segment = exports.isSourceDef = exports.isRepeatedRecord = exports.arrayEachFields = exports.TinyParser = exports.Dialect = exports.spread = exports.literal = exports.variadicParam = exports.param = exports.makeParam = exports.sql = exports.maxScalar = exports.minAggregate = exports.anyExprType = exports.minScalar = exports.overload = exports.qtz = exports.arg = exports.registerDialect = exports.MySQLDialect = exports.SnowflakeDialect = exports.PostgresDialect = exports.TrinoDialect = exports.StandardSQLDialect = exports.DuckDBDialect = void 0;
4
+ exports.Tag = exports.toAsyncGenerator = exports.Explore = exports.DataWriter = exports.Parse = exports.JSONWriter = exports.CSVWriter = exports.QueryMaterializer = exports.Result = exports.PreparedResult = exports.TimestampTimeframe = exports.DateTimeframe = exports.SourceRelationship = exports.JoinRelationship = void 0;
5
5
  /*
6
6
  * Copyright 2023 Google LLC
7
7
  *
@@ -46,6 +46,7 @@ Object.defineProperty(exports, "variadicParam", { enumerable: true, get: functio
46
46
  Object.defineProperty(exports, "literal", { enumerable: true, get: function () { return dialect_1.literal; } });
47
47
  Object.defineProperty(exports, "spread", { enumerable: true, get: function () { return dialect_1.spread; } });
48
48
  Object.defineProperty(exports, "Dialect", { enumerable: true, get: function () { return dialect_1.Dialect; } });
49
+ Object.defineProperty(exports, "TinyParser", { enumerable: true, get: function () { return dialect_1.TinyParser; } });
49
50
  var model_1 = require("./model");
50
51
  Object.defineProperty(exports, "arrayEachFields", { enumerable: true, get: function () { return model_1.arrayEachFields; } });
51
52
  Object.defineProperty(exports, "isRepeatedRecord", { enumerable: true, get: function () { return model_1.isRepeatedRecord; } });
@@ -3,7 +3,7 @@
3
3
  * Copyright (c) Meta Platforms, Inc. and affiliates.
4
4
  *
5
5
  * This source code is licensed under the MIT license found in the
6
- * LICENSE file in the root directory of this source tree.
6
+ * LICENSE file in the root directory of this source tree.
7
7
  */
8
8
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
9
9
  if (k2 === undefined) k2 = k;
@@ -0,0 +1,9 @@
1
+ import { ExprValue } from '../types/expr-value';
2
+ import { ExpressionDef } from '../types/expression-def';
3
+ import { FieldSpace } from '../types/field-space';
4
+ export declare class ArrayLiteral extends ExpressionDef {
5
+ readonly elements: ExpressionDef[];
6
+ elementType: string;
7
+ constructor(elements: ExpressionDef[]);
8
+ getExpression(fs: FieldSpace): ExprValue;
9
+ }
@@ -0,0 +1,93 @@
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
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
9
+ if (k2 === undefined) k2 = k;
10
+ var desc = Object.getOwnPropertyDescriptor(m, k);
11
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
12
+ desc = { enumerable: true, get: function() { return m[k]; } };
13
+ }
14
+ Object.defineProperty(o, k2, desc);
15
+ }) : (function(o, m, k, k2) {
16
+ if (k2 === undefined) k2 = k;
17
+ o[k2] = m[k];
18
+ }));
19
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
20
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
21
+ }) : function(o, v) {
22
+ o["default"] = v;
23
+ });
24
+ var __importStar = (this && this.__importStar) || function (mod) {
25
+ if (mod && mod.__esModule) return mod;
26
+ var result = {};
27
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
28
+ __setModuleDefault(result, mod);
29
+ return result;
30
+ };
31
+ Object.defineProperty(exports, "__esModule", { value: true });
32
+ exports.ArrayLiteral = void 0;
33
+ const model_1 = require("../../../model");
34
+ const expr_value_1 = require("../types/expr-value");
35
+ const expression_def_1 = require("../types/expression-def");
36
+ const TDU = __importStar(require("../typedesc-utils"));
37
+ class ArrayLiteral extends expression_def_1.ExpressionDef {
38
+ constructor(elements) {
39
+ super();
40
+ this.elements = elements;
41
+ this.elementType = 'array literal';
42
+ this.has({ elements });
43
+ }
44
+ getExpression(fs) {
45
+ const values = [];
46
+ const fromValues = [];
47
+ let firstValue = undefined;
48
+ if (this.elements.length > 0) {
49
+ for (const nextElement of this.elements) {
50
+ const v = nextElement.getExpression(fs);
51
+ fromValues.push(v);
52
+ if (v.type === 'error') {
53
+ continue;
54
+ }
55
+ if (firstValue) {
56
+ if (!TDU.typeEq(firstValue, v)) {
57
+ nextElement.logError('array-values-incompatible', 'All array elements must be same type');
58
+ continue;
59
+ }
60
+ }
61
+ else {
62
+ firstValue = v;
63
+ }
64
+ values.push(v.value);
65
+ }
66
+ }
67
+ const elementTypeDef = TDU.atomicDef(firstValue || { type: 'number' });
68
+ const typeDef = {
69
+ type: 'array',
70
+ join: 'many',
71
+ name: '',
72
+ dialect: fs.dialectName(),
73
+ elementTypeDef: elementTypeDef.type !== 'record'
74
+ ? elementTypeDef
75
+ : { type: 'record_element' },
76
+ fields: elementTypeDef.type === 'record'
77
+ ? elementTypeDef.fields
78
+ : (0, model_1.arrayEachFields)(elementTypeDef),
79
+ };
80
+ const aLit = {
81
+ node: 'arrayLiteral',
82
+ kids: { values },
83
+ typeDef,
84
+ };
85
+ return (0, expr_value_1.computedExprValue)({
86
+ dataType: typeDef,
87
+ value: aLit,
88
+ from: fromValues,
89
+ });
90
+ }
91
+ }
92
+ exports.ArrayLiteral = ArrayLiteral;
93
+ //# sourceMappingURL=expr-array-literal.js.map
@@ -12,5 +12,5 @@ export declare class RecordLiteral extends ExpressionDef {
12
12
  readonly pairs: RecordElement[];
13
13
  elementType: string;
14
14
  constructor(pairs: RecordElement[]);
15
- getExpression(_fs: FieldSpace): ExprValue;
15
+ getExpression(fs: FieldSpace): ExprValue;
16
16
  }
@@ -3,12 +3,38 @@
3
3
  * Copyright (c) Meta Platforms, Inc. and affiliates.
4
4
  *
5
5
  * This source code is licensed under the MIT license found in the
6
- * LICENSE file in the root directory of this source tree.
6
+ * LICENSE file in the root directory of this source tree.
7
7
  */
8
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
9
+ if (k2 === undefined) k2 = k;
10
+ var desc = Object.getOwnPropertyDescriptor(m, k);
11
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
12
+ desc = { enumerable: true, get: function() { return m[k]; } };
13
+ }
14
+ Object.defineProperty(o, k2, desc);
15
+ }) : (function(o, m, k, k2) {
16
+ if (k2 === undefined) k2 = k;
17
+ o[k2] = m[k];
18
+ }));
19
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
20
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
21
+ }) : function(o, v) {
22
+ o["default"] = v;
23
+ });
24
+ var __importStar = (this && this.__importStar) || function (mod) {
25
+ if (mod && mod.__esModule) return mod;
26
+ var result = {};
27
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
28
+ __setModuleDefault(result, mod);
29
+ return result;
30
+ };
8
31
  Object.defineProperty(exports, "__esModule", { value: true });
9
32
  exports.RecordLiteral = exports.RecordElement = void 0;
33
+ const model_1 = require("../../../model");
34
+ const expr_value_1 = require("../types/expr-value");
10
35
  const expression_def_1 = require("../types/expression-def");
11
36
  const malloy_element_1 = require("../types/malloy-element");
37
+ const TDU = __importStar(require("../typedesc-utils"));
12
38
  class RecordElement extends malloy_element_1.MalloyElement {
13
39
  constructor(key, value) {
14
40
  super();
@@ -26,33 +52,35 @@ class RecordLiteral extends expression_def_1.ExpressionDef {
26
52
  this.elementType = 'record literal';
27
53
  this.has({ pairs });
28
54
  }
29
- getExpression(_fs) {
30
- throw new Error('get expression on record todo');
31
- // const recLit: RecordLiteralNode = {
32
- // node: 'recordLiteral',
33
- // kids: {},
34
- // };
35
- // const dependents: ExprValue[] = [];
36
- // for (const el of this.pairs) {
37
- // const xVal = el.value.getExpression(fs);
38
- // const expr: TypedExpr = {typeDef: {type: 'error'}, ...xVal.value};
39
- // if (TD.isError(expr.typeDef) && isAtomicFieldType(xVal.dataType)) {
40
- // expr.typeDef = xVal.dataType;
41
- // }
42
- // if (TD.isError(expr.typeDef) && xVal.dataType !== 'error') {
43
- // this.logError(
44
- // 'illegal-record-property-type',
45
- // `Type '${xVal.dataType}' not a legal record value`
46
- // );
47
- // }
48
- // recLit.kids[el.key] = expr;
49
- // dependents.push(xVal);
50
- // }
51
- // return computedExprValue({
52
- // dataType: 'record',
53
- // value: recLit,
54
- // from: dependents,
55
- // });
55
+ getExpression(fs) {
56
+ const recLit = {
57
+ node: 'recordLiteral',
58
+ kids: {},
59
+ typeDef: {
60
+ name: '',
61
+ type: 'record',
62
+ join: 'one',
63
+ dialect: fs.dialectName(),
64
+ fields: [],
65
+ },
66
+ };
67
+ const dependents = [];
68
+ for (const el of this.pairs) {
69
+ const xVal = el.value.getExpression(fs);
70
+ if (model_1.TD.isAtomic(xVal)) {
71
+ dependents.push(xVal);
72
+ recLit.kids[el.key] = xVal.value;
73
+ recLit.typeDef.fields.push({ ...TDU.atomicDef(xVal), name: el.key });
74
+ }
75
+ else {
76
+ this.logError('illegal-record-property-type', `Record property '${el.key} is type '${xVal.type}', which is not a legal property value type`);
77
+ }
78
+ }
79
+ return (0, expr_value_1.computedExprValue)({
80
+ value: recLit,
81
+ dataType: recLit.typeDef,
82
+ from: dependents,
83
+ });
56
84
  }
57
85
  }
58
86
  exports.RecordLiteral = RecordLiteral;
@@ -4,5 +4,5 @@ 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, parentDialect: string);
7
+ constructor(parameterSpace: ParameterSpace, join: Join);
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, parentDialect) {
29
- super(join.structDef(parameterSpace), parentDialect);
28
+ constructor(parameterSpace, join) {
29
+ super(join.structDef(parameterSpace));
30
30
  this.parameterSpace = parameterSpace;
31
31
  this.join = join;
32
32
  }
@@ -32,7 +32,7 @@ class ProjectFieldSpace extends query_spaces_1.QuerySpace {
32
32
  }
33
33
  canContain(typeDesc) {
34
34
  if (typeDesc === undefined ||
35
- !malloy_types_1.TD.isLeafAtomic(typeDesc) ||
35
+ !malloy_types_1.TD.isAtomic(typeDesc) ||
36
36
  (0, malloy_types_1.expressionIsAggregate)(typeDesc.expressionType)) {
37
37
  // We don't need to log here, because an error should have already been logged.
38
38
  return false;
@@ -84,7 +84,7 @@ class ReferenceField extends space_field_1.SpaceField {
84
84
  };
85
85
  }
86
86
  else {
87
- // mtoy todo
87
+ // not sure what to do here, if we get here
88
88
  throw new Error('impossible turtle/join parameter');
89
89
  }
90
90
  }
@@ -26,8 +26,7 @@ export declare class StaticSpace implements FieldSpace {
26
26
  isQueryFieldSpace(): this is QueryFieldSpace;
27
27
  }
28
28
  export declare class StructSpaceField extends StructSpaceFieldBase {
29
- private parentDialect;
30
- constructor(def: JoinFieldDef, dialect: string);
29
+ constructor(def: JoinFieldDef);
31
30
  get fieldSpace(): FieldSpace;
32
31
  }
33
32
  export declare class StaticSourceSpace extends StaticSpace implements SourceFieldSpace {
@@ -51,7 +51,7 @@ class StaticSpace {
51
51
  }
52
52
  defToSpaceField(from) {
53
53
  if ((0, malloy_types_1.isJoined)(from)) {
54
- return new StructSpaceField(from, this.fromStruct.dialect);
54
+ return new StructSpaceField(from);
55
55
  }
56
56
  else if ((0, malloy_types_1.isTurtleDef)(from)) {
57
57
  return new ir_view_field_1.IRViewField(this, from);
@@ -107,7 +107,7 @@ class StaticSpace {
107
107
  lookup(path) {
108
108
  const head = path[0];
109
109
  const rest = path.slice(1);
110
- const found = this.entry(head.refString);
110
+ let found = this.entry(head.refString);
111
111
  if (!found) {
112
112
  return {
113
113
  error: {
@@ -120,6 +120,17 @@ class StaticSpace {
120
120
  if (found instanceof space_field_1.SpaceField) {
121
121
  const definition = found.fieldDef();
122
122
  if (definition) {
123
+ if (!(found instanceof struct_space_field_base_1.StructSpaceFieldBase) && (0, malloy_types_1.isJoined)(definition)) {
124
+ // We have looked up a field which is a join, but not a StructSpaceField
125
+ // because it is someting like "dimension: joinedArray is arrayComputation"
126
+ // which wasn't known to be a join when the fieldspace was constructed.
127
+ // TODO don't make one of these every time you do a lookup
128
+ found = new StructSpaceField(definition);
129
+ }
130
+ // cswenson review todo I don't know how to count the reference properly now
131
+ // i tried only writing it as a join reference if there was more in the path
132
+ // but that failed because lookup([JOINNAME]) is called when translating JOINNAME.AGGREGATE(...)
133
+ // with a 1-length-path but that IS a join reference and there is a test
123
134
  head.addReference({
124
135
  type: found instanceof struct_space_field_base_1.StructSpaceFieldBase
125
136
  ? 'joinReference'
@@ -129,7 +140,7 @@ class StaticSpace {
129
140
  text: head.refString,
130
141
  });
131
142
  }
132
- }
143
+ } // cswenson review todo { else this is SpaceEntry not a field which can only be a param and what is going on? }
133
144
  const joinPath = found instanceof struct_space_field_base_1.StructSpaceFieldBase
134
145
  ? [{ ...found.joinPathElement, name: head.refString }]
135
146
  : [];
@@ -162,9 +173,8 @@ class StaticSpace {
162
173
  }
163
174
  exports.StaticSpace = StaticSpace;
164
175
  class StructSpaceField extends struct_space_field_base_1.StructSpaceFieldBase {
165
- constructor(def, dialect) {
176
+ constructor(def) {
166
177
  super(def);
167
- this.parentDialect = dialect;
168
178
  }
169
179
  get fieldSpace() {
170
180
  return new StaticSpace(this.structDef);
@@ -62,7 +62,7 @@ export declare abstract class ViewField extends SpaceField {
62
62
  onCompositeFieldUsage?: import("../../../model/malloy_types").CompositeFieldUsage | undefined;
63
63
  annotation?: import("../../../model/malloy_types").Annotation | undefined;
64
64
  modelAnnotation?: import("../../../model/malloy_types").ModelAnnotation | undefined;
65
- fields: ((import("../../../model/malloy_types").StringTypeDef & import("../../../model/malloy_types").FieldBase) | (import("../../../model/malloy_types").DateTypeDef & import("../../../model/malloy_types").FieldBase) | (import("../../../model/malloy_types").TimestampTypeDef & import("../../../model/malloy_types").FieldBase) | (import("../../../model/malloy_types").NumberTypeDef & import("../../../model/malloy_types").FieldBase) | (import("../../../model/malloy_types").BooleanTypeDef & import("../../../model/malloy_types").FieldBase) | (import("../../../model/malloy_types").JSONTypeDef & import("../../../model/malloy_types").FieldBase) | (import("../../../model/malloy_types").NativeUnsupportedTypeDef & import("../../../model/malloy_types").FieldBase) | (import("../../../model/malloy_types").ErrorTypeDef & import("../../../model/malloy_types").FieldBase) | (import("../../../model/malloy_types").ArrayTypeDef & import("../../../model/malloy_types").FieldBase) | (import("../../../model/malloy_types").RecordTypeDef & import("../../../model/malloy_types").FieldBase) | (import("../../../model/malloy_types").JoinBase & import("../../../model/malloy_types").TableSourceDef) | (import("../../../model/malloy_types").JoinBase & import("../../../model/malloy_types").SQLSourceDef) | (import("../../../model/malloy_types").JoinBase & import("../../../model/malloy_types").QuerySourceDef) | (import("../../../model/malloy_types").JoinBase & import("../../../model/malloy_types").ArrayTypeDef & import("../../../model/malloy_types").FieldBase) | (import("../../../model/malloy_types").JoinBase & import("../../../model/malloy_types").RecordTypeDef & import("../../../model/malloy_types").FieldBase) | TurtleDef)[];
65
+ fields: ((import("../../../model/malloy_types").StringTypeDef & import("../../../model/malloy_types").FieldBase) | (import("../../../model/malloy_types").DateTypeDef & import("../../../model/malloy_types").FieldBase) | (import("../../../model/malloy_types").TimestampTypeDef & import("../../../model/malloy_types").FieldBase) | (import("../../../model/malloy_types").NumberTypeDef & import("../../../model/malloy_types").FieldBase) | (import("../../../model/malloy_types").BooleanTypeDef & import("../../../model/malloy_types").FieldBase) | (import("../../../model/malloy_types").JSONTypeDef & import("../../../model/malloy_types").FieldBase) | (import("../../../model/malloy_types").NativeUnsupportedTypeDef & import("../../../model/malloy_types").FieldBase) | (import("../../../model/malloy_types").ErrorTypeDef & import("../../../model/malloy_types").FieldBase) | (import("../../../model/malloy_types").ArrayTypeDef & import("../../../model/malloy_types").FieldBase) | (import("../../../model/malloy_types").RecordTypeDef & import("../../../model/malloy_types").FieldBase) | (import("../../../model/malloy_types").JoinBase & import("../../../model/malloy_types").TableSourceDef) | (import("../../../model/malloy_types").JoinBase & import("../../../model/malloy_types").SQLSourceDef) | (import("../../../model/malloy_types").JoinBase & import("../../../model/malloy_types").QuerySourceDef) | (import("../../../model/malloy_types").JoinBase & import("../../../model/malloy_types").CompositeSourceDef) | (import("../../../model/malloy_types").JoinBase & import("../../../model/malloy_types").ArrayTypeDef & import("../../../model/malloy_types").FieldBase) | (import("../../../model/malloy_types").JoinBase & import("../../../model/malloy_types").RecordTypeDef & import("../../../model/malloy_types").FieldBase) | TurtleDef)[];
66
66
  dialect: string;
67
67
  location?: import("../../../model/malloy_types").DocumentLocation | undefined;
68
68
  name: string;
@@ -75,7 +75,7 @@ export declare abstract class ViewField extends SpaceField {
75
75
  join: "one";
76
76
  annotation?: import("../../../model/malloy_types").Annotation | undefined;
77
77
  modelAnnotation?: import("../../../model/malloy_types").ModelAnnotation | undefined;
78
- fields: ((import("../../../model/malloy_types").StringTypeDef & import("../../../model/malloy_types").FieldBase) | (import("../../../model/malloy_types").DateTypeDef & import("../../../model/malloy_types").FieldBase) | (import("../../../model/malloy_types").TimestampTypeDef & import("../../../model/malloy_types").FieldBase) | (import("../../../model/malloy_types").NumberTypeDef & import("../../../model/malloy_types").FieldBase) | (import("../../../model/malloy_types").BooleanTypeDef & import("../../../model/malloy_types").FieldBase) | (import("../../../model/malloy_types").JSONTypeDef & import("../../../model/malloy_types").FieldBase) | (import("../../../model/malloy_types").NativeUnsupportedTypeDef & import("../../../model/malloy_types").FieldBase) | (import("../../../model/malloy_types").ErrorTypeDef & import("../../../model/malloy_types").FieldBase) | (import("../../../model/malloy_types").ArrayTypeDef & import("../../../model/malloy_types").FieldBase) | (import("../../../model/malloy_types").RecordTypeDef & import("../../../model/malloy_types").FieldBase) | (import("../../../model/malloy_types").JoinBase & import("../../../model/malloy_types").TableSourceDef) | (import("../../../model/malloy_types").JoinBase & import("../../../model/malloy_types").SQLSourceDef) | (import("../../../model/malloy_types").JoinBase & import("../../../model/malloy_types").QuerySourceDef) | (import("../../../model/malloy_types").JoinBase & import("../../../model/malloy_types").ArrayTypeDef & import("../../../model/malloy_types").FieldBase) | (import("../../../model/malloy_types").JoinBase & import("../../../model/malloy_types").RecordTypeDef & import("../../../model/malloy_types").FieldBase) | TurtleDef)[];
78
+ fields: ((import("../../../model/malloy_types").StringTypeDef & import("../../../model/malloy_types").FieldBase) | (import("../../../model/malloy_types").DateTypeDef & import("../../../model/malloy_types").FieldBase) | (import("../../../model/malloy_types").TimestampTypeDef & import("../../../model/malloy_types").FieldBase) | (import("../../../model/malloy_types").NumberTypeDef & import("../../../model/malloy_types").FieldBase) | (import("../../../model/malloy_types").BooleanTypeDef & import("../../../model/malloy_types").FieldBase) | (import("../../../model/malloy_types").JSONTypeDef & import("../../../model/malloy_types").FieldBase) | (import("../../../model/malloy_types").NativeUnsupportedTypeDef & import("../../../model/malloy_types").FieldBase) | (import("../../../model/malloy_types").ErrorTypeDef & import("../../../model/malloy_types").FieldBase) | (import("../../../model/malloy_types").ArrayTypeDef & import("../../../model/malloy_types").FieldBase) | (import("../../../model/malloy_types").RecordTypeDef & import("../../../model/malloy_types").FieldBase) | (import("../../../model/malloy_types").JoinBase & import("../../../model/malloy_types").TableSourceDef) | (import("../../../model/malloy_types").JoinBase & import("../../../model/malloy_types").SQLSourceDef) | (import("../../../model/malloy_types").JoinBase & import("../../../model/malloy_types").QuerySourceDef) | (import("../../../model/malloy_types").JoinBase & import("../../../model/malloy_types").CompositeSourceDef) | (import("../../../model/malloy_types").JoinBase & import("../../../model/malloy_types").ArrayTypeDef & import("../../../model/malloy_types").FieldBase) | (import("../../../model/malloy_types").JoinBase & import("../../../model/malloy_types").RecordTypeDef & import("../../../model/malloy_types").FieldBase) | TurtleDef)[];
79
79
  dialect: string;
80
80
  location?: import("../../../model/malloy_types").DocumentLocation | undefined;
81
81
  name: string;
@@ -54,6 +54,7 @@ export * from './expressions/partial-compare';
54
54
  export * from './expressions/partition_by';
55
55
  export * from './expressions/pick-when';
56
56
  export * from './expressions/case';
57
+ export * from './expressions/expr-array-literal';
57
58
  export * from './expressions/expr-record-literal';
58
59
  export * from './expressions/range';
59
60
  export * from './expressions/time-frame';
@@ -92,6 +92,7 @@ __exportStar(require("./expressions/partial-compare"), exports);
92
92
  __exportStar(require("./expressions/partition_by"), exports);
93
93
  __exportStar(require("./expressions/pick-when"), exports);
94
94
  __exportStar(require("./expressions/case"), exports);
95
+ __exportStar(require("./expressions/expr-array-literal"), exports);
95
96
  __exportStar(require("./expressions/expr-record-literal"), exports);
96
97
  __exportStar(require("./expressions/range"), exports);
97
98
  __exportStar(require("./expressions/time-frame"), exports);
@@ -96,20 +96,26 @@ class AtomicFieldDeclaration extends malloy_element_1.MalloyElement {
96
96
  type: 'error',
97
97
  };
98
98
  }
99
- let retType = exprValue.type;
100
- if (retType === 'null') {
99
+ if (exprValue.type === 'null') {
101
100
  this.expr.logWarning('null-typed-field-definition', 'null value defaults to type number, use "null::TYPE" to specify correct type');
102
- retType = 'number';
101
+ const nullAsNumber = {
102
+ type: 'number',
103
+ value: exprValue.value,
104
+ expressionType: exprValue.expressionType,
105
+ evalSpace: exprValue.evalSpace,
106
+ compositeFieldUsage: exprValue.compositeFieldUsage,
107
+ };
108
+ exprValue = nullAsNumber;
103
109
  }
104
- if ((0, malloy_types_1.isAtomicFieldType)(retType) && retType !== 'error') {
110
+ if ((0, malloy_types_1.isAtomicFieldType)(exprValue.type) && exprValue.type !== 'error') {
105
111
  this.typecheckExprValue(exprValue);
106
112
  let ret;
107
- switch (retType) {
113
+ switch (exprValue.type) {
108
114
  case 'date':
109
115
  case 'timestamp': {
110
116
  const timeRet = {
111
117
  name: exprName,
112
- type: retType,
118
+ type: exprValue.type,
113
119
  location: this.location,
114
120
  e: exprValue.value,
115
121
  compositeFieldUsage: exprValue.compositeFieldUsage,
@@ -126,7 +132,7 @@ class AtomicFieldDeclaration extends malloy_element_1.MalloyElement {
126
132
  case 'number':
127
133
  case 'sql native': {
128
134
  ret = {
129
- type: retType,
135
+ type: exprValue.type,
130
136
  name: exprName,
131
137
  location: this.location,
132
138
  e: exprValue.value,
@@ -135,21 +141,29 @@ class AtomicFieldDeclaration extends malloy_element_1.MalloyElement {
135
141
  break;
136
142
  }
137
143
  case 'record': {
138
- const fields = [];
139
144
  ret = {
140
145
  type: 'record',
141
146
  name: exprName,
142
147
  location: this.location,
143
148
  join: 'one',
144
- fields,
149
+ fields: exprValue.fields,
145
150
  e: exprValue.value,
146
151
  compositeFieldUsage: exprValue.compositeFieldUsage,
147
152
  dialect: exprFS.dialectName(),
148
153
  };
149
154
  break;
150
155
  }
151
- case 'array':
152
- throw this.internalError('Cannot return an array result from a query (yet)');
156
+ case 'array': {
157
+ ret = {
158
+ type: 'array',
159
+ elementTypeDef: exprValue.elementTypeDef,
160
+ name: exprName,
161
+ join: 'many',
162
+ fields: exprValue.fields,
163
+ e: exprValue.value,
164
+ dialect: exprValue.dialect,
165
+ };
166
+ }
153
167
  }
154
168
  if (exprValue.expressionType) {
155
169
  ret.expressionType = exprValue.expressionType;
@@ -73,8 +73,6 @@ class Filter extends malloy_element_1.ListOf {
73
73
  }
74
74
  checkedFilterCondition(fs, filter) {
75
75
  const fExpr = filter.filterCondition(fs);
76
- // mtoy todo is having we never set then queryRefinementStage might be wrong
77
- // ... calculations and aggregations must go last
78
76
  // Aggregates are ALSO checked at SQL generation time, but checking
79
77
  // here allows better reflection of errors back to user.
80
78
  if (this.havingClause !== undefined) {
@@ -37,7 +37,7 @@ class Join extends malloy_element_1.MalloyElement {
37
37
  this.extendNote = noteable_1.extendNoteMethod;
38
38
  }
39
39
  makeEntry(fs) {
40
- fs.newEntry(this.name.refString, this, new join_space_field_1.JoinSpaceField(fs.parameterSpace(), this, fs.dialect));
40
+ fs.newEntry(this.name.refString, this, new join_space_field_1.JoinSpaceField(fs.parameterSpace(), this));
41
41
  }
42
42
  getStructDefFromExpr(parameterSpace) {
43
43
  const source = this.sourceExpr.getSource();
@@ -3,7 +3,7 @@
3
3
  * Copyright (c) Meta Platforms, Inc. and affiliates.
4
4
  *
5
5
  * This source code is licensed under the MIT license found in the
6
- * LICENSE file in the root directory of this source tree.
6
+ * LICENSE file in the root directory of this source tree.
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.isComparison = exports.isEquality = exports.getExprNode = void 0;
@@ -3,7 +3,7 @@
3
3
  * Copyright (c) Meta Platforms, Inc. and affiliates.
4
4
  *
5
5
  * This source code is licensed under the MIT license found in the
6
- * LICENSE file in the root directory of this source tree.
6
+ * LICENSE file in the root directory of this source tree.
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.DialectNameSpace = void 0;
@@ -2055,7 +2055,7 @@ export declare class ExprLiteralRecordContext extends FieldExprContext {
2055
2055
  OCURLY(): TerminalNode;
2056
2056
  recordElement(): RecordElementContext[];
2057
2057
  recordElement(i: number): RecordElementContext;
2058
- closeCurly(): CloseCurlyContext;
2058
+ CCURLY(): TerminalNode;
2059
2059
  COMMA(): TerminalNode[];
2060
2060
  COMMA(i: number): TerminalNode;
2061
2061
  constructor(ctx: FieldExprContext);
@@ -5817,24 +5817,22 @@ class MalloyParser extends Parser_1.Parser {
5817
5817
  this.recordElement();
5818
5818
  this.state = 1094;
5819
5819
  this._errHandler.sync(this);
5820
- _alt = this.interpreter.adaptivePredict(this._input, 110, this._ctx);
5821
- while (_alt !== 2 && _alt !== ATN_1.ATN.INVALID_ALT_NUMBER) {
5822
- if (_alt === 1) {
5820
+ _la = this._input.LA(1);
5821
+ while (_la === MalloyParser.COMMA) {
5822
+ {
5823
5823
  {
5824
- {
5825
- this.state = 1090;
5826
- this.match(MalloyParser.COMMA);
5827
- this.state = 1091;
5828
- this.recordElement();
5829
- }
5824
+ this.state = 1090;
5825
+ this.match(MalloyParser.COMMA);
5826
+ this.state = 1091;
5827
+ this.recordElement();
5830
5828
  }
5831
5829
  }
5832
5830
  this.state = 1096;
5833
5831
  this._errHandler.sync(this);
5834
- _alt = this.interpreter.adaptivePredict(this._input, 110, this._ctx);
5832
+ _la = this._input.LA(1);
5835
5833
  }
5836
5834
  this.state = 1097;
5837
- this.closeCurly();
5835
+ this.match(MalloyParser.CCURLY);
5838
5836
  }
5839
5837
  break;
5840
5838
  case 5:
@@ -8569,8 +8567,8 @@ MalloyParser._serializedATNSegment2 = "\u0430\xE7\x03\x02\x02\x02\u0431\u0432\bu
8569
8567
  "\u0448\x05\xF8}\x02\u0444\u0445\x07w\x02\x02\u0445\u0447\x05\xF8}\x02" +
8570
8568
  "\u0446\u0444\x03\x02\x02\x02\u0447\u044A\x03\x02\x02\x02\u0448\u0446\x03" +
8571
8569
  "\x02\x02\x02\u0448\u0449\x03\x02\x02\x02\u0449\u044B\x03\x02\x02\x02\u044A" +
8572
- "\u0448\x03\x02\x02\x02\u044B\u044C\x05\x04\x03\x02\u044C\u0499\x03\x02" +
8573
- "\x02\x02\u044D\u044E\x07\x80\x02\x02\u044E\u0499\x05\xE8u\x1B\u044F\u0450" +
8570
+ "\u0448\x03\x02\x02\x02\u044B\u044C\x07r\x02\x02\u044C\u0499\x03\x02\x02" +
8571
+ "\x02\u044D\u044E\x07\x80\x02\x02\u044E\u0499\x05\xE8u\x1B\u044F\u0450" +
8574
8572
  "\x07I\x02\x02\u0450\u0499\x05\xE8u\x0F\u0451\u0452\x07+\x02\x02\u0452" +
8575
8573
  "\u0453\x07m\x02\x02\u0453\u0454\x05\xE8u\x02\u0454\u0455\x07%\x02\x02" +
8576
8574
  "\u0455\u0456\x05\xE6t\x02\u0456\u0457\x07n\x02\x02\u0457\u0499\x03\x02" +
@@ -14590,9 +14588,7 @@ class ExprLiteralRecordContext extends FieldExprContext {
14590
14588
  return this.getRuleContext(i, RecordElementContext);
14591
14589
  }
14592
14590
  }
14593
- closeCurly() {
14594
- return this.getRuleContext(0, CloseCurlyContext);
14595
- }
14591
+ CCURLY() { return this.getToken(MalloyParser.CCURLY, 0); }
14596
14592
  COMMA(i) {
14597
14593
  if (i === undefined) {
14598
14594
  return this.getTokens(MalloyParser.COMMA);
@@ -228,7 +228,7 @@ export declare class MalloyToAST extends AbstractParseTreeVisitor<ast.MalloyElem
228
228
  visitRecordRef(pcx: parse.RecordRefContext): ast.RecordElement;
229
229
  visitRecordExpr(pcx: parse.RecordExprContext): ast.RecordElement;
230
230
  visitExprLiteralRecord(pcx: parse.ExprLiteralRecordContext): ast.RecordLiteral;
231
- visitExprArrayLiteral(pcx: parse.ExprArrayLiteralContext): ast.Unimplemented;
231
+ visitExprArrayLiteral(pcx: parse.ExprArrayLiteralContext): ast.ArrayLiteral;
232
232
  visitExprWarnLike(pcx: parse.ExprWarnLikeContext): ast.ExprCompare;
233
233
  visitExprWarnNullCmp(pcx: parse.ExprWarnNullCmpContext): ast.ExprCompare;
234
234
  visitExprWarnIn(pcx: parse.ExprWarnInContext): ast.ExprLegacyIn;
@@ -1338,13 +1338,13 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
1338
1338
  return new ast.RecordElement(elementKey, elementVal);
1339
1339
  }
1340
1340
  visitExprLiteralRecord(pcx) {
1341
- this.contextError(pcx, 'not-yet-implemented', 'Record data is not yet implemented');
1342
1341
  const els = this.only(pcx.recordElement().map(elCx => this.astAt(this.visit(elCx), elCx)), visited => visited instanceof ast.RecordElement && visited, 'a key value pair');
1343
1342
  return new ast.RecordLiteral(els);
1344
1343
  }
1345
1344
  visitExprArrayLiteral(pcx) {
1346
- this.contextError(pcx, 'not-yet-implemented', 'Array data is not yet implemented');
1347
- return new ast.Unimplemented();
1345
+ const contents = pcx.fieldExpr().map(fcx => this.getFieldExpr(fcx));
1346
+ const literal = new ast.ArrayLiteral(contents);
1347
+ return this.astAt(literal, pcx);
1348
1348
  }
1349
1349
  visitExprWarnLike(pcx) {
1350
1350
  let op = '~';