@malloydata/malloy 0.0.220-dev241205013400 → 0.0.220-dev241205182408

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.
@@ -393,8 +393,7 @@ ${(0, utils_1.indent)(sql)}
393
393
  }
394
394
  }
395
395
  else if (malloyType.type === 'record' ||
396
- (malloyType.type === 'array' &&
397
- malloyType.elementTypeDef.type === 'record_element')) {
396
+ (0, malloy_types_1.isRepeatedRecordType)(malloyType)) {
398
397
  const sqlFields = malloyType.fields.reduce((ret, f) => {
399
398
  var _a;
400
399
  if ((0, malloy_types_1.isAtomic)(f)) {
@@ -409,8 +408,7 @@ ${(0, utils_1.indent)(sql)}
409
408
  ? recordScehma
410
409
  : `ARRAY(${recordScehma})`;
411
410
  }
412
- else if (malloyType.type === 'array' &&
413
- malloyType.elementTypeDef.type !== 'record_element') {
411
+ else if ((0, malloy_types_1.isScalarArrayType)(malloyType)) {
414
412
  return `ARRAY(${this.malloyTypeToSQLType(malloyType.elementTypeDef)})`;
415
413
  }
416
414
  return malloyType.type;
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  export { DuckDBDialect, StandardSQLDialect, TrinoDialect, PostgresDialect, SnowflakeDialect, MySQLDialect, registerDialect, arg, qtz, overload, minScalar, anyExprType, minAggregate, maxScalar, sql, makeParam, param, variadicParam, literal, spread, Dialect, TinyParser, } from './dialect';
2
2
  export type { DialectFieldList, DialectFunctionOverloadDef, QueryInfo, MalloyStandardFunctionImplementations, DefinitionBlueprint, DefinitionBlueprintMap, OverloadedDefinitionBlueprint, TinyToken, } from './dialect';
3
3
  export type { QueryDataRow, StructDef, TableSourceDef, SQLSourceDef, SourceDef, JoinFieldDef, NamedSourceDefs, MalloyQueryData, DateUnit, ExtractUnit, TimestampUnit, TemporalFieldType, QueryData, QueryValue, Expr, FilterCondition, SQLSentence, FieldDef, PipeSegment, QueryFieldDef, IndexFieldDef, TurtleDef, SearchValueMapResult, SearchIndexResult, ModelDef, Query, QueryResult, QueryRunStats, NamedQuery, NamedModelObject, ExpressionType, FunctionDef, FunctionOverloadDef, FunctionParameterDef, ExpressionValueType, TypeDesc, FunctionParamTypeDesc, DocumentLocation, DocumentRange, DocumentPosition, Sampling, Annotation, LeafAtomicTypeDef, LeafAtomicDef, AtomicTypeDef, AtomicFieldDef, ArrayDef, ArrayTypeDef, RecordTypeDef, RepeatedRecordTypeDef, RecordDef, RepeatedRecordDef, RecordLiteralNode, ArrayLiteralNode, } from './model';
4
- export { arrayEachFields, isRepeatedRecord, isSourceDef, Segment, isLeafAtomic, isJoined, isJoinedSource, isSamplingEnable, isSamplingPercent, isSamplingRows, expressionIsAggregate, expressionIsAnalytic, expressionIsCalculation, expressionIsScalar, expressionIsUngroupedAggregate, indent, composeSQLExpr, } from './model';
4
+ export { isRepeatedRecord, isSourceDef, Segment, isLeafAtomic, isJoinedField, isJoinedSource, isSamplingEnable, isSamplingPercent, isSamplingRows, isRepeatedRecordType, isScalarArrayType, isScalarArray, mkArrayDef, mkFieldDef, expressionIsAggregate, expressionIsAnalytic, expressionIsCalculation, expressionIsScalar, expressionIsUngroupedAggregate, indent, composeSQLExpr, } from './model';
5
5
  export { MalloyTranslator, } from './lang';
6
6
  export type { LogMessage, TranslateResponse } from './lang';
7
7
  export { Model, Malloy, Runtime, AtomicFieldType, ConnectionRuntime, SingleConnectionRuntime, EmptyURLReader, InMemoryURLReader, FixedConnectionMap, MalloyError, JoinRelationship, SourceRelationship, DateTimeframe, TimestampTimeframe, PreparedResult, Result, QueryMaterializer, CSVWriter, JSONWriter, Parse, DataWriter, Explore, } from './malloy';
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
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;
3
+ 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.mkFieldDef = exports.mkArrayDef = exports.isScalarArray = exports.isScalarArrayType = exports.isRepeatedRecordType = exports.isSamplingRows = exports.isSamplingPercent = exports.isSamplingEnable = exports.isJoinedSource = exports.isJoinedField = exports.isLeafAtomic = exports.Segment = exports.isSourceDef = exports.isRepeatedRecord = 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 = exports.MalloyError = exports.FixedConnectionMap = exports.InMemoryURLReader = exports.EmptyURLReader = void 0;
5
5
  /*
6
6
  * Copyright 2023 Google LLC
7
7
  *
@@ -48,17 +48,21 @@ Object.defineProperty(exports, "spread", { enumerable: true, get: function () {
48
48
  Object.defineProperty(exports, "Dialect", { enumerable: true, get: function () { return dialect_1.Dialect; } });
49
49
  Object.defineProperty(exports, "TinyParser", { enumerable: true, get: function () { return dialect_1.TinyParser; } });
50
50
  var model_1 = require("./model");
51
- Object.defineProperty(exports, "arrayEachFields", { enumerable: true, get: function () { return model_1.arrayEachFields; } });
52
51
  Object.defineProperty(exports, "isRepeatedRecord", { enumerable: true, get: function () { return model_1.isRepeatedRecord; } });
53
52
  Object.defineProperty(exports, "isSourceDef", { enumerable: true, get: function () { return model_1.isSourceDef; } });
54
53
  // Used in Composer Demo
55
54
  Object.defineProperty(exports, "Segment", { enumerable: true, get: function () { return model_1.Segment; } });
56
55
  Object.defineProperty(exports, "isLeafAtomic", { enumerable: true, get: function () { return model_1.isLeafAtomic; } });
57
- Object.defineProperty(exports, "isJoined", { enumerable: true, get: function () { return model_1.isJoined; } });
56
+ Object.defineProperty(exports, "isJoinedField", { enumerable: true, get: function () { return model_1.isJoinedField; } });
58
57
  Object.defineProperty(exports, "isJoinedSource", { enumerable: true, get: function () { return model_1.isJoinedSource; } });
59
58
  Object.defineProperty(exports, "isSamplingEnable", { enumerable: true, get: function () { return model_1.isSamplingEnable; } });
60
59
  Object.defineProperty(exports, "isSamplingPercent", { enumerable: true, get: function () { return model_1.isSamplingPercent; } });
61
60
  Object.defineProperty(exports, "isSamplingRows", { enumerable: true, get: function () { return model_1.isSamplingRows; } });
61
+ Object.defineProperty(exports, "isRepeatedRecordType", { enumerable: true, get: function () { return model_1.isRepeatedRecordType; } });
62
+ Object.defineProperty(exports, "isScalarArrayType", { enumerable: true, get: function () { return model_1.isScalarArrayType; } });
63
+ Object.defineProperty(exports, "isScalarArray", { enumerable: true, get: function () { return model_1.isScalarArray; } });
64
+ Object.defineProperty(exports, "mkArrayDef", { enumerable: true, get: function () { return model_1.mkArrayDef; } });
65
+ Object.defineProperty(exports, "mkFieldDef", { enumerable: true, get: function () { return model_1.mkFieldDef; } });
62
66
  Object.defineProperty(exports, "expressionIsAggregate", { enumerable: true, get: function () { return model_1.expressionIsAggregate; } });
63
67
  Object.defineProperty(exports, "expressionIsAnalytic", { enumerable: true, get: function () { return model_1.expressionIsAnalytic; } });
64
68
  Object.defineProperty(exports, "expressionIsCalculation", { enumerable: true, get: function () { return model_1.expressionIsCalculation; } });
@@ -241,7 +241,7 @@ function getJoinUsage(fs, expr) {
241
241
  if (frag.node === 'field') {
242
242
  const def = lookupWithPath(fs, frag.path);
243
243
  const field = def.def;
244
- if ((0, malloy_types_1.isAtomic)(field) && !(0, malloy_types_1.isJoined)(field)) {
244
+ if ((0, malloy_types_1.isAtomic)(field) && !(0, malloy_types_1.isJoinedField)(field)) {
245
245
  if ((0, malloy_types_1.hasExpression)(field)) {
246
246
  const defUsage = getJoinUsage(def.fs, field.e);
247
247
  result.push(...defUsage.map(r => [...def.joinPath, ...r]));
@@ -30,7 +30,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
30
30
  };
31
31
  Object.defineProperty(exports, "__esModule", { value: true });
32
32
  exports.ArrayLiteral = void 0;
33
- const model_1 = require("../../../model");
34
33
  const expr_value_1 = require("../types/expr-value");
35
34
  const expression_def_1 = require("../types/expression-def");
36
35
  const TDU = __importStar(require("../typedesc-utils"));
@@ -65,18 +64,16 @@ class ArrayLiteral extends expression_def_1.ExpressionDef {
65
64
  }
66
65
  }
67
66
  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
- };
67
+ const typeDef = elementTypeDef.type === 'record'
68
+ ? {
69
+ type: 'array',
70
+ elementTypeDef: { type: 'record_element' },
71
+ fields: elementTypeDef.fields,
72
+ }
73
+ : {
74
+ type: 'array',
75
+ elementTypeDef,
76
+ };
80
77
  const aLit = {
81
78
  node: 'arrayLiteral',
82
79
  kids: { values },
@@ -57,10 +57,7 @@ class RecordLiteral extends expression_def_1.ExpressionDef {
57
57
  node: 'recordLiteral',
58
58
  kids: {},
59
59
  typeDef: {
60
- name: '',
61
60
  type: 'record',
62
- join: 'one',
63
- dialect: fs.dialectName(),
64
61
  fields: [],
65
62
  },
66
63
  };
@@ -70,7 +67,7 @@ class RecordLiteral extends expression_def_1.ExpressionDef {
70
67
  if (model_1.TD.isAtomic(xVal)) {
71
68
  dependents.push(xVal);
72
69
  recLit.kids[el.key] = xVal.value;
73
- recLit.typeDef.fields.push({ ...TDU.atomicDef(xVal), name: el.key });
70
+ recLit.typeDef.fields.push((0, model_1.mkFieldDef)(TDU.atomicDef(xVal), el.key, fs.dialectName()));
74
71
  }
75
72
  else {
76
73
  this.logError('illegal-record-property-type', `Record property '${el.key} is type '${xVal.type}', which is not a legal property value type`);
@@ -78,8 +78,7 @@ class ReferenceField extends space_field_1.SpaceField {
78
78
  const foundType = check.found.typeDesc();
79
79
  if (malloy_types_1.TD.isAtomic(foundType)) {
80
80
  this.queryFieldDef = {
81
- ...TDU.atomicDef(foundType),
82
- name: path[0],
81
+ ...(0, malloy_types_1.mkFieldDef)(TDU.atomicDef(foundType), path[0], fs.dialectName()),
83
82
  e: { node: 'parameter', path },
84
83
  };
85
84
  }
@@ -50,7 +50,7 @@ class StaticSpace {
50
50
  }
51
51
  }
52
52
  defToSpaceField(from) {
53
- if ((0, malloy_types_1.isJoined)(from)) {
53
+ if ((0, malloy_types_1.isJoinedField)(from)) {
54
54
  return new StructSpaceField(from);
55
55
  }
56
56
  else if ((0, malloy_types_1.isTurtleDef)(from)) {
@@ -120,7 +120,8 @@ 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)) {
123
+ if (!(found instanceof struct_space_field_base_1.StructSpaceFieldBase) &&
124
+ (0, malloy_types_1.isJoinedField)(definition)) {
124
125
  // We have looked up a field which is a join, but not a StructSpaceField
125
126
  // because it is someting like "dimension: joinedArray is arrayComputation"
126
127
  // which wasn't known to be a join when the fieldspace was constructed.
@@ -55,34 +55,20 @@ export declare abstract class ViewField extends SpaceField {
55
55
  } | {
56
56
  compositeFieldUsage: import("../../../model/malloy_types").CompositeFieldUsage;
57
57
  type: "array";
58
- elementTypeDef: import("../../../model/malloy_types").LeafAtomicTypeDef | import("../../../model/malloy_types").ArrayTypeDef | import("../../../model/malloy_types").RecordElementTypeDef;
59
- join: "many";
60
- matrixOperation?: import("../../../model/malloy_types").MatrixOperation | undefined;
61
- onExpression?: import("../../../model/malloy_types").Expr | undefined;
62
- onCompositeFieldUsage?: import("../../../model/malloy_types").CompositeFieldUsage | undefined;
63
- annotation?: import("../../../model/malloy_types").Annotation | undefined;
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").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
- dialect: string;
67
- location?: import("../../../model/malloy_types").DocumentLocation | undefined;
68
- name: string;
69
- as?: string | undefined;
58
+ elementTypeDef: import("../../../model/malloy_types").LeafAtomicTypeDef | import("../../../model/malloy_types").LeafArrayTypeDef | import("../../../model/malloy_types").RepeatedRecordTypeDef;
70
59
  expressionType: import("../../../model/malloy_types").ExpressionType;
71
60
  evalSpace: import("../../../model/malloy_types").EvalSpace;
72
61
  } | {
73
62
  compositeFieldUsage: import("../../../model/malloy_types").CompositeFieldUsage;
74
63
  type: "record";
75
- join: "one";
76
- annotation?: import("../../../model/malloy_types").Annotation | undefined;
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").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
- dialect: string;
80
- location?: import("../../../model/malloy_types").DocumentLocation | undefined;
81
- name: string;
82
- as?: string | undefined;
83
- matrixOperation?: import("../../../model/malloy_types").MatrixOperation | undefined;
84
- onExpression?: import("../../../model/malloy_types").Expr | undefined;
85
- onCompositeFieldUsage?: import("../../../model/malloy_types").CompositeFieldUsage | undefined;
64
+ fields: import("../../../model/malloy_types").FieldDef[];
65
+ expressionType: import("../../../model/malloy_types").ExpressionType;
66
+ evalSpace: import("../../../model/malloy_types").EvalSpace;
67
+ } | {
68
+ compositeFieldUsage: import("../../../model/malloy_types").CompositeFieldUsage;
69
+ type: "array";
70
+ elementTypeDef: import("../../../model/malloy_types").RecordElementTypeDef;
71
+ fields: import("../../../model/malloy_types").FieldDef[];
86
72
  expressionType: import("../../../model/malloy_types").ExpressionType;
87
73
  evalSpace: import("../../../model/malloy_types").EvalSpace;
88
74
  } | {
@@ -109,62 +109,14 @@ class AtomicFieldDeclaration extends malloy_element_1.MalloyElement {
109
109
  }
110
110
  if ((0, malloy_types_1.isAtomicFieldType)(exprValue.type) && exprValue.type !== 'error') {
111
111
  this.typecheckExprValue(exprValue);
112
- let ret;
113
- switch (exprValue.type) {
114
- case 'date':
115
- case 'timestamp': {
116
- const timeRet = {
117
- name: exprName,
118
- type: exprValue.type,
119
- location: this.location,
120
- e: exprValue.value,
121
- compositeFieldUsage: exprValue.compositeFieldUsage,
122
- };
123
- if ((0, granular_result_1.isGranularResult)(exprValue)) {
124
- timeRet.timeframe = exprValue.timeframe;
125
- }
126
- ret = timeRet;
127
- break;
128
- }
129
- case 'json':
130
- case 'boolean':
131
- case 'string':
132
- case 'number':
133
- case 'sql native': {
134
- ret = {
135
- type: exprValue.type,
136
- name: exprName,
137
- location: this.location,
138
- e: exprValue.value,
139
- compositeFieldUsage: exprValue.compositeFieldUsage,
140
- };
141
- break;
142
- }
143
- case 'record': {
144
- ret = {
145
- type: 'record',
146
- name: exprName,
147
- location: this.location,
148
- join: 'one',
149
- fields: exprValue.fields,
150
- e: exprValue.value,
151
- compositeFieldUsage: exprValue.compositeFieldUsage,
152
- dialect: exprFS.dialectName(),
153
- };
154
- break;
155
- }
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
- }
112
+ const ret = (0, malloy_types_1.mkFieldDef)(TDU.atomicDef(exprValue), exprName, exprFS.dialectName());
113
+ if ((ret.type === 'date' || ret.type === 'timestamp') &&
114
+ (0, granular_result_1.isGranularResult)(exprValue)) {
115
+ ret.timeframe = exprValue.timeframe;
167
116
  }
117
+ ret.location = this.location;
118
+ ret.e = exprValue.value;
119
+ ret.compositeFieldUsage = exprValue.compositeFieldUsage;
168
120
  if (exprValue.expressionType) {
169
121
  ret.expressionType = exprValue.expressionType;
170
122
  }
@@ -125,23 +125,19 @@ function atomicDef(td) {
125
125
  if (model_1.TD.isAtomic(td)) {
126
126
  switch (td.type) {
127
127
  case 'array': {
128
- return {
129
- name: '',
130
- type: 'array',
131
- join: 'many',
132
- elementTypeDef: td.elementTypeDef,
133
- dialect: td.dialect,
134
- fields: td.fields,
135
- };
128
+ return (0, model_1.isRepeatedRecordType)(td)
129
+ ? {
130
+ type: 'array',
131
+ elementTypeDef: td.elementTypeDef,
132
+ fields: td.fields,
133
+ }
134
+ : {
135
+ type: 'array',
136
+ elementTypeDef: td.elementTypeDef,
137
+ };
136
138
  }
137
139
  case 'record': {
138
- return {
139
- name: '',
140
- type: 'record',
141
- join: 'one',
142
- dialect: td.dialect,
143
- fields: td.fields,
144
- };
140
+ return { type: 'record', fields: td.fields };
145
141
  }
146
142
  case 'number': {
147
143
  return td.numberType
@@ -92,8 +92,8 @@ source: botProjQSrc is botProjQ
92
92
  const maybeField = newSrc === null || newSrc === void 0 ? void 0 : newSrc.fields.find(f => f.name === 'b');
93
93
  expect(maybeField).toBeDefined();
94
94
  const f = maybeField;
95
- expect((0, model_1.isJoined)(f)).toBeTruthy();
96
- if ((0, model_1.isJoined)(f)) {
95
+ expect((0, model_1.isJoinedField)(f)).toBeTruthy();
96
+ if ((0, model_1.isJoinedField)(f)) {
97
97
  expect(f.type).toBe('query_source');
98
98
  if (f.type === 'query_source') {
99
99
  expect(typeof f.query.structRef).not.toBe('string');
@@ -1038,7 +1038,7 @@ describe('query:', () => {
1038
1038
  const q = t.translated.queryList[0].pipeline[0];
1039
1039
  if (q.type === 'reduce' && q.extendSource) {
1040
1040
  expect(q.extendSource.length).toBe(1);
1041
- expect((0, model_1.isJoined)(q.extendSource[0])).toBeTruthy();
1041
+ expect((0, model_1.isJoinedField)(q.extendSource[0])).toBeTruthy();
1042
1042
  expect(q.extendSource[0].type).toBe('table');
1043
1043
  }
1044
1044
  else {
@@ -74,14 +74,7 @@ const mockSchema = {
74
74
  matrixOperation: 'left',
75
75
  dialect: 'standardsql',
76
76
  },
77
- {
78
- type: 'array',
79
- name: 'ais',
80
- elementTypeDef: intType,
81
- join: 'many',
82
- fields: (0, malloy_types_1.arrayEachFields)(intType),
83
- dialect: 'standardsql',
84
- },
77
+ (0, malloy_types_1.mkArrayDef)(intType, 'ais', 'standardsql'),
85
78
  ],
86
79
  },
87
80
  'malloytest.carriers': {
package/dist/malloy.js CHANGED
@@ -1041,7 +1041,7 @@ class Explore extends Entity {
1041
1041
  this._fieldMap = new Map(this.structDef.fields.map(fieldDef => {
1042
1042
  const name = fieldDef.as || fieldDef.name;
1043
1043
  const sourceField = sourceFields.get(fieldDef.name);
1044
- if ((0, model_1.isJoined)(fieldDef)) {
1044
+ if ((0, model_1.isJoinedField)(fieldDef)) {
1045
1045
  return [name, new ExploreField(fieldDef, this, sourceField)];
1046
1046
  }
1047
1047
  else if (fieldDef.type === 'turtle') {
@@ -107,7 +107,7 @@ function _resolveCompositeSources(path, source, compositeFieldUsage, narrowedCom
107
107
  error: { code: 'composite_source_not_defined', data: { path: newPath } },
108
108
  };
109
109
  }
110
- if (!(0, malloy_types_1.isJoined)(join) || !(0, malloy_types_1.isSourceDef)(join)) {
110
+ if (!(0, malloy_types_1.isJoinedField)(join) || !(0, malloy_types_1.isSourceDef)(join)) {
111
111
  return {
112
112
  error: { code: 'composite_source_not_a_join', data: { path: newPath } },
113
113
  };
@@ -1269,7 +1269,7 @@ class FieldInstanceResult {
1269
1269
  if (fi instanceof FieldInstanceField) {
1270
1270
  if (fi.fieldUsage.type === 'result') {
1271
1271
  if (fi.f.fieldDef.type === 'turtle' ||
1272
- (0, malloy_types_1.isJoined)(fi.f.fieldDef) ||
1272
+ (0, malloy_types_1.isJoinedField)(fi.f.fieldDef) ||
1273
1273
  (0, malloy_types_1.expressionIsAnalytic)(fi.f.fieldDef.expressionType)) {
1274
1274
  continue;
1275
1275
  }
@@ -381,28 +381,42 @@ export interface NativeUnsupportedTypeDef {
381
381
  rawType?: string;
382
382
  }
383
383
  export type NativeUnsupportedFieldDef = NativeUnsupportedTypeDef & AtomicFieldDef;
384
- export interface ArrayTypeDef extends JoinBase, StructDefBase {
384
+ export interface LeafArrayTypeDef {
385
+ type: 'array';
386
+ elementTypeDef: Exclude<AtomicTypeDef, RecordTypeDef>;
387
+ }
388
+ export interface LeafArrayDef extends LeafArrayTypeDef, StructDefBase, JoinBase, FieldBase {
385
389
  type: 'array';
386
- elementTypeDef: Exclude<AtomicTypeDef, RecordTypeDef> | RecordElementTypeDef;
387
390
  join: 'many';
388
391
  }
389
- export type ArrayDef = ArrayTypeDef & AtomicFieldDef;
390
- export declare function arrayEachFields(arrayOf: AtomicTypeDef): AtomicFieldDef[];
391
- export interface RecordTypeDef extends StructDefBase, JoinBase {
392
+ export declare function mkFieldDef(atd: AtomicTypeDef, name: string, dialect: string): AtomicFieldDef;
393
+ export declare function mkArrayDef(ofType: AtomicTypeDef, name: string, dialect: string): ArrayDef;
394
+ export interface RecordTypeDef {
395
+ type: 'record';
396
+ fields: FieldDef[];
397
+ }
398
+ export interface RecordDef extends RecordTypeDef, StructDefBase, JoinBase, FieldBase {
392
399
  type: 'record';
393
400
  join: 'one';
394
401
  }
395
402
  export interface RecordElementTypeDef {
396
403
  type: 'record_element';
397
404
  }
398
- export interface RepeatedRecordTypeDef extends ArrayDef {
405
+ export interface RepeatedRecordTypeDef {
399
406
  type: 'array';
400
407
  elementTypeDef: RecordElementTypeDef;
408
+ fields: FieldDef[];
409
+ }
410
+ export interface RepeatedRecordDef extends RepeatedRecordTypeDef, StructDefBase, JoinBase, FieldBase {
411
+ type: 'array';
401
412
  join: 'many';
402
413
  }
403
- export type RecordDef = RecordTypeDef & AtomicFieldDef;
404
- export type RepeatedRecordDef = RepeatedRecordTypeDef & AtomicFieldDef;
405
- export declare function isRepeatedRecord(fd: FieldDef): fd is RepeatedRecordDef;
414
+ export type ArrayTypeDef = LeafArrayTypeDef | RepeatedRecordTypeDef;
415
+ export type ArrayDef = LeafArrayDef | RepeatedRecordDef;
416
+ export declare function isRepeatedRecordType(td: AtomicTypeDef): td is RepeatedRecordTypeDef;
417
+ export declare function isRepeatedRecord(fd: FieldDef | QueryFieldDef | StructDef): fd is RepeatedRecordDef;
418
+ export declare function isScalarArrayType(td: AtomicTypeDef): td is LeafArrayTypeDef;
419
+ export declare function isScalarArray(fd: FieldDef | QueryFieldDef | StructDef): fd is LeafArrayDef;
406
420
  export interface ErrorTypeDef {
407
421
  type: 'error';
408
422
  }
@@ -419,10 +433,11 @@ export interface JoinBase {
419
433
  onExpression?: Expr;
420
434
  onCompositeFieldUsage?: CompositeFieldUsage;
421
435
  }
422
- export type Joinable = CompositeSourceDef | TableSourceDef | SQLSourceDef | QuerySourceDef | RecordDef | ArrayDef;
423
- export type JoinFieldDef = JoinBase & Joinable;
436
+ export type Joinable = CompositeSourceDef | TableSourceDef | SQLSourceDef | QuerySourceDef | RepeatedRecordDef | RecordDef | ArrayDef;
437
+ export type JoinFieldDef = Joinable & JoinBase;
424
438
  export declare function isJoinable(sd: StructDef): sd is Joinable;
425
- export declare function isJoined<T extends FieldDef | StructDef>(fd: T): fd is T & Joinable & JoinBase;
439
+ export declare function isJoinedField(fd: FieldDef): fd is JoinFieldDef;
440
+ export declare function isJoined(sd: StructDef): sd is JoinFieldDef;
426
441
  export declare function isJoinedSource(sd: StructDef): sd is SourceDef & JoinBase;
427
442
  export type DateUnit = 'day' | 'week' | 'month' | 'quarter' | 'year';
428
443
  export declare function isDateUnit(str: string): str is DateUnit;
@@ -622,7 +637,6 @@ export declare function isSourceDef(sd: NamedModelObject | FieldDef): sd is Sour
622
637
  export type SourceDef = TableSourceDef | SQLSourceDef | QuerySourceDef | QueryResultDef | FinalizeSourceDef | NestSourceDef | CompositeSourceDef;
623
638
  /** Is this the "FROM" table of a query tree */
624
639
  export declare function isBaseTable(def: StructDef): def is SourceDef;
625
- export declare function isScalarArray(def: FieldDef | StructDef): boolean;
626
640
  export type StructDef = SourceDef | RecordDef | ArrayDef;
627
641
  export type NonAtomicType = Exclude<JoinElementType, 'array' | 'record'> | 'turtle' | 'null' | 'duration' | 'any' | 'regular expression';
628
642
  export interface NonAtomicTypeDef {
@@ -679,11 +693,11 @@ export interface ConnectionDef extends NamedObject {
679
693
  }
680
694
  export type TemporalTypeDef = DateTypeDef | TimestampTypeDef;
681
695
  export type LeafAtomicTypeDef = StringTypeDef | TemporalTypeDef | NumberTypeDef | BooleanTypeDef | JSONTypeDef | NativeUnsupportedTypeDef | ErrorTypeDef;
682
- export type AtomicTypeDef = LeafAtomicTypeDef | ArrayTypeDef | RecordTypeDef;
683
696
  export type LeafAtomicDef = LeafAtomicTypeDef & FieldBase;
684
- export type AtomicFieldDef = AtomicTypeDef & FieldBase;
697
+ export type AtomicTypeDef = LeafAtomicTypeDef | LeafArrayTypeDef | RecordTypeDef | RepeatedRecordTypeDef;
698
+ export type AtomicFieldDef = LeafAtomicDef | LeafArrayDef | RecordDef | RepeatedRecordDef;
685
699
  export declare function isLeafAtomic(fd: FieldDef | QueryFieldDef | AtomicTypeDef): fd is LeafAtomicDef;
686
- export type FieldDef = AtomicFieldDef | JoinFieldDef | TurtleDef;
700
+ export type FieldDef = LeafAtomicDef | JoinFieldDef | TurtleDef;
687
701
  export type FieldDefType = AtomicFieldType | 'turtle' | JoinElementType;
688
702
  export interface RefToField {
689
703
  type: 'fieldref';
@@ -22,8 +22,8 @@
22
22
  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
23
  */
24
24
  Object.defineProperty(exports, "__esModule", { value: true });
25
- exports.isBaseTable = exports.isSourceDef = exports.sourceBase = exports.isSegmentSQL = exports.isIndexSegment = exports.isRawSegment = exports.isSamplingEnable = exports.isSamplingPercent = exports.isSamplingRows = exports.isQuerySegment = exports.isProjectSegment = exports.isPartialSegment = exports.isReduceSegment = exports.structHasErrors = exports.segmentHasErrors = exports.refIsStructDef = exports.isByExpression = exports.isByName = exports.ValueType = exports.isExtractUnit = exports.isTimestampUnit = exports.isDateUnit = exports.isJoinedSource = exports.isJoined = exports.isJoinable = exports.isMatrixOperation = exports.isRepeatedRecord = exports.arrayEachFields = exports.fieldIsIntrinsic = exports.isCastType = exports.canOrderBy = exports.isAtomicFieldType = exports.isTemporalField = exports.hasExpression = exports.maxOfExpressionTypes = exports.maxExpressionType = exports.isExpressionTypeLEQ = exports.expressionIsAnalytic = exports.expressionIsCalculation = exports.expressionInvolvesAggregate = exports.expressionIsUngroupedAggregate = exports.expressionIsAggregate = exports.expressionIsScalar = exports.paramHasValue = exports.isRawCast = exports.mkTemporal = exports.isAsymmetricExpr = exports.exprIsLeaf = exports.exprHasE = exports.exprHasKids = void 0;
26
- exports.TD = exports.isValueDate = exports.isValueTimestamp = exports.isValueBoolean = exports.isValueNumber = exports.isValueString = exports.getAtomicFields = exports.isAtomic = exports.isTurtleDef = exports.getIdentifier = exports.isLeafAtomic = exports.mergeEvalSpaces = exports.isLiteral = exports.isScalarArray = void 0;
25
+ exports.isRawSegment = exports.isSamplingEnable = exports.isSamplingPercent = exports.isSamplingRows = exports.isQuerySegment = exports.isProjectSegment = exports.isPartialSegment = exports.isReduceSegment = exports.structHasErrors = exports.segmentHasErrors = exports.refIsStructDef = exports.isByExpression = exports.isByName = exports.ValueType = exports.isExtractUnit = exports.isTimestampUnit = exports.isDateUnit = exports.isJoinedSource = exports.isJoined = exports.isJoinedField = exports.isJoinable = exports.isMatrixOperation = exports.isScalarArray = exports.isScalarArrayType = exports.isRepeatedRecord = exports.isRepeatedRecordType = exports.mkArrayDef = exports.mkFieldDef = exports.fieldIsIntrinsic = exports.isCastType = exports.canOrderBy = exports.isAtomicFieldType = exports.isTemporalField = exports.hasExpression = exports.maxOfExpressionTypes = exports.maxExpressionType = exports.isExpressionTypeLEQ = exports.expressionIsAnalytic = exports.expressionIsCalculation = exports.expressionInvolvesAggregate = exports.expressionIsUngroupedAggregate = exports.expressionIsAggregate = exports.expressionIsScalar = exports.paramHasValue = exports.isRawCast = exports.mkTemporal = exports.isAsymmetricExpr = exports.exprIsLeaf = exports.exprHasE = exports.exprHasKids = void 0;
26
+ exports.TD = exports.isValueDate = exports.isValueTimestamp = exports.isValueBoolean = exports.isValueNumber = exports.isValueString = exports.getAtomicFields = exports.isAtomic = exports.isTurtleDef = exports.getIdentifier = exports.isLeafAtomic = exports.mergeEvalSpaces = exports.isLiteral = exports.isBaseTable = exports.isSourceDef = exports.sourceBase = exports.isSegmentSQL = exports.isIndexSegment = void 0;
27
27
  function exprHasKids(e) {
28
28
  return 'kids' in e;
29
29
  }
@@ -179,38 +179,87 @@ function fieldIsIntrinsic(f) {
179
179
  return isAtomicFieldType(f.type) && !hasExpression(f);
180
180
  }
181
181
  exports.fieldIsIntrinsic = fieldIsIntrinsic;
182
- function arrayEachFields(arrayOf) {
183
- return [
184
- { ...arrayOf, e: { node: 'field', path: ['value'] }, name: 'each' },
185
- { ...arrayOf, name: 'value' },
186
- ];
187
- }
188
- exports.arrayEachFields = arrayEachFields;
182
+ function mkFieldDef(atd, name, dialect) {
183
+ if (isScalarArrayType(atd)) {
184
+ return mkArrayDef(atd.elementTypeDef, name, dialect);
185
+ }
186
+ if (isRepeatedRecordType(atd)) {
187
+ const { type, fields, elementTypeDef } = atd;
188
+ return { type, fields, elementTypeDef, join: 'many', name, dialect };
189
+ }
190
+ if (atd.type === 'record') {
191
+ const { type, fields } = atd;
192
+ return { type, fields, join: 'one', dialect, name };
193
+ }
194
+ return { ...atd, name };
195
+ }
196
+ exports.mkFieldDef = mkFieldDef;
197
+ function mkArrayDef(ofType, name, dialect) {
198
+ if (ofType.type === 'record') {
199
+ return {
200
+ type: 'array',
201
+ join: 'many',
202
+ name,
203
+ dialect,
204
+ elementTypeDef: { type: 'record_element' },
205
+ fields: ofType.fields,
206
+ };
207
+ }
208
+ const valueEnt = mkFieldDef(ofType, 'value', dialect);
209
+ return {
210
+ type: 'array',
211
+ join: 'many',
212
+ name,
213
+ dialect,
214
+ elementTypeDef: ofType,
215
+ fields: [
216
+ valueEnt,
217
+ { ...valueEnt, name: 'each', e: { node: 'field', path: ['value'] } },
218
+ ],
219
+ };
220
+ }
221
+ exports.mkArrayDef = mkArrayDef;
222
+ function isRepeatedRecordType(td) {
223
+ return td.type === 'array' && td.elementTypeDef.type === 'record_element';
224
+ }
225
+ exports.isRepeatedRecordType = isRepeatedRecordType;
189
226
  function isRepeatedRecord(fd) {
190
227
  return fd.type === 'array' && fd.elementTypeDef.type === 'record_element';
191
228
  }
192
229
  exports.isRepeatedRecord = isRepeatedRecord;
230
+ function isScalarArrayType(td) {
231
+ return td.type === 'array' && td.elementTypeDef.type !== 'record_element';
232
+ }
233
+ exports.isScalarArrayType = isScalarArrayType;
234
+ function isScalarArray(fd) {
235
+ return fd.type === 'array' && fd.elementTypeDef.type !== 'record_element';
236
+ }
237
+ exports.isScalarArray = isScalarArray;
193
238
  function isMatrixOperation(x) {
194
239
  return ['left', 'right', 'full', 'inner'].includes(x);
195
240
  }
196
241
  exports.isMatrixOperation = isMatrixOperation;
197
242
  function isJoinable(sd) {
198
243
  return [
244
+ 'composite',
199
245
  'table',
200
246
  'sql_select',
201
247
  'query_source',
202
248
  'array',
203
249
  'record',
204
- 'composite',
205
250
  ].includes(sd.type);
206
251
  }
207
252
  exports.isJoinable = isJoinable;
208
- function isJoined(fd) {
253
+ function isJoinedField(fd) {
209
254
  return 'join' in fd;
210
255
  }
256
+ exports.isJoinedField = isJoinedField;
257
+ function isJoined(sd) {
258
+ return 'join' in sd;
259
+ }
211
260
  exports.isJoined = isJoined;
212
261
  function isJoinedSource(sd) {
213
- return isSourceDef(sd) && isJoined(sd);
262
+ return isSourceDef(sd) && 'join' in sd;
214
263
  }
215
264
  exports.isJoinedSource = isJoinedSource;
216
265
  function isDateUnit(str) {
@@ -330,7 +379,7 @@ function isSourceDef(sd) {
330
379
  exports.isSourceDef = isSourceDef;
331
380
  /** Is this the "FROM" table of a query tree */
332
381
  function isBaseTable(def) {
333
- if (isJoined(def)) {
382
+ if (isJoinedSource(def)) {
334
383
  return false;
335
384
  }
336
385
  if (isSourceDef(def)) {
@@ -339,10 +388,6 @@ function isBaseTable(def) {
339
388
  return false;
340
389
  }
341
390
  exports.isBaseTable = isBaseTable;
342
- function isScalarArray(def) {
343
- return def.type === 'array' && def.elementTypeDef.type !== 'record_element';
344
- }
345
- exports.isScalarArray = isScalarArray;
346
391
  function isLiteral(evalSpace) {
347
392
  return evalSpace === 'literal';
348
393
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@malloydata/malloy",
3
- "version": "0.0.220-dev241205013400",
3
+ "version": "0.0.220-dev241205182408",
4
4
  "license": "MIT",
5
5
  "exports": {
6
6
  ".": "./dist/index.js",