@malloydata/malloy-tests 0.0.177-dev240828173040 → 0.0.177-dev240829030921

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.
package/package.json CHANGED
@@ -21,13 +21,13 @@
21
21
  },
22
22
  "dependencies": {
23
23
  "@jest/globals": "^29.4.3",
24
- "@malloydata/db-bigquery": "^0.0.177-dev240828173040",
25
- "@malloydata/db-duckdb": "^0.0.177-dev240828173040",
26
- "@malloydata/db-postgres": "^0.0.177-dev240828173040",
27
- "@malloydata/db-snowflake": "^0.0.177-dev240828173040",
28
- "@malloydata/db-trino": "^0.0.177-dev240828173040",
29
- "@malloydata/malloy": "^0.0.177-dev240828173040",
30
- "@malloydata/render": "^0.0.177-dev240828173040",
24
+ "@malloydata/db-bigquery": "^0.0.177-dev240829030921",
25
+ "@malloydata/db-duckdb": "^0.0.177-dev240829030921",
26
+ "@malloydata/db-postgres": "^0.0.177-dev240829030921",
27
+ "@malloydata/db-snowflake": "^0.0.177-dev240829030921",
28
+ "@malloydata/db-trino": "^0.0.177-dev240829030921",
29
+ "@malloydata/malloy": "^0.0.177-dev240829030921",
30
+ "@malloydata/render": "^0.0.177-dev240829030921",
31
31
  "jsdom": "^22.1.0",
32
32
  "luxon": "^2.4.0",
33
33
  "madge": "^6.0.0"
@@ -36,5 +36,5 @@
36
36
  "@types/jsdom": "^21.1.1",
37
37
  "@types/luxon": "^2.4.0"
38
38
  },
39
- "version": "0.0.177-dev240828173040"
39
+ "version": "0.0.177-dev240829030921"
40
40
  }
@@ -47,11 +47,13 @@ describe('BigQuery hand-built expression test', () => {
47
47
  return {
48
48
  type: 'one',
49
49
  matrixOperation: 'left',
50
- onExpression: [
51
- {type: 'field', path: leftKey},
52
- '=',
53
- {type: 'field', path: rightKey},
54
- ],
50
+ onExpression: {
51
+ node: '=',
52
+ kids: {
53
+ left: {node: 'field', path: leftKey},
54
+ right: {node: 'field', path: rightKey},
55
+ },
56
+ },
55
57
  };
56
58
  }
57
59
 
@@ -114,20 +116,18 @@ describe('BigQuery hand-built expression test', () => {
114
116
  {
115
117
  name: 'model_count',
116
118
  type: 'number',
117
- e: [{type: 'aggregate', function: 'count', e: []}],
119
+ e: {node: 'aggregate', function: 'count', e: {node: ''}},
118
120
  expressionType: 'aggregate',
119
121
  numberType: 'float',
120
122
  },
121
123
  {
122
124
  name: 'total_seats',
123
125
  type: 'number',
124
- e: [
125
- {
126
- type: 'aggregate',
127
- function: 'sum',
128
- e: [{type: 'field', path: ['seats']}],
129
- },
130
- ],
126
+ e: {
127
+ node: 'aggregate',
128
+ function: 'sum',
129
+ e: {node: 'field', path: ['seats']},
130
+ },
131
131
  expressionType: 'aggregate',
132
132
  numberType: 'float',
133
133
  },
@@ -135,43 +135,42 @@ describe('BigQuery hand-built expression test', () => {
135
135
  name: 'boeing_seats',
136
136
  type: 'number',
137
137
  expressionType: 'aggregate',
138
- e: [
139
- {
140
- type: 'filterExpression',
141
- e: [
142
- {
143
- type: 'aggregate',
144
- function: 'sum',
145
- e: [{type: 'field', path: ['seats']}],
146
- },
147
- ],
138
+ e: {
139
+ node: 'filteredExpr',
140
+ kids: {
141
+ e: {
142
+ node: 'aggregate',
143
+ function: 'sum',
144
+ e: {node: 'field', path: ['seats']},
145
+ },
148
146
  filterList: [
149
147
  {
148
+ node: 'filterCondition',
150
149
  expressionType: 'aggregate',
151
150
  code: "manufacturer='BOEING'",
152
- expression: [
153
- {
154
- type: 'field',
155
- path: ['manufacturer'],
151
+ e: {
152
+ node: '=',
153
+ kids: {
154
+ left: {node: 'field', path: ['manufacturer']},
155
+ right: {node: 'stringLiteral', literal: 'BOEING'},
156
156
  },
157
- "='BOEING'",
158
- ],
157
+ },
159
158
  },
160
159
  ],
161
160
  },
162
- ],
161
+ },
163
162
  numberType: 'float',
164
163
  },
165
164
  {
166
165
  name: 'percent_boeing',
167
166
  type: 'number',
168
- e: [
167
+ e: malloy.composeSQLExpr([
169
168
  '(',
170
- {type: 'field', path: ['boeing_seats']},
169
+ {node: 'field', path: ['boeing_seats']},
171
170
  '/',
172
- {type: 'field', path: ['total_seats']},
171
+ {node: 'field', path: ['total_seats']},
173
172
  ')*100',
174
- ],
173
+ ]),
175
174
  expressionType: 'aggregate',
176
175
  numberType: 'float',
177
176
  },
@@ -179,7 +178,11 @@ describe('BigQuery hand-built expression test', () => {
179
178
  name: 'percent_boeing_floor',
180
179
  type: 'number',
181
180
  expressionType: 'aggregate',
182
- e: ['FLOOR(', {type: 'field', path: ['percent_boeing']}, ')'],
181
+ e: malloy.composeSQLExpr([
182
+ 'FLOOR(',
183
+ {node: 'field', path: ['percent_boeing']},
184
+ ')',
185
+ ]),
183
186
  numberType: 'float',
184
187
  },
185
188
  ],
@@ -231,7 +234,7 @@ describe('BigQuery hand-built expression test', () => {
231
234
  {
232
235
  name: 'aircraft_count',
233
236
  type: 'number',
234
- e: [{type: 'aggregate', function: 'count', e: []}],
237
+ e: {node: 'aggregate', function: 'count', e: {node: ''}},
235
238
  expressionType: 'aggregate',
236
239
  numberType: 'float',
237
240
  },
@@ -309,36 +312,30 @@ describe('BigQuery hand-built expression test', () => {
309
312
  name: 'total_seats',
310
313
  type: 'number',
311
314
  expressionType: 'aggregate',
312
- e: [
313
- {
314
- type: 'filterExpression',
315
- e: [
316
- {
317
- type: 'aggregate',
318
- function: 'sum',
319
- e: [
320
- {
321
- type: 'field',
322
- path: ['aircraft_models', 'seats'],
323
- },
324
- ],
325
- },
326
- ],
315
+ e: {
316
+ node: 'filteredExpr',
317
+ kids: {
318
+ e: {
319
+ node: 'aggregate',
320
+ function: 'sum',
321
+ e: {node: 'field', path: ['aircraft_models', 'seats']},
322
+ },
327
323
  filterList: [
328
324
  {
325
+ node: 'filterCondition',
329
326
  expressionType: 'aggregate',
330
327
  code: "manufacturer='BOEING'",
331
- expression: [
328
+ e: malloy.composeSQLExpr([
332
329
  {
333
- type: 'field',
330
+ node: 'field',
334
331
  path: ['aircraft_models', 'manufacturer'],
335
332
  },
336
333
  "='BOEING'",
337
- ],
334
+ ]),
338
335
  },
339
336
  ],
340
337
  },
341
- ],
338
+ },
342
339
  },
343
340
  // {
344
341
  // name: "aircraft_models.total_seats",
@@ -448,12 +445,10 @@ describe('BigQuery hand-built expression test', () => {
448
445
  name: 'total_aircraft',
449
446
  type: 'number',
450
447
  expressionType: 'aggregate',
451
- e: [
452
- {
453
- type: 'exclude',
454
- e: [{type: 'field', path: ['aircraft_count']}],
455
- },
456
- ],
448
+ e: {
449
+ node: 'exclude',
450
+ e: {node: 'field', path: ['aircraft_count']},
451
+ },
457
452
  },
458
453
  ]),
459
454
  },
@@ -501,12 +496,10 @@ describe('BigQuery hand-built expression test', () => {
501
496
  name: 'total_aircraft',
502
497
  type: 'number',
503
498
  expressionType: 'aggregate',
504
- e: [
505
- {
506
- type: 'exclude',
507
- e: [{type: 'field', path: ['aircraft_count']}],
508
- },
509
- ],
499
+ e: {
500
+ node: 'exclude',
501
+ e: {node: 'field', path: ['aircraft_count']},
502
+ },
510
503
  },
511
504
  ]),
512
505
  },
@@ -561,13 +554,11 @@ describe('BigQuery hand-built expression test', () => {
561
554
  {
562
555
  name: 'total_aircraft',
563
556
  type: 'number',
564
- e: [
565
- {
566
- type: 'aggregate',
567
- function: 'sum',
568
- e: [{type: 'field', path: ['aircraft_count']}],
569
- },
570
- ],
557
+ e: {
558
+ node: 'aggregate',
559
+ function: 'sum',
560
+ e: {node: 'field', path: ['aircraft_count']},
561
+ },
571
562
  expressionType: 'aggregate',
572
563
  numberType: 'float',
573
564
  },
@@ -681,34 +672,31 @@ describe('BigQuery hand-built expression test', () => {
681
672
  name: 'boeing_seats',
682
673
  type: 'number',
683
674
  expressionType: 'aggregate',
684
- e: [
685
- {
686
- type: 'filterExpression',
687
- e: [
688
- {
689
- type: 'aggregate',
690
- function: 'sum',
691
- structPath: ['aircraft_models'],
692
- e: [
693
- {type: 'field', path: ['aircraft_models', 'seats']},
694
- ],
695
- },
696
- ],
675
+ e: {
676
+ node: 'filteredExpr',
677
+ kids: {
678
+ e: {
679
+ node: 'aggregate',
680
+ function: 'sum',
681
+ structPath: ['aircraft_models'],
682
+ e: {node: 'field', path: ['aircraft_models', 'seats']},
683
+ },
697
684
  filterList: [
698
685
  {
686
+ node: 'filterCondition',
699
687
  expressionType: 'aggregate',
700
688
  code: "manufacturer='BOEING'",
701
- expression: [
689
+ e: malloy.composeSQLExpr([
702
690
  {
703
- type: 'field',
691
+ node: 'field',
704
692
  path: ['aircraft_models', 'manufacturer'],
705
693
  },
706
694
  "='BOEING'",
707
- ],
695
+ ]),
708
696
  },
709
697
  ],
710
698
  },
711
- ],
699
+ },
712
700
  },
713
701
  ],
714
702
  },
@@ -729,11 +717,11 @@ describe('BigQuery hand-built expression test', () => {
729
717
  structRelationship: {
730
718
  type: 'many',
731
719
  matrixOperation: 'left',
732
- onExpression: [
733
- {type: 'field', path: ['aircraft_model_code']},
720
+ onExpression: malloy.composeSQLExpr([
721
+ {node: 'field', path: ['aircraft_model_code']},
734
722
  '=',
735
- {type: 'field', path: ['aircraft', 'aircraft_model_code']},
736
- ],
723
+ {node: 'field', path: ['aircraft', 'aircraft_model_code']},
724
+ ]),
737
725
  },
738
726
  },
739
727
  ],
@@ -102,13 +102,7 @@ describe('BigQuery expression tests', () => {
102
102
  type: 'number',
103
103
  name: 'route_flights',
104
104
  expressionType: 'aggregate',
105
- e: [
106
- {
107
- type: 'aggregate',
108
- function: 'count',
109
- e: [],
110
- },
111
- ],
105
+ e: {node: 'aggregate', function: 'count', e: {node: ''}},
112
106
  },
113
107
  ]),
114
108
  },
@@ -209,19 +203,17 @@ describe('BigQuery expression tests', () => {
209
203
  type: 'number',
210
204
  name: 'total_distance_ca',
211
205
  expressionType: 'aggregate',
212
- e: [
213
- {
214
- type: 'filterExpression',
206
+ e: {
207
+ node: 'filteredExpr',
208
+ kids: {
215
209
  filterList: [fStringEq('origin.state', 'CA')],
216
- e: [
217
- {
218
- type: 'aggregate',
219
- function: 'sum',
220
- e: [{type: 'field', path: ['distance']}],
221
- },
222
- ],
210
+ e: {
211
+ node: 'aggregate',
212
+ function: 'sum',
213
+ e: {node: 'field', path: ['distance']},
214
+ },
223
215
  },
224
- ],
216
+ },
225
217
  },
226
218
  ],
227
219
  limit: 20,
@@ -280,13 +272,11 @@ describe('BigQuery expression tests', () => {
280
272
  type: 'number',
281
273
  expressionType: 'aggregate',
282
274
  name: 'total_distance',
283
- e: [
284
- {
285
- type: 'aggregate',
286
- function: 'sum',
287
- e: [{type: 'field', path: ['distance']}],
288
- },
289
- ],
275
+ e: {
276
+ node: 'aggregate',
277
+ function: 'sum',
278
+ e: {node: 'field', path: ['distance']},
279
+ },
290
280
  },
291
281
  'aircraft.aircraft_models.total_seats',
292
282
  ]),
@@ -306,11 +296,11 @@ describe('BigQuery expression tests', () => {
306
296
  {
307
297
  type: 'string',
308
298
  name: 'carrier',
309
- e: [
299
+ e: malloy.composeSQLExpr([
310
300
  'UPPER(',
311
- {type: 'field', path: ['carriers', 'nickname']},
301
+ {node: 'field', path: ['carriers', 'nickname']},
312
302
  ')',
313
- ],
303
+ ]),
314
304
  },
315
305
  'flight_count',
316
306
  ]),
@@ -331,13 +321,11 @@ describe('BigQuery expression tests', () => {
331
321
  type: 'number',
332
322
  expressionType: 'aggregate',
333
323
  name: 'total_distance',
334
- e: [
335
- {
336
- type: 'aggregate',
337
- function: 'sum',
338
- e: [{type: 'field', path: ['distance']}],
339
- },
340
- ],
324
+ e: {
325
+ node: 'aggregate',
326
+ function: 'sum',
327
+ e: {node: 'field', path: ['distance']},
328
+ },
341
329
  },
342
330
  ]),
343
331
  type: 'reduce',
@@ -359,19 +347,17 @@ describe('BigQuery expression tests', () => {
359
347
  type: 'number',
360
348
  expressionType: 'aggregate',
361
349
  name: 'total_distance',
362
- e: [
363
- {
364
- type: 'filterExpression',
350
+ e: {
351
+ node: 'filteredExpr',
352
+ kids: {
365
353
  filterList: [fStringEq('origin_code', 'SFO')],
366
- e: [
367
- {
368
- type: 'aggregate',
369
- function: 'sum',
370
- e: [{type: 'field', path: ['distance']}],
371
- },
372
- ],
354
+ e: {
355
+ node: 'aggregate',
356
+ function: 'sum',
357
+ e: {node: 'field', path: ['distance']},
358
+ },
373
359
  },
374
- ],
360
+ },
375
361
  },
376
362
  ]),
377
363
  },
@@ -393,19 +379,17 @@ describe('BigQuery expression tests', () => {
393
379
  type: 'number',
394
380
  expressionType: 'aggregate',
395
381
  name: 'total_distance',
396
- e: [
397
- {
398
- type: 'filterExpression',
382
+ e: {
383
+ node: 'filteredExpr',
384
+ kids: {
399
385
  filterList: [fStringEq('origin_code', 'SFO')],
400
- e: [
401
- {
402
- type: 'aggregate',
403
- function: 'sum',
404
- e: [{type: 'field', path: ['distance']}],
405
- },
406
- ],
386
+ e: {
387
+ node: 'aggregate',
388
+ function: 'sum',
389
+ e: {node: 'field', path: ['distance']},
390
+ },
407
391
  },
408
- ],
392
+ },
409
393
  },
410
394
  ]),
411
395
  filterList: [fStringEq('carriers.code', 'WN')],
@@ -21,7 +21,12 @@
21
21
  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
22
  */
23
23
 
24
- import {ModelDef, StructDef, StructRelationship} from '@malloydata/malloy';
24
+ import {
25
+ composeSQLExpr,
26
+ ModelDef,
27
+ StructDef,
28
+ StructRelationship,
29
+ } from '@malloydata/malloy';
25
30
 
26
31
  import {fStringEq, fToIF, fToQF, fYearEq} from '../util';
27
32
 
@@ -31,11 +36,11 @@ function withJoin(leftKey: string, rightKey: string): StructRelationship {
31
36
  return {
32
37
  type: 'one',
33
38
  matrixOperation: 'left',
34
- onExpression: [
35
- {type: 'field', path: leftKey.split('.')},
39
+ onExpression: composeSQLExpr([
40
+ {node: 'field', path: leftKey.split('.')},
36
41
  '=',
37
- {type: 'field', path: rightKey.split('.')},
38
- ],
42
+ {node: 'field', path: rightKey.split('.')},
43
+ ]),
39
44
  };
40
45
  }
41
46
 
@@ -72,19 +77,17 @@ export const FLIGHTS_EXPLORE: StructDef = {
72
77
  type: 'number',
73
78
  name: 'flight_count',
74
79
  expressionType: 'aggregate',
75
- e: [{type: 'aggregate', function: 'count', e: []}],
80
+ e: {node: 'aggregate', function: 'count', e: {node: ''}},
76
81
  },
77
82
  {
78
83
  type: 'number',
79
84
  name: 'total_distance',
80
85
  expressionType: 'aggregate',
81
- e: [
82
- {
83
- type: 'aggregate',
84
- function: 'sum',
85
- e: [{type: 'field', path: ['distance']}],
86
- },
87
- ],
86
+ e: {
87
+ node: 'aggregate',
88
+ function: 'sum',
89
+ e: {node: 'field', path: ['distance']},
90
+ },
88
91
  },
89
92
 
90
93
  // carriers
@@ -100,11 +103,11 @@ export const FLIGHTS_EXPLORE: StructDef = {
100
103
  structRelationship: {
101
104
  type: 'one',
102
105
  matrixOperation: 'left',
103
- onExpression: [
104
- {type: 'field', path: ['carrier']},
106
+ onExpression: composeSQLExpr([
107
+ {node: 'field', path: ['carrier']},
105
108
  '=',
106
- {type: 'field', path: ['carriers', 'code']},
107
- ],
109
+ {node: 'field', path: ['carriers', 'code']},
110
+ ]),
108
111
  },
109
112
  primaryKey: 'code',
110
113
  fields: [
@@ -164,19 +167,17 @@ export const FLIGHTS_EXPLORE: StructDef = {
164
167
  type: 'number',
165
168
  name: 'aircraft_count',
166
169
  expressionType: 'aggregate',
167
- e: [{type: 'aggregate', function: 'count', e: []}],
170
+ e: {node: 'aggregate', function: 'count', e: {node: ''}},
168
171
  },
169
172
  {
170
173
  type: 'number',
171
174
  name: 'total_engines',
172
175
  expressionType: 'aggregate',
173
- e: [
174
- {
175
- type: 'aggregate',
176
- function: 'sum',
177
- e: [{type: 'field', path: ['aircraft_models', 'engines']}],
178
- },
179
- ],
176
+ e: {
177
+ node: 'aggregate',
178
+ function: 'sum',
179
+ e: {node: 'field', path: ['aircraft_models', 'engines']},
180
+ },
180
181
  },
181
182
 
182
183
  // subjoin aircraft models
@@ -222,13 +223,11 @@ export const FLIGHTS_EXPLORE: StructDef = {
222
223
  type: 'number',
223
224
  expressionType: 'aggregate',
224
225
  name: 'total_seats',
225
- e: [
226
- {
227
- type: 'aggregate',
228
- function: 'sum',
229
- e: [{type: 'field', path: ['seats']}],
230
- },
231
- ],
226
+ e: {
227
+ node: 'aggregate',
228
+ function: 'sum',
229
+ e: {node: 'field', path: ['seats']},
230
+ },
232
231
  },
233
232
  ],
234
233
  },
@@ -279,7 +278,7 @@ export const FLIGHTS_EXPLORE: StructDef = {
279
278
  type: 'number',
280
279
  name: 'count',
281
280
  expressionType: 'aggregate',
282
- e: [{type: 'aggregate', function: 'count', e: []}],
281
+ e: {node: 'aggregate', function: 'count', e: {node: ''}},
283
282
  },
284
283
  ],
285
284
  },
@@ -328,7 +327,7 @@ export const FLIGHTS_EXPLORE: StructDef = {
328
327
  type: 'number',
329
328
  name: 'count',
330
329
  expressionType: 'aggregate',
331
- e: [{type: 'aggregate', function: 'count', e: []}],
330
+ e: {node: 'aggregate', function: 'count', e: {node: ''}},
332
331
  },
333
332
  ],
334
333
  },
@@ -353,13 +352,11 @@ export const FLIGHTS_EXPLORE: StructDef = {
353
352
  type: 'number',
354
353
  name: 'lifetime_distance',
355
354
  expressionType: 'aggregate',
356
- e: [
357
- {
358
- type: 'aggregate',
359
- function: 'sum',
360
- e: [{type: 'field', path: ['distance']}],
361
- },
362
- ],
355
+ e: {
356
+ node: 'aggregate',
357
+ function: 'sum',
358
+ e: {node: 'field', path: ['distance']},
359
+ },
363
360
  },
364
361
  ]),
365
362
  },
@@ -388,26 +385,22 @@ export const FLIGHTS_EXPLORE: StructDef = {
388
385
  type: 'number',
389
386
  name: 'origin_count',
390
387
  expressionType: 'aggregate',
391
- e: [
392
- {
393
- type: 'aggregate',
394
- function: 'count',
395
- e: [],
396
- structPath: ['origin'],
397
- },
398
- ],
388
+ e: {
389
+ node: 'aggregate',
390
+ function: 'count',
391
+ e: {node: ''},
392
+ structPath: ['origin'],
393
+ },
399
394
  },
400
395
  {
401
396
  type: 'number',
402
397
  name: 'my_total_distance',
403
398
  expressionType: 'aggregate',
404
- e: [
405
- {
406
- type: 'aggregate',
407
- function: 'sum',
408
- e: [{type: 'field', path: ['distance']}],
409
- },
410
- ],
399
+ e: {
400
+ node: 'aggregate',
401
+ function: 'sum',
402
+ e: {node: 'field', path: ['distance']},
403
+ },
411
404
  },
412
405
  ]),
413
406
  orderBy: [{field: 'name', dir: 'asc'}],
@@ -427,37 +420,25 @@ export const FLIGHTS_EXPLORE: StructDef = {
427
420
  name: 'flights_2001',
428
421
  type: 'number',
429
422
  expressionType: 'aggregate',
430
- e: [
431
- {
432
- type: 'filterExpression',
423
+ e: {
424
+ node: 'filteredExpr',
425
+ kids: {
433
426
  filterList: [fYearEq('dep_time', 2001)],
434
- e: [
435
- {
436
- type: 'aggregate',
437
- function: 'count',
438
- e: [],
439
- },
440
- ],
427
+ e: {node: 'aggregate', function: 'count', e: {node: ''}},
441
428
  },
442
- ],
429
+ },
443
430
  },
444
431
  {
445
432
  name: 'flights_2002',
446
433
  type: 'number',
447
434
  expressionType: 'aggregate',
448
- e: [
449
- {
450
- type: 'filterExpression',
435
+ e: {
436
+ node: 'filteredExpr',
437
+ kids: {
451
438
  filterList: [fYearEq('dep_time', 2001)],
452
- e: [
453
- {
454
- type: 'aggregate',
455
- function: 'count',
456
- e: [],
457
- },
458
- ],
439
+ e: {node: 'aggregate', function: 'count', e: {node: ''}},
459
440
  },
460
- ],
441
+ },
461
442
  },
462
443
  ]),
463
444
  orderBy: [{field: 'name', dir: 'asc'}],
@@ -511,13 +492,11 @@ export const FLIGHTS_EXPLORE: StructDef = {
511
492
  type: 'number',
512
493
  name: 'lifetime_distance',
513
494
  expressionType: 'aggregate',
514
- e: [
515
- {
516
- type: 'aggregate',
517
- function: 'sum',
518
- e: [{type: 'field', path: ['distance']}],
519
- },
520
- ],
495
+ e: {
496
+ node: 'aggregate',
497
+ function: 'sum',
498
+ e: {node: 'field', path: ['distance']},
499
+ },
521
500
  },
522
501
  ]),
523
502
  },
@@ -720,14 +699,12 @@ export const FLIGHTS_EXPLORE: StructDef = {
720
699
  type: 'number',
721
700
  name: 'origin_count',
722
701
  expressionType: 'aggregate',
723
- e: [
724
- {
725
- type: 'aggregate',
726
- function: 'count',
727
- e: [],
728
- structPath: ['origin'],
729
- },
730
- ],
702
+ e: {
703
+ node: 'aggregate',
704
+ function: 'count',
705
+ e: {node: ''},
706
+ structPath: ['origin'],
707
+ },
731
708
  },
732
709
  ]),
733
710
  orderBy: [{field: 'flight_count', dir: 'desc'}],
@@ -988,7 +965,7 @@ const tableAirports: StructDef = {
988
965
  type: 'number',
989
966
  name: 'count',
990
967
  expressionType: 'aggregate',
991
- e: [{type: 'aggregate', function: 'count', e: []}],
968
+ e: {node: 'aggregate', function: 'count', e: {node: ''}},
992
969
  },
993
970
  ],
994
971
  };
@@ -21,7 +21,7 @@
21
21
  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
22
  */
23
23
 
24
- import {StructDef} from '@malloydata/malloy';
24
+ import {composeSQLExpr, StructDef} from '@malloydata/malloy';
25
25
  import {fToQF} from '../util';
26
26
 
27
27
  // will it build?
@@ -66,25 +66,27 @@ export const medicareModel: StructDef = {
66
66
  type: 'number',
67
67
  name: 'count_of_drugs',
68
68
  expressionType: 'aggregate',
69
- e: [{type: 'aggregate', function: 'count', e: []}],
69
+ e: {node: 'aggregate', function: 'count', e: {node: ''}},
70
70
  },
71
71
  {
72
72
  type: 'number',
73
73
  name: 'provider_count',
74
74
  expressionType: 'aggregate',
75
- e: ['COUNT(DISTINCT ', {type: 'field', path: ['provider_id']}, ')'],
75
+ e: composeSQLExpr([
76
+ 'COUNT(DISTINCT ',
77
+ {node: 'field', path: ['provider_id']},
78
+ ')',
79
+ ]),
76
80
  },
77
81
  {
78
82
  type: 'number',
79
83
  name: 'total_discharges',
80
84
  expressionType: 'aggregate',
81
- e: [
82
- {
83
- type: 'aggregate',
84
- function: 'sum',
85
- e: [{type: 'field', path: ['discharges']}],
86
- },
87
- ],
85
+ e: {
86
+ node: 'aggregate',
87
+ function: 'sum',
88
+ e: {node: 'field', path: ['discharges']},
89
+ },
88
90
  },
89
91
 
90
92
  {
@@ -235,11 +237,11 @@ export const medicareStateFacts: StructDef = {
235
237
  type: 'number',
236
238
  name: 'num_providers',
237
239
  expressionType: 'aggregate',
238
- e: [
240
+ e: composeSQLExpr([
239
241
  'COUNT(DISTINCT ',
240
- {type: 'field', path: ['provider_id']},
242
+ {node: 'field', path: ['provider_id']},
241
243
  ')',
242
- ],
244
+ ]),
243
245
  },
244
246
  ]),
245
247
  type: 'reduce',
package/src/util/index.ts CHANGED
@@ -22,13 +22,14 @@
22
22
  */
23
23
 
24
24
  import {
25
- FilterExpression,
26
- Fragment,
25
+ FilterCondition,
27
26
  QueryFieldDef,
28
27
  IndexFieldDef,
29
28
  QueryMaterializer,
30
29
  Result,
31
30
  Runtime,
31
+ Expr,
32
+ composeSQLExpr,
32
33
  } from '@malloydata/malloy';
33
34
  export * from '@malloydata/malloy/test';
34
35
 
@@ -46,28 +47,43 @@ export function fToIF(fs: string[]): IndexFieldDef[] {
46
47
  );
47
48
  }
48
49
 
49
- export function fStringEq(field: string, value: string): FilterExpression {
50
+ export function fStringEq(field: string, value: string): FilterCondition {
50
51
  return {
51
- expression: [{type: 'field', path: field.split('.')}, `='${value}'`],
52
+ node: 'filterCondition',
53
+ e: {
54
+ node: '=',
55
+ kids: {
56
+ left: {node: 'field', path: field.split('.')},
57
+ right: {node: 'stringLiteral', literal: value},
58
+ },
59
+ },
52
60
  code: `${field}='${value}'`,
53
61
  expressionType: 'scalar',
54
62
  };
55
63
  }
56
64
 
57
- export function fStringLike(field: string, value: string): FilterExpression {
65
+ export function fStringLike(field: string, value: string): FilterCondition {
58
66
  return {
59
- expression: [{type: 'field', path: field.split('.')}, ` LIKE '${value}'`],
67
+ node: 'filterCondition',
68
+ e: {
69
+ node: 'like',
70
+ kids: {
71
+ left: {node: 'field', path: field.split('.')},
72
+ right: {node: 'stringLiteral', literal: value},
73
+ },
74
+ },
60
75
  code: `${field}~'${value}'`,
61
76
  expressionType: 'scalar',
62
77
  };
63
78
  }
64
79
 
65
- export function fYearEq(field: string, year: number): FilterExpression {
80
+ export function fYearEq(field: string, year: number): FilterCondition {
66
81
  const yBegin = `'${year}-01-01 00:00:00'`;
67
82
  const yEnd = `'${year + 1}-01-01 00:00:00'`;
68
- const fx: Fragment = {type: 'field', path: field.split('.')};
83
+ const fx: Expr = {node: 'field', path: field.split('.')};
69
84
  return {
70
- expression: [fx, `>=${yBegin} and `, fx, `<${yEnd}`],
85
+ node: 'filterCondition',
86
+ e: composeSQLExpr([fx, `>=${yBegin} and `, fx, `<${yEnd}`]),
71
87
  code: `${field}:@${year}`,
72
88
  expressionType: 'scalar',
73
89
  };