@malloydata/malloy 0.0.334 → 0.0.335

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.
@@ -61,7 +61,13 @@ const expr_aggregate_function_1 = require("./expr-aggregate-function");
61
61
  class ExprCountDistinct extends expr_aggregate_function_1.ExprAggregateFunction {
62
62
  constructor(expr) {
63
63
  super('distinct', expr);
64
- this.legalChildTypes = [TDU.numberT, TDU.stringT, TDU.dateT, TDU.timestampT];
64
+ this.legalChildTypes = [
65
+ TDU.numberT,
66
+ TDU.stringT,
67
+ TDU.dateT,
68
+ TDU.timestampT,
69
+ TDU.timestamptzT,
70
+ ];
65
71
  }
66
72
  returns(ev) {
67
73
  return {
@@ -77,7 +77,7 @@ class ExprGranularTime extends expression_def_1.ExpressionDef {
77
77
  this.units = units;
78
78
  this.truncate = truncate;
79
79
  this.elementType = 'granularTime';
80
- this.legalChildTypes = [TDU.timestampT, TDU.dateT];
80
+ this.legalChildTypes = [TDU.timestampT, TDU.timestamptzT, TDU.dateT];
81
81
  }
82
82
  granular() {
83
83
  return true;
@@ -61,7 +61,13 @@ const expr_aggregate_function_1 = require("./expr-aggregate-function");
61
61
  class ExprMax extends expr_aggregate_function_1.ExprAggregateFunction {
62
62
  constructor(expr) {
63
63
  super('max', expr);
64
- this.legalChildTypes = [TDU.numberT, TDU.stringT, TDU.dateT, TDU.timestampT];
64
+ this.legalChildTypes = [
65
+ TDU.numberT,
66
+ TDU.stringT,
67
+ TDU.dateT,
68
+ TDU.timestampT,
69
+ TDU.timestamptzT,
70
+ ];
65
71
  }
66
72
  returns(ev) {
67
73
  return ev;
@@ -61,7 +61,13 @@ const expr_aggregate_function_1 = require("./expr-aggregate-function");
61
61
  class ExprMin extends expr_aggregate_function_1.ExprAggregateFunction {
62
62
  constructor(expr) {
63
63
  super('min', expr);
64
- this.legalChildTypes = [TDU.numberT, TDU.stringT, TDU.dateT, TDU.timestampT];
64
+ this.legalChildTypes = [
65
+ TDU.numberT,
66
+ TDU.stringT,
67
+ TDU.dateT,
68
+ TDU.timestampT,
69
+ TDU.timestamptzT,
70
+ ];
65
71
  }
66
72
  returns(ev) {
67
73
  return ev;
@@ -71,7 +71,7 @@ class ForRange extends expression_def_1.ExpressionDef {
71
71
  this.duration = duration;
72
72
  this.timeframe = timeframe;
73
73
  this.elementType = 'forRange';
74
- this.legalChildTypes = [TDU.timestampT, TDU.dateT];
74
+ this.legalChildTypes = [TDU.timestampT, TDU.timestamptzT, TDU.dateT];
75
75
  }
76
76
  apply(fs, op, expr) {
77
77
  const startV = this.from.getExpression(fs);
@@ -233,7 +233,7 @@ function timeCompare(left, lhs, op, rhs) {
233
233
  const lval = willMorphTo(lhs, 'timestamp');
234
234
  const rval = willMorphTo(rhs, 'timestamp');
235
235
  if (lval && rval) {
236
- return { node, kids: { left: lval, right: lval } };
236
+ return { node, kids: { left: lval, right: rval } };
237
237
  }
238
238
  }
239
239
  else {
@@ -1,4 +1,4 @@
1
- import type { DocumentLocation, FieldDef, ModelDef, NamedModelObject, PipeSegment, Query, QueryFieldDef, StructDef, TurtleDef, SourceDef, SQLSourceDef } from '../../model/malloy_types';
1
+ import type { DocumentLocation, FieldDef, ModelDef, NamedModelObject, PipeSegment, Query, QueryFieldDef, StructDef, TurtleDef, SourceDef, TableSourceDef, SQLSourceDef } from '../../model/malloy_types';
2
2
  import { MalloyElement } from '../ast';
3
3
  import type { NameSpace } from '../ast/types/name-space';
4
4
  import type { ModelEntry } from '../ast/types/model-entry';
@@ -17,7 +17,14 @@ export declare function pretty(thing: unknown): string;
17
17
  * @returns prettified printable version
18
18
  */
19
19
  export declare function humanify(value: unknown): string;
20
- export declare const aTableDef: SourceDef;
20
+ export declare const TEST_DIALECT = "duckdb";
21
+ export declare const aTableDef: TableSourceDef;
22
+ export declare const bqTableDef: SourceDef;
23
+ /**
24
+ * A TestTranlator never actually talks to connection, instead uses
25
+ * some mocked schema definitions.
26
+ */
27
+ export declare const mockSchema: TableSourceDef[];
21
28
  /**
22
29
  * When translating partial trees, there will not be a document node
23
30
  * to handle namespace requests, this stands in for document in that case.
@@ -23,7 +23,7 @@
23
23
  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
24
  */
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.BetaExpression = exports.TestTranslator = exports.TestChildTranslator = exports.aTableDef = void 0;
26
+ exports.BetaExpression = exports.TestTranslator = exports.TestChildTranslator = exports.mockSchema = exports.bqTableDef = exports.aTableDef = exports.TEST_DIALECT = void 0;
27
27
  exports.pretty = pretty;
28
28
  exports.humanify = humanify;
29
29
  exports.getExplore = getExplore;
@@ -134,65 +134,85 @@ function humanify(value) {
134
134
  }
135
135
  const intType = { type: 'number', numberType: 'integer' };
136
136
  const bigintType = { type: 'number', numberType: 'bigint' };
137
- const mockSchema = {
138
- 'aTable': {
139
- type: 'table',
140
- name: 'aTable',
141
- dialect: 'standardsql',
142
- tablePath: 'aTable',
143
- connection: 'test',
137
+ // Base fields shared by both duckdb and BigQuery table definitions
138
+ const baseFields = [
139
+ { type: 'string', name: 'astr' },
140
+ { type: 'number', name: 'af', numberType: 'float' },
141
+ { ...intType, name: 'ai' },
142
+ { ...bigintType, name: 'abig' },
143
+ { type: 'date', name: 'ad' },
144
+ { type: 'boolean', name: 'abool' },
145
+ { type: 'timestamp', name: 'ats' },
146
+ { type: 'sql native', name: 'aun' },
147
+ { type: 'sql native', name: 'aweird', rawType: 'weird' },
148
+ {
149
+ type: 'array',
150
+ name: 'astruct',
151
+ elementTypeDef: { type: 'record_element' },
152
+ join: 'many',
144
153
  fields: [
145
- { type: 'string', name: 'astr' },
146
- { type: 'number', name: 'af', numberType: 'float' },
147
- { ...intType, name: 'ai' },
148
- { ...bigintType, name: 'abig' },
149
- { type: 'date', name: 'ad' },
150
- { type: 'boolean', name: 'abool' },
151
- { type: 'timestamp', name: 'ats' },
152
- { type: 'sql native', name: 'aun' },
153
- { type: 'sql native', name: 'aweird', rawType: 'weird' },
154
- {
155
- type: 'array',
156
- name: 'astruct',
157
- elementTypeDef: { type: 'record_element' },
158
- join: 'many',
159
- fields: [
160
- {
161
- name: 'column',
162
- type: 'number',
163
- numberType: 'integer',
164
- },
165
- ],
166
- },
167
154
  {
168
- type: 'record',
169
- name: 'aninline',
170
- fields: [{ ...intType, name: 'column' }],
171
- join: 'one',
172
- matrixOperation: 'left',
155
+ name: 'column',
156
+ type: 'number',
157
+ numberType: 'integer',
173
158
  },
174
- (0, malloy_types_1.mkArrayDef)(intType, 'ais'),
175
159
  ],
176
160
  },
177
- 'malloytest.carriers': {
161
+ {
162
+ type: 'record',
163
+ name: 'aninline',
164
+ fields: [{ ...intType, name: 'column' }],
165
+ join: 'one',
166
+ matrixOperation: 'left',
167
+ },
168
+ (0, malloy_types_1.mkArrayDef)(intType, 'ais'),
169
+ ];
170
+ exports.TEST_DIALECT = 'duckdb';
171
+ exports.aTableDef = {
172
+ type: 'table',
173
+ name: 'aTable',
174
+ dialect: exports.TEST_DIALECT,
175
+ tablePath: 'aTable',
176
+ connection: '_db_',
177
+ fields: [
178
+ ...baseFields,
179
+ { type: 'timestamptz', name: 'atstz' }, // duckdb supports timestamptz
180
+ ],
181
+ };
182
+ // BigQuery-compatible table definition (no timestamptz support)
183
+ exports.bqTableDef = {
184
+ type: 'table',
185
+ name: 'aTable',
186
+ dialect: 'standardsql',
187
+ tablePath: 'aTable',
188
+ connection: '_bq_',
189
+ fields: baseFields,
190
+ };
191
+ /**
192
+ * A TestTranlator never actually talks to connection, instead uses
193
+ * some mocked schema definitions.
194
+ */
195
+ exports.mockSchema = [
196
+ exports.aTableDef,
197
+ exports.bqTableDef,
198
+ {
178
199
  type: 'table',
179
- name: 'malloytest.carriers',
180
- dialect: 'standardsql',
200
+ name: 'carriers',
201
+ dialect: exports.TEST_DIALECT,
181
202
  tablePath: 'malloytest.carriers',
182
- connection: 'bigquery',
203
+ connection: '_db_',
183
204
  fields: [
184
205
  { name: 'code', type: 'string' },
185
206
  { name: 'name', type: 'string' },
186
207
  { name: 'nickname', type: 'string' },
187
208
  ],
188
- as: 'carriers',
189
209
  },
190
- 'malloytest.flights': {
210
+ {
191
211
  type: 'table',
192
- name: 'malloytest.flights',
193
- dialect: 'standardsql',
212
+ name: 'flights',
213
+ dialect: exports.TEST_DIALECT,
194
214
  tablePath: 'malloytest.flights',
195
- connection: 'bigquery',
215
+ connection: '_db_',
196
216
  fields: [
197
217
  { name: 'carrier', type: 'string' },
198
218
  { name: 'origin', type: 'string' },
@@ -211,14 +231,13 @@ const mockSchema = {
211
231
  { name: 'diverted', type: 'string' },
212
232
  { name: 'id2', type: 'number', numberType: 'integer' },
213
233
  ],
214
- as: 'flights',
215
234
  },
216
- 'malloytest.airports': {
235
+ {
217
236
  type: 'table',
218
- name: 'malloytest.airports',
219
- dialect: 'standardsql',
237
+ name: 'airports',
238
+ dialect: exports.TEST_DIALECT,
220
239
  tablePath: 'malloytest.airports',
221
- connection: 'bigquery',
240
+ connection: '_db_',
222
241
  fields: [
223
242
  { name: 'id', type: 'number', numberType: 'integer' },
224
243
  { name: 'code', type: 'string' },
@@ -248,17 +267,11 @@ const mockSchema = {
248
267
  { name: 'cntl_twr', type: 'string' },
249
268
  { name: 'major', type: 'string' },
250
269
  ],
251
- as: 'airports',
252
270
  },
253
- };
254
- exports.aTableDef = mockSchema['aTable'];
271
+ ];
255
272
  const bJoinedIntoA = {
256
- type: 'table',
257
- name: 'aTable',
258
- dialect: 'standardsql',
259
- tablePath: 'aTable',
260
- connection: 'test',
261
- as: 'b',
273
+ ...exports.aTableDef,
274
+ name: 'b',
262
275
  join: 'one',
263
276
  matrixOperation: 'left',
264
277
  onExpression: {
@@ -268,7 +281,6 @@ const bJoinedIntoA = {
268
281
  right: { node: 'field', path: ['b', 'astr'] },
269
282
  },
270
283
  },
271
- fields: exports.aTableDef.fields,
272
284
  };
273
285
  /**
274
286
  * When translating partial trees, there will not be a document node
@@ -323,19 +335,31 @@ class TestTranslator extends parse_malloy_1.MalloyTranslator {
323
335
  this.testSrc = testSrc;
324
336
  this.allDialectsEnabled = true;
325
337
  /*
338
+ * There are two connections:
339
+ * _db_ - duckdb dialect, with the following tables ...
340
+ * aTable, malloytest.carriers, malloytest.flights, malloytest.airports
341
+ * _bq_ - bigquery/standardsql dialect, with one table
342
+ * aTable
343
+ *
344
+ * The "aTable" table is a mocked table with one column of each type.
345
+ * The _bq_ version does not have the timestamptz column, and when
346
+ * DATETIME support is added, the _db_ version will not have that.
347
+ *
326
348
  * All test source files can assume that an import of this
327
-
328
349
  *
329
- * Also the following tables will be available on _db_
330
- * aTable, malloytest.carriers, malloytest.flights, malloytest.airports
350
+ * source:
351
+ * bq_a is _bq_.table('aTable') extend { primary_key: astr }
352
+ * carriers is _db_.table('malloytest.carriers')
353
+ * flights is _db_.table('malloytest.flights')
354
+ * airports is _db_.table('malloytest.airports')
355
+ * a is _db_.table('aTable') extend { primary_key: astr }
356
+ * b is a
357
+ * ab is a extend {
358
+ * join_one: b with astr
359
+ * measure: acount is count()
360
+ * view: aturtle is { group_by: astr; aggregate: acount }
361
+ * }
331
362
  *
332
- * source: a is _db_.table('aTable') extend { primary_key: astr }
333
- * source: b is a
334
- * source: ab is a extend {
335
- * join_one: b with astr
336
- * measure: acount is count()
337
- * query: aturtle is { group_by: astr; aggregate: acount }
338
- * }
339
363
  */
340
364
  this.internalModel = {
341
365
  name: testURI,
@@ -344,8 +368,10 @@ class TestTranslator extends parse_malloy_1.MalloyTranslator {
344
368
  dependencies: {},
345
369
  contents: {
346
370
  _db_: { type: 'connection', name: '_db_' },
347
- a: { ...exports.aTableDef, primaryKey: 'astr', as: 'a' },
348
- b: { ...exports.aTableDef, primaryKey: 'astr', as: 'b' },
371
+ _bq_: { type: 'connection', name: '_bq_' },
372
+ a: { ...exports.aTableDef, primaryKey: 'astr', name: 'a' },
373
+ b: { ...exports.aTableDef, primaryKey: 'astr', name: 'b' },
374
+ bq_a: { ...exports.bqTableDef, primaryKey: 'astr', name: 'bq_a' },
349
375
  ab: {
350
376
  ...exports.aTableDef,
351
377
  primaryKey: 'astr',
@@ -378,7 +404,7 @@ class TestTranslator extends parse_malloy_1.MalloyTranslator {
378
404
  { type: 'string', name: 'acount' },
379
405
  ],
380
406
  connection: 'test',
381
- dialect: 'standardsql',
407
+ dialect: exports.TEST_DIALECT,
382
408
  },
383
409
  isRepeated: true,
384
410
  },
@@ -393,9 +419,8 @@ class TestTranslator extends parse_malloy_1.MalloyTranslator {
393
419
  if (internalModel !== undefined) {
394
420
  this.internalModel = internalModel;
395
421
  }
396
- for (const tableName in mockSchema) {
397
- this.schemaZone.define(tableName, mockSchema[tableName]);
398
- this.schemaZone.define(`_db_:${tableName}`, mockSchema[tableName]);
422
+ for (const actualSchema of exports.mockSchema) {
423
+ this.schemaZone.define(`${actualSchema.connection}:${actualSchema.tablePath}`, actualSchema);
399
424
  }
400
425
  }
401
426
  translate() {
@@ -645,7 +670,7 @@ function getSelectOneStruct(sqlBlock) {
645
670
  [key]: {
646
671
  type: 'sql_select',
647
672
  name: key,
648
- dialect: 'standardsql',
673
+ dialect: exports.TEST_DIALECT,
649
674
  connection: '_db_',
650
675
  selectStr: sqlBlock.selectStr,
651
676
  fields: [{ type: 'number', name: 'one' }],
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const MALLOY_VERSION = "0.0.334";
1
+ export declare const MALLOY_VERSION = "0.0.335";
package/dist/version.js CHANGED
@@ -2,5 +2,5 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.MALLOY_VERSION = void 0;
4
4
  // generated with 'generate-version-file' script; do not edit manually
5
- exports.MALLOY_VERSION = '0.0.334';
5
+ exports.MALLOY_VERSION = '0.0.335';
6
6
  //# sourceMappingURL=version.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@malloydata/malloy",
3
- "version": "0.0.334",
3
+ "version": "0.0.335",
4
4
  "license": "MIT",
5
5
  "exports": {
6
6
  ".": "./dist/index.js",
@@ -45,9 +45,9 @@
45
45
  "generate-version-file": "VERSION=$(npm pkg get version --workspaces=false | tr -d \\\")\necho \"// generated with 'generate-version-file' script; do not edit manually\\nexport const MALLOY_VERSION = '$VERSION';\" > src/version.ts"
46
46
  },
47
47
  "dependencies": {
48
- "@malloydata/malloy-filter": "0.0.334",
49
- "@malloydata/malloy-interfaces": "0.0.334",
50
- "@malloydata/malloy-tag": "0.0.334",
48
+ "@malloydata/malloy-filter": "0.0.335",
49
+ "@malloydata/malloy-interfaces": "0.0.335",
50
+ "@malloydata/malloy-tag": "0.0.335",
51
51
  "antlr4ts": "^0.5.0-alpha.4",
52
52
  "assert": "^2.0.0",
53
53
  "jaro-winkler": "^0.2.8",