@malloydata/malloy 0.0.1 → 0.0.3

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 (56) hide show
  1. package/README.md +12 -11
  2. package/dist/dialect/dialect.d.ts +1 -1
  3. package/dist/dialect/dialect.js +13 -0
  4. package/dist/dialect/duckdb.d.ts +1 -1
  5. package/dist/dialect/duckdb.js +35 -37
  6. package/dist/dialect/postgres.d.ts +1 -1
  7. package/dist/dialect/postgres.js +15 -8
  8. package/dist/dialect/standardsql.js +1 -0
  9. package/dist/index.d.ts +4 -4
  10. package/dist/index.js +2 -2
  11. package/dist/lang/ast/apply-expr.d.ts +2 -2
  12. package/dist/lang/ast/apply-expr.js +19 -3
  13. package/dist/lang/ast/ast-expr.d.ts +37 -37
  14. package/dist/lang/ast/ast-expr.js +24 -39
  15. package/dist/lang/ast/ast-main.d.ts +14 -14
  16. package/dist/lang/ast/ast-main.js +36 -45
  17. package/dist/lang/ast/ast-time-expr.d.ts +19 -19
  18. package/dist/lang/ast/ast-time-expr.js +6 -7
  19. package/dist/lang/ast/time-utils.d.ts +1 -0
  20. package/dist/lang/ast/time-utils.js +12 -1
  21. package/dist/lang/field-space.d.ts +43 -41
  22. package/dist/lang/field-space.js +115 -135
  23. package/dist/lang/lib/Malloy/MalloyLexer.d.ts +108 -106
  24. package/dist/lang/lib/Malloy/MalloyLexer.js +1019 -1006
  25. package/dist/lang/lib/Malloy/MalloyParser.d.ts +581 -590
  26. package/dist/lang/lib/Malloy/MalloyParser.js +1141 -1202
  27. package/dist/lang/lib/Malloy/MalloyParserListener.d.ts +2015 -0
  28. package/dist/lang/lib/Malloy/MalloyParserListener.js +4 -0
  29. package/dist/lang/lib/Malloy/MalloyParserVisitor.d.ts +1269 -0
  30. package/dist/lang/lib/Malloy/MalloyParserVisitor.js +4 -0
  31. package/dist/lang/parse-to-ast.d.ts +3 -4
  32. package/dist/lang/parse-to-ast.js +1 -1
  33. package/dist/lang/parse-tree-walkers/document-completion-walker.js +2 -0
  34. package/dist/lang/parse-tree-walkers/explore-query-walker.d.ts +2 -2
  35. package/dist/lang/space-field.d.ts +10 -7
  36. package/dist/lang/space-field.js +11 -4
  37. package/dist/lang/test/field-symbols.spec.js +2 -2
  38. package/dist/lang/test/parse.spec.js +16 -1
  39. package/dist/lang/test/test-translator.js +1 -1
  40. package/dist/malloy.d.ts +1 -1
  41. package/dist/malloy.js +11 -5
  42. package/dist/md5.d.ts +1 -0
  43. package/dist/md5.js +30 -0
  44. package/dist/model/malloy_query.js +10 -6
  45. package/dist/model/malloy_types.d.ts +15 -2
  46. package/package.json +9 -13
  47. package/dist/dialect/dialect-map.d.ts +0 -3
  48. package/dist/dialect/dialect-map.js +0 -33
  49. package/dist/model/malloy-query.d.ts +0 -313
  50. package/dist/model/malloy-query.js +0 -2603
  51. package/dist/model/malloy-types.d.ts +0 -404
  52. package/dist/model/malloy-types.js +0 -242
  53. package/dist/model/sql-block.d.ts +0 -11
  54. package/dist/model/sql-block.js +0 -38
  55. package/dist/runtime-types.d.ts +0 -116
  56. package/dist/runtime-types.js +0 -40
@@ -96,20 +96,10 @@ class ConstantFieldSpace {
96
96
  this.type = "fieldSpace";
97
97
  }
98
98
  structDef() {
99
- return {
100
- type: "struct",
101
- name: "empty structdef",
102
- structSource: { type: "table" },
103
- structRelationship: {
104
- type: "basetable",
105
- connectionName: "noConnection",
106
- },
107
- fields: [],
108
- dialect: "noDialect",
109
- };
99
+ throw new Error("ConstantFieldSpace cannot generate a structDef");
110
100
  }
111
101
  emptyStructDef() {
112
- return { ...this.structDef(), fields: [] };
102
+ throw new Error("ConstantFieldSpace cannot generate a structDef");
113
103
  }
114
104
  lookup(_name) {
115
105
  return {
@@ -117,11 +107,8 @@ class ConstantFieldSpace {
117
107
  found: undefined,
118
108
  };
119
109
  }
120
- getDialect() {
121
- // well dialects totally make this wrong and broken and stupid and useless
122
- // but since this is only used for parameters which are also wrong and
123
- // broken and stupid and useless, this will do for now
124
- throw new Error("I just put this line of code here to make things compile");
110
+ dialectObj() {
111
+ return undefined;
125
112
  }
126
113
  whenComplete(step) {
127
114
  step();
@@ -140,10 +127,7 @@ class ConstantSubExpression extends ExpressionDef {
140
127
  if (!this.cfs) {
141
128
  this.cfs = new ConstantFieldSpace();
142
129
  }
143
- return {
144
- in: this.cfs,
145
- out: this.cfs,
146
- };
130
+ return this.cfs;
147
131
  }
148
132
  constantValue() {
149
133
  return this.expr.getExpression(this.constantFs);
@@ -179,11 +163,7 @@ class FieldDeclaration extends index_1.MalloyElement {
179
163
  * a refactor of QueryFieldSpace might someday be the place where this should
180
164
  * happen.
181
165
  */
182
- const defPair = {
183
- in: new field_space_1.DefSpace(fs, this),
184
- out: fs,
185
- };
186
- return this.queryFieldDef(defPair, exprName);
166
+ return this.queryFieldDef(new field_space_1.DefSpace(fs, this), exprName);
187
167
  }
188
168
  queryFieldDef(exprFS, exprName) {
189
169
  let exprValue;
@@ -391,7 +371,7 @@ class ExprIdReference extends ExpressionDef {
391
371
  return this.fieldReference.refString;
392
372
  }
393
373
  getExpression(fs) {
394
- const def = this.fieldReference.getField(fs.in);
374
+ const def = this.fieldReference.getField(fs);
395
375
  if (def.found) {
396
376
  // TODO if type is a query or a struct this should fail nicely
397
377
  const typeMixin = def.found.type();
@@ -404,7 +384,7 @@ class ExprIdReference extends ExpressionDef {
404
384
  return (0, index_1.errorFor)(def.error);
405
385
  }
406
386
  apply(fs, op, expr) {
407
- const entry = this.fieldReference.getField(fs.in).found;
387
+ const entry = this.fieldReference.getField(fs).found;
408
388
  if (entry instanceof space_field_1.SpaceParam) {
409
389
  const cParam = entry.parameter();
410
390
  if ((0, malloy_types_1.isConditionParameter)(cParam)) {
@@ -548,7 +528,7 @@ class ExprAggregateFunction extends ExpressionDef {
548
528
  let exprVal = (_a = this.expr) === null || _a === void 0 ? void 0 : _a.getExpression(fs);
549
529
  let structPath = (_b = this.source) === null || _b === void 0 ? void 0 : _b.refString;
550
530
  if (this.source) {
551
- const sourceFoot = this.source.getField(fs.in).found;
531
+ const sourceFoot = this.source.getField(fs).found;
552
532
  if (sourceFoot) {
553
533
  const footType = sourceFoot.type();
554
534
  if ((0, malloy_types_1.isAtomicFieldType)(footType.type)) {
@@ -705,19 +685,24 @@ class ExprUngroup extends ExpressionDef {
705
685
  }
706
686
  const ungroup = { type: this.control, e: exprVal.value };
707
687
  if (this.typeCheck(this.expr, { ...exprVal, aggregate: false })) {
708
- const dstFields = [];
709
- for (const mustBeInOutput of this.fields) {
710
- const name = mustBeInOutput.refString;
688
+ if (this.fields.length > 0) {
689
+ let qs = fs;
690
+ if (fs instanceof field_space_1.DefSpace) {
691
+ qs = fs.realFS;
692
+ }
693
+ if (!(qs instanceof field_space_1.QuerySpace)) {
694
+ this.log(`${this.control}() must be in a query -- weird internal error`);
695
+ return (0, index_1.errorFor)("ungroup query check");
696
+ }
697
+ const output = qs.result;
698
+ const dstFields = [];
711
699
  const isExclude = this.control == "exclude";
712
- const resultSpace = fs.out;
713
- if (resultSpace instanceof field_space_1.QuerySpace) {
714
- resultSpace.whenComplete(() => {
715
- resultSpace.checkUngroup(mustBeInOutput, isExclude);
700
+ for (const mustBeInOutput of this.fields) {
701
+ output.whenComplete(() => {
702
+ output.checkUngroup(mustBeInOutput, isExclude);
716
703
  });
717
- dstFields.push(name);
704
+ dstFields.push(mustBeInOutput.refString);
718
705
  }
719
- }
720
- if (dstFields.length > 0) {
721
706
  ungroup.fields = dstFields;
722
707
  }
723
708
  return {
@@ -1,5 +1,5 @@
1
1
  import * as model from "../../model/malloy_types";
2
- import { FieldSpace, FSPair, QuerySpace, LookupResult } from "../field-space";
2
+ import { FieldSpace, QuerySpace, LookupResult } from "../field-space";
3
3
  import { MalloyTranslation } from "../parse-malloy";
4
4
  import { ConstantSubExpression, ExpressionDef, FieldDeclaration } from "./index";
5
5
  import { SQLBlockRequest } from "../../model/sql_block";
@@ -149,7 +149,7 @@ export declare class QuerySource extends Mallobj {
149
149
  export declare abstract class Join extends MalloyElement {
150
150
  abstract name: ModelEntryReference;
151
151
  abstract structDef(): model.StructDef;
152
- abstract fixupJoinOn(outer: FSPair, inStruct: model.StructDef): void;
152
+ abstract fixupJoinOn(outer: FieldSpace, inStruct: model.StructDef): void;
153
153
  }
154
154
  export declare class KeyJoin extends Join {
155
155
  readonly name: ModelEntryReference;
@@ -158,7 +158,7 @@ export declare class KeyJoin extends Join {
158
158
  elementType: string;
159
159
  constructor(name: ModelEntryReference, source: Mallobj, keyExpr: ExpressionDef);
160
160
  structDef(): model.StructDef;
161
- fixupJoinOn(outer: FSPair, inStruct: model.StructDef): void;
161
+ fixupJoinOn(outer: FieldSpace, inStruct: model.StructDef): void;
162
162
  }
163
163
  declare type ExpressionJoinType = "many" | "one" | "cross";
164
164
  export declare class ExpressionJoin extends Join {
@@ -170,7 +170,7 @@ export declare class ExpressionJoin extends Join {
170
170
  constructor(name: ModelEntryReference, source: Mallobj);
171
171
  set joinOn(joinExpr: ExpressionDef | undefined);
172
172
  get joinOn(): ExpressionDef | undefined;
173
- fixupJoinOn(outer: FSPair, inStruct: model.StructDef): model.Expr | undefined;
173
+ fixupJoinOn(outer: FieldSpace, inStruct: model.StructDef): model.Expr | undefined;
174
174
  structDef(): model.StructDef;
175
175
  }
176
176
  export declare class Joins extends ListOf<Join> {
@@ -188,14 +188,14 @@ export declare class FilterElement extends MalloyElement {
188
188
  readonly exprSrc: string;
189
189
  elementType: string;
190
190
  constructor(expr: ExpressionDef, exprSrc: string);
191
- filterExpression(fs: FSPair): model.FilterExpression;
191
+ filterExpression(fs: FieldSpace): model.FilterExpression;
192
192
  }
193
193
  export declare class Filter extends ListOf<FilterElement> {
194
194
  elementType: string;
195
195
  private havingClause?;
196
196
  constructor(elements?: FilterElement[]);
197
197
  set having(isHaving: boolean);
198
- getFilterList(fs: FSPair): model.FilterExpression[];
198
+ getFilterList(fs: FieldSpace): model.FilterExpression[];
199
199
  }
200
200
  export declare class DeclareFields extends ListOf<FieldDeclaration> {
201
201
  constructor(fields: FieldDeclaration[], fieldType?: string);
@@ -215,7 +215,7 @@ export declare class FieldName extends MalloyElement {
215
215
  constructor(name: string);
216
216
  get refString(): string;
217
217
  toString(): string;
218
- getField(fs: FSPair): LookupResult;
218
+ getField(fs: FieldSpace): LookupResult;
219
219
  }
220
220
  export declare class FieldReference extends ListOf<FieldName> {
221
221
  elementType: string;
@@ -303,15 +303,15 @@ export declare class WildcardFieldReference extends MalloyElement {
303
303
  }
304
304
  export declare class OrderBy extends MalloyElement {
305
305
  readonly field: number | FieldName;
306
- readonly dir?: "asc" | "desc" | undefined;
306
+ readonly dir?: "desc" | "asc" | undefined;
307
307
  elementType: string;
308
- constructor(field: number | FieldName, dir?: "asc" | "desc" | undefined);
308
+ constructor(field: number | FieldName, dir?: "desc" | "asc" | undefined);
309
309
  get modelField(): string | number;
310
- getOrderBy(_fs: FSPair): model.OrderBy;
310
+ getOrderBy(_fs: FieldSpace): model.OrderBy;
311
311
  }
312
312
  export declare class Ordering extends ListOf<OrderBy> {
313
313
  constructor(list: OrderBy[]);
314
- getOrderBy(fs: FSPair): model.OrderBy[];
314
+ getOrderBy(fs: FieldSpace): model.OrderBy[];
315
315
  }
316
316
  export declare class Limit extends MalloyElement {
317
317
  readonly limit: number;
@@ -376,8 +376,8 @@ export declare class FullQuery extends TurtleHeadedPipe {
376
376
  export declare class TurtleDecl extends TurtleHeadedPipe {
377
377
  readonly name: string;
378
378
  constructor(name: string);
379
- getPipeline(fs: FSPair): model.Pipeline;
380
- getFieldDef(inSpace: FieldSpace, nestParent: QuerySpace | undefined): model.TurtleDef;
379
+ getPipeline(fs: FieldSpace): model.Pipeline;
380
+ getFieldDef(fs: FieldSpace, nestParent: QuerySpace | undefined): model.TurtleDef;
381
381
  }
382
382
  export declare class NestReference extends FieldReference {
383
383
  readonly name: FieldName;
@@ -422,7 +422,7 @@ export declare class Top extends MalloyElement {
422
422
  readonly by?: TopInit | undefined;
423
423
  elementType: string;
424
424
  constructor(limit: number, by?: TopInit | undefined);
425
- getBy(fs: FSPair): model.By | undefined;
425
+ getBy(fs: FieldSpace): model.By | undefined;
426
426
  }
427
427
  export declare class JSONElement extends MalloyElement {
428
428
  elementType: string;
@@ -55,7 +55,7 @@ const theErrorStruct = {
55
55
  type: "struct",
56
56
  name: "~malformed~",
57
57
  dialect: "~malformed~",
58
- structSource: { type: "table" },
58
+ structSource: { type: "table", tablePath: "//undefined_error_table_path" },
59
59
  structRelationship: {
60
60
  type: "basetable",
61
61
  connectionName: "//undefined_error_connection",
@@ -512,7 +512,7 @@ class RefinedExplore extends Mallobj {
512
512
  fs.addParameters(pList);
513
513
  }
514
514
  if (primaryKey) {
515
- const keyDef = primaryKey.field.getField({ in: fs, out: fs });
515
+ const keyDef = primaryKey.field.getField(fs);
516
516
  if (keyDef.error) {
517
517
  primaryKey.log(keyDef.error);
518
518
  }
@@ -522,7 +522,7 @@ class RefinedExplore extends Mallobj {
522
522
  let moreFilters = false;
523
523
  for (const filter of filters) {
524
524
  for (const el of filter.list) {
525
- const fc = el.filterExpression({ in: fs, out: fs });
525
+ const fc = el.filterExpression(fs);
526
526
  if (fc.aggregate) {
527
527
  el.log("Can't use aggregate computations in top level filters");
528
528
  }
@@ -867,6 +867,7 @@ class ExpressionJoin extends Join {
867
867
  if (sourceDef.structSource.type === "query") {
868
868
  // the name from query does not need to be preserved
869
869
  joinStruct.name = this.name.refString;
870
+ delete joinStruct.as;
870
871
  }
871
872
  else {
872
873
  joinStruct.as = this.name.refString;
@@ -1017,7 +1018,7 @@ class FieldName extends MalloyElement {
1017
1018
  return this.refString;
1018
1019
  }
1019
1020
  getField(fs) {
1020
- return fs.in.lookup([this]);
1021
+ return fs.lookup([this]);
1021
1022
  }
1022
1023
  }
1023
1024
  exports.FieldName = FieldName;
@@ -1100,28 +1101,25 @@ class Aggregate extends ListOf {
1100
1101
  }
1101
1102
  exports.Aggregate = Aggregate;
1102
1103
  class ReduceExecutor {
1103
- constructor(baseFS, out) {
1104
+ constructor(baseFS) {
1104
1105
  this.filters = [];
1105
- this.inputFS = baseFS;
1106
- this.queryFS = out || new field_space_1.ReduceFieldSpace(baseFS);
1106
+ this.resultFS = this.getResultSpace(baseFS);
1107
+ this.inputFS = this.resultFS.exprSpace;
1107
1108
  }
1108
- get qfs() {
1109
- return {
1110
- in: this.queryFS.inputFS(),
1111
- out: this.queryFS,
1112
- };
1109
+ getResultSpace(fs) {
1110
+ return new field_space_1.ReduceFieldSpace(fs);
1113
1111
  }
1114
1112
  execute(qp) {
1115
1113
  if (qp instanceof GroupBy ||
1116
1114
  qp instanceof Aggregate ||
1117
1115
  qp instanceof Nests) {
1118
- this.queryFS.addQueryItems(...qp.list);
1116
+ this.resultFS.addQueryItems(...qp.list);
1119
1117
  }
1120
1118
  else if (isNestedQuery(qp)) {
1121
- this.queryFS.addQueryItems(qp);
1119
+ this.resultFS.addQueryItems(qp);
1122
1120
  }
1123
1121
  else if (qp instanceof Filter) {
1124
- this.filters.push(...qp.getFilterList(this.qfs));
1122
+ this.filters.push(...qp.getFilterList(this.inputFS));
1125
1123
  }
1126
1124
  else if (qp instanceof Top) {
1127
1125
  if (this.limit) {
@@ -1157,7 +1155,7 @@ class ReduceExecutor {
1157
1155
  }
1158
1156
  else if (qp instanceof Joins || qp instanceof DeclareFields) {
1159
1157
  for (const qel of qp.list) {
1160
- this.queryFS.extendSource(qel);
1158
+ this.inputFS.extendSource(qel);
1161
1159
  }
1162
1160
  }
1163
1161
  }
@@ -1179,13 +1177,13 @@ class ReduceExecutor {
1179
1177
  to.limit = this.limit;
1180
1178
  }
1181
1179
  if (this.order instanceof Top) {
1182
- const topBy = this.order.getBy(this.qfs);
1180
+ const topBy = this.order.getBy(this.inputFS);
1183
1181
  if (topBy) {
1184
1182
  to.by = topBy;
1185
1183
  }
1186
1184
  }
1187
1185
  if (this.order instanceof Ordering) {
1188
- to.orderBy = this.order.getOrderBy(this.qfs);
1186
+ to.orderBy = this.order.getOrderBy(this.inputFS);
1189
1187
  }
1190
1188
  const oldFilters = (from === null || from === void 0 ? void 0 : from.filterList) || [];
1191
1189
  if (this.filters.length > 0 && !oldFilters) {
@@ -1202,22 +1200,22 @@ class ReduceExecutor {
1202
1200
  from = fromSeg;
1203
1201
  }
1204
1202
  else {
1205
- this.queryFS.log(`Can't refine reduce with ${fromSeg.type}`);
1203
+ this.inputFS.result.log(`Can't refine reduce with ${fromSeg.type}`);
1206
1204
  return ErrorFactory.reduceSegment;
1207
1205
  }
1208
1206
  }
1209
- const reduceSegment = this.queryFS.getPipeSegment(from);
1207
+ const reduceSegment = this.resultFS.getQuerySegment(from);
1210
1208
  this.refineFrom(from, reduceSegment);
1211
1209
  return reduceSegment;
1212
1210
  }
1213
1211
  }
1214
1212
  class ProjectExecutor extends ReduceExecutor {
1215
- constructor(baseFS) {
1216
- super(baseFS, new field_space_1.ProjectFieldSpace(baseFS));
1213
+ getResultSpace(fs) {
1214
+ return new field_space_1.ProjectFieldSpace(fs);
1217
1215
  }
1218
1216
  execute(qp) {
1219
1217
  if (qp instanceof ProjectStatement) {
1220
- this.queryFS.addMembers(qp.list);
1218
+ this.resultFS.addMembers(qp.list);
1221
1219
  }
1222
1220
  else if ((qp instanceof Filter && qp.elementType === "having") ||
1223
1221
  qp instanceof Measures ||
@@ -1235,30 +1233,24 @@ class ProjectExecutor extends ReduceExecutor {
1235
1233
  from = fromSeg;
1236
1234
  }
1237
1235
  else {
1238
- this.queryFS.log(`Can't refine project with ${fromSeg.type}`);
1236
+ this.resultFS.log(`Can't refine project with ${fromSeg.type}`);
1239
1237
  return ErrorFactory.projectSegment;
1240
1238
  }
1241
1239
  }
1242
- const projectSegment = this.queryFS.getPipeSegment(from);
1240
+ const projectSegment = this.resultFS.getQuerySegment(from);
1243
1241
  this.refineFrom(from, projectSegment);
1244
1242
  return projectSegment;
1245
1243
  }
1246
1244
  }
1247
1245
  class IndexExecutor {
1248
- constructor(baseFS) {
1246
+ constructor(inputFS) {
1249
1247
  this.filters = [];
1250
- this.inputFS = baseFS;
1251
- this.queryFS = new field_space_1.IndexFieldSpace(baseFS);
1252
- }
1253
- get qfs() {
1254
- return {
1255
- in: this.queryFS.inputFS(),
1256
- out: this.queryFS,
1257
- };
1248
+ this.resultFS = new field_space_1.IndexFieldSpace(inputFS);
1249
+ this.inputFS = this.resultFS.exprSpace;
1258
1250
  }
1259
1251
  execute(qp) {
1260
1252
  if (qp instanceof Filter) {
1261
- this.filters.push(...qp.getFilterList(this.qfs));
1253
+ this.filters.push(...qp.getFilterList(this.inputFS));
1262
1254
  }
1263
1255
  else if (qp instanceof Limit) {
1264
1256
  if (this.limit) {
@@ -1267,7 +1259,7 @@ class IndexExecutor {
1267
1259
  this.limit = qp;
1268
1260
  }
1269
1261
  else if (qp instanceof Index) {
1270
- this.queryFS.addMembers(qp.fields.list);
1262
+ this.resultFS.addMembers(qp.fields.list);
1271
1263
  if (qp.weightBy) {
1272
1264
  if (this.indexOn) {
1273
1265
  this.indexOn.log("Ignoring previous BY");
@@ -1284,10 +1276,10 @@ class IndexExecutor {
1284
1276
  }
1285
1277
  finalize(from) {
1286
1278
  if (from && from.type !== "index") {
1287
- this.queryFS.log(`Can't refine index with ${from.type}`);
1279
+ this.resultFS.log(`Can't refine index with ${from.type}`);
1288
1280
  return ErrorFactory.indexSegment;
1289
1281
  }
1290
- const indexSegment = this.queryFS.getPipeSegment(from);
1282
+ const indexSegment = this.resultFS.getPipeSegment(from);
1291
1283
  const oldFilters = (from === null || from === void 0 ? void 0 : from.filterList) || [];
1292
1284
  if (this.filters.length > 0 && !oldFilters) {
1293
1285
  indexSegment.filterList = this.filters;
@@ -1385,9 +1377,9 @@ class QOPDesc extends ListOf {
1385
1377
  getOp(inputFS, forPipeline) {
1386
1378
  const qex = this.getExecutor(inputFS);
1387
1379
  if (forPipeline === null || forPipeline === void 0 ? void 0 : forPipeline.nestedInQuerySpace) {
1388
- qex.queryFS.nestParent = forPipeline.nestedInQuerySpace;
1380
+ qex.inputFS.nestParent = forPipeline.nestedInQuerySpace;
1389
1381
  }
1390
- qex.queryFS.astEl = this;
1382
+ qex.resultFS.astEl = this;
1391
1383
  for (const qp of this.list) {
1392
1384
  qex.execute(qp);
1393
1385
  }
@@ -1724,7 +1716,7 @@ class FullQuery extends TurtleHeadedPipe {
1724
1716
  };
1725
1717
  }
1726
1718
  if (this.turtleName) {
1727
- const { error } = this.turtleName.getField((0, field_space_1.fsPair)(pipeFs));
1719
+ const { error } = this.turtleName.getField(pipeFs);
1728
1720
  if (error)
1729
1721
  this.log(error);
1730
1722
  const name = this.turtleName.refString;
@@ -1769,7 +1761,7 @@ class TurtleDecl extends TurtleHeadedPipe {
1769
1761
  else if (headEnt.found instanceof space_field_1.QueryField) {
1770
1762
  const headDef = headEnt.found.getQueryFieldDef(fs);
1771
1763
  if (isTurtle(headDef)) {
1772
- const newPipe = this.refinePipeline(fs.in, headDef);
1764
+ const newPipe = this.refinePipeline(fs, headDef);
1773
1765
  modelPipe.pipeline = [...newPipe.pipeline];
1774
1766
  reportWrongType = false;
1775
1767
  }
@@ -1781,7 +1773,7 @@ class TurtleDecl extends TurtleHeadedPipe {
1781
1773
  else if (this.headRefinement) {
1782
1774
  throw this.internalError("Can't refine the head of a turtle in its definition");
1783
1775
  }
1784
- let appendInput = fs.in;
1776
+ let appendInput = fs;
1785
1777
  if (modelPipe.pipeline.length > 0) {
1786
1778
  let endStruct = appendInput.structDef();
1787
1779
  for (const existingSeg of modelPipe.pipeline) {
@@ -1793,8 +1785,7 @@ class TurtleDecl extends TurtleHeadedPipe {
1793
1785
  modelPipe.pipeline = appended.opList;
1794
1786
  return modelPipe;
1795
1787
  }
1796
- getFieldDef(inSpace, nestParent) {
1797
- const fs = (0, field_space_1.fsPair)(inSpace);
1788
+ getFieldDef(fs, nestParent) {
1798
1789
  if (nestParent) {
1799
1790
  this.nestedInQuerySpace = nestParent;
1800
1791
  }
@@ -1,5 +1,5 @@
1
1
  import { TimestampUnit, ExtractUnit, TimeFieldType } from "../../model/malloy_types";
2
- import { FSPair } from "../field-space";
2
+ import { FieldSpace } from "../field-space";
3
3
  import { ExpressionDef, BinaryBoolean, ExprValue, MalloyElement, Comparison } from "./index";
4
4
  export declare class Timeframe extends MalloyElement {
5
5
  elementType: string;
@@ -21,10 +21,10 @@ export declare class ExprGranularTime extends ExpressionDef {
21
21
  legalChildTypes: import("./ast-types").FragType[];
22
22
  constructor(expr: ExpressionDef, units: TimestampUnit, truncate: boolean);
23
23
  granular(): boolean;
24
- getExpression(fs: FSPair): ExprValue;
25
- apply(fs: FSPair, op: string, left: ExpressionDef): ExprValue;
26
- protected timestampRange(fs: FSPair, op: string, expr: ExpressionDef): ExprValue;
27
- protected dateRange(fs: FSPair, op: string, expr: ExpressionDef): ExprValue;
24
+ getExpression(fs: FieldSpace): ExprValue;
25
+ apply(fs: FieldSpace, op: string, left: ExpressionDef): ExprValue;
26
+ protected timestampRange(fs: FieldSpace, op: string, expr: ExpressionDef): ExprValue;
27
+ protected dateRange(fs: FieldSpace, op: string, expr: ExpressionDef): ExprValue;
28
28
  }
29
29
  /**
30
30
  * GranularTime made from a literal. Funky because it doesn't know if it
@@ -39,12 +39,12 @@ export declare class GranularLiteral extends ExpressionDef {
39
39
  constructor(moment: string, until: string, units: TimestampUnit);
40
40
  granular(): boolean;
41
41
  static parse(possibleLiteral: string): GranularLiteral | undefined;
42
- apply(fs: FSPair, op: string, left: ExpressionDef): ExprValue;
43
- getExpression(fs: FSPair): ExprValue;
42
+ apply(fs: FieldSpace, op: string, left: ExpressionDef): ExprValue;
43
+ getExpression(_fs: FieldSpace): ExprValue;
44
44
  }
45
45
  export declare class ExprNow extends ExpressionDef {
46
46
  elementType: string;
47
- getExpression(_fs: FSPair): ExprValue;
47
+ getExpression(_fs: FieldSpace): ExprValue;
48
48
  }
49
49
  export declare class ExprDuration extends ExpressionDef {
50
50
  readonly n: ExpressionDef;
@@ -52,13 +52,13 @@ export declare class ExprDuration extends ExpressionDef {
52
52
  elementType: string;
53
53
  legalChildTypes: import("./ast-types").FragType[];
54
54
  constructor(n: ExpressionDef, timeframe: TimestampUnit);
55
- apply(fs: FSPair, op: string, left: ExpressionDef): ExprValue;
56
- getExpression(_fs: FSPair): ExprValue;
55
+ apply(fs: FieldSpace, op: string, left: ExpressionDef): ExprValue;
56
+ getExpression(_fs: FieldSpace): ExprValue;
57
57
  }
58
58
  export declare class ExprCompare extends BinaryBoolean<Comparison> {
59
59
  elementType: string;
60
60
  constructor(left: ExpressionDef, op: Comparison, right: ExpressionDef);
61
- getExpression(fs: FSPair): ExprValue;
61
+ getExpression(fs: FieldSpace): ExprValue;
62
62
  }
63
63
  export declare class Apply extends ExprCompare {
64
64
  readonly left: ExpressionDef;
@@ -72,9 +72,9 @@ export declare class PartialCompare extends ExpressionDef {
72
72
  elementType: string;
73
73
  constructor(op: Comparison, right: ExpressionDef);
74
74
  granular(): boolean;
75
- apply(fs: FSPair, op: string, expr: ExpressionDef): ExprValue;
76
- requestExpression(_fs: FSPair): ExprValue | undefined;
77
- getExpression(_fs: FSPair): ExprValue;
75
+ apply(fs: FieldSpace, op: string, expr: ExpressionDef): ExprValue;
76
+ requestExpression(_fs: FieldSpace): ExprValue | undefined;
77
+ getExpression(_fs: FieldSpace): ExprValue;
78
78
  }
79
79
  /**
80
80
  * TODO: This is sort of a hand clone of the "Range" class, they should
@@ -87,9 +87,9 @@ export declare class ForRange extends ExpressionDef {
87
87
  elementType: string;
88
88
  legalChildTypes: import("./ast-types").FragType[];
89
89
  constructor(from: ExpressionDef, duration: ExpressionDef, timeframe: Timeframe);
90
- apply(fs: FSPair, op: string, expr: ExpressionDef): ExprValue;
91
- requestExpression(_fs: FSPair): ExprValue | undefined;
92
- getExpression(_fs: FSPair): ExprValue;
90
+ apply(fs: FieldSpace, op: string, expr: ExpressionDef): ExprValue;
91
+ requestExpression(_fs: FieldSpace): ExprValue | undefined;
92
+ getExpression(_fs: FieldSpace): ExprValue;
93
93
  }
94
94
  export declare class ExprTimeExtract extends ExpressionDef {
95
95
  readonly extractText: string;
@@ -98,12 +98,12 @@ export declare class ExprTimeExtract extends ExpressionDef {
98
98
  static pluralMap: Record<string, ExtractUnit>;
99
99
  static extractor(funcName: string): ExtractUnit | undefined;
100
100
  constructor(extractText: string, args: ExpressionDef[]);
101
- getExpression(fs: FSPair): ExprValue;
101
+ getExpression(fs: FieldSpace): ExprValue;
102
102
  }
103
103
  export declare class ExprFunc extends ExpressionDef {
104
104
  readonly name: string;
105
105
  readonly args: ExpressionDef[];
106
106
  elementType: string;
107
107
  constructor(name: string, args: ExpressionDef[]);
108
- getExpression(fs: FSPair): ExprValue;
108
+ getExpression(fs: FieldSpace): ExprValue;
109
109
  }
@@ -197,18 +197,17 @@ class GranularLiteral extends index_1.ExpressionDef {
197
197
  if (lhs.dataType === "date" && !this.timeType) {
198
198
  rangeType = "date";
199
199
  }
200
- const dialect = fs.in.getDialect();
201
- const range = new index_1.Range(new index_1.ExprTime(rangeType, dialect.sqlLiteralTime(this.moment, rangeType, "UTC")), new index_1.ExprTime(rangeType, dialect.sqlLiteralTime(this.until, rangeType, "UTC")));
200
+ const range = new index_1.Range(new index_1.ExprTime(rangeType, (0, index_1.timeLiteral)(this.moment, rangeType, "UTC")), new index_1.ExprTime(rangeType, (0, index_1.timeLiteral)(this.until, rangeType, "UTC")));
202
201
  return range.apply(fs, op, left);
203
202
  }
204
203
  return super.apply(fs, op, left);
205
204
  }
206
- getExpression(fs) {
205
+ getExpression(_fs) {
207
206
  const dataType = this.timeType || "date";
208
207
  const value = {
209
208
  dataType,
210
209
  aggregate: false,
211
- value: [fs.in.getDialect().sqlLiteralTime(this.moment, dataType, "UTC")],
210
+ value: (0, index_1.timeLiteral)(this.moment, dataType, "UTC"),
212
211
  };
213
212
  // Literals with date resolution can be used as timestamps or dates,
214
213
  // this is the third attempt to make that work. It still feels like
@@ -519,7 +518,7 @@ class ExprFunc extends index_1.ExpressionDef {
519
518
  this.elementType = "function call()";
520
519
  }
521
520
  getExpression(fs) {
522
- var _a, _b;
521
+ var _a, _b, _c;
523
522
  let anyAggregate = false;
524
523
  let collectType;
525
524
  const funcCall = [`${this.name}(`];
@@ -537,8 +536,8 @@ class ExprFunc extends index_1.ExpressionDef {
537
536
  funcCall.push(...expr.value);
538
537
  }
539
538
  funcCall.push(")");
540
- const funcInfo = fs.in.getDialect().getFunctionInfo(this.name);
541
- const dataType = (_b = (_a = funcInfo === null || funcInfo === void 0 ? void 0 : funcInfo.returnType) !== null && _a !== void 0 ? _a : collectType) !== null && _b !== void 0 ? _b : "number";
539
+ const dialect = fs.dialectObj();
540
+ const dataType = (_c = (_b = (_a = dialect === null || dialect === void 0 ? void 0 : dialect.getFunctionInfo(this.name)) === null || _a === void 0 ? void 0 : _a.returnType) !== null && _b !== void 0 ? _b : collectType) !== null && _c !== void 0 ? _c : "number";
542
541
  return {
543
542
  dataType: dataType,
544
543
  aggregate: anyAggregate,
@@ -6,3 +6,4 @@ export declare function castTimestampToDate(from: Expr, safe?: boolean): Expr;
6
6
  export declare function castDateToTimestamp(from: Expr, safe?: boolean): Expr;
7
7
  export declare function resolution(timeframe: string): TimeFieldType;
8
8
  export declare function timeResult(t: TimeResult, tt: TimestampUnit | undefined): TimeResult | GranularResult;
9
+ export declare function timeLiteral(literalStr: string, timeType: TimeFieldType, tz: string): Expr;
@@ -12,7 +12,7 @@
12
12
  * GNU General Public License for more details.
13
13
  */
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.timeResult = exports.resolution = exports.castDateToTimestamp = exports.castTimestampToDate = exports.castTo = exports.timeOffset = void 0;
15
+ exports.timeLiteral = exports.timeResult = exports.resolution = exports.castDateToTimestamp = exports.castTimestampToDate = exports.castTo = exports.timeOffset = void 0;
16
16
  function timeOffset(timeType, from, op, n, timeframe) {
17
17
  return [
18
18
  {
@@ -80,4 +80,15 @@ function timeResult(t, tt) {
80
80
  return t;
81
81
  }
82
82
  exports.timeResult = timeResult;
83
+ function timeLiteral(literalStr, timeType, tz) {
84
+ const fragment = {
85
+ type: "dialect",
86
+ function: "timeLiteral",
87
+ literal: literalStr,
88
+ literalType: timeType,
89
+ timezone: tz,
90
+ };
91
+ return [fragment];
92
+ }
93
+ exports.timeLiteral = timeLiteral;
83
94
  //# sourceMappingURL=time-utils.js.map