@malloydata/malloy-tests 0.0.68-dev230808000650 → 0.0.68

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 (81) hide show
  1. package/dist/databases/all/db_index.spec.d.ts +1 -0
  2. package/dist/databases/all/db_index.spec.js +36 -0
  3. package/dist/databases/all/db_index.spec.js.map +1 -0
  4. package/dist/databases/all/expr.spec.d.ts +0 -2
  5. package/dist/databases/all/expr.spec.js +2 -547
  6. package/dist/databases/all/expr.spec.js.map +1 -1
  7. package/dist/databases/all/functions.spec.d.ts +1 -2
  8. package/dist/databases/all/functions.spec.js +2 -751
  9. package/dist/databases/all/functions.spec.js.map +1 -1
  10. package/dist/databases/all/join.spec.d.ts +1 -2
  11. package/dist/databases/all/join.spec.js +2 -276
  12. package/dist/databases/all/join.spec.js.map +1 -1
  13. package/dist/databases/all/nomodel.spec.d.ts +1 -2
  14. package/dist/databases/all/nomodel.spec.js +2 -923
  15. package/dist/databases/all/nomodel.spec.js.map +1 -1
  16. package/dist/databases/all/orderby.spec.d.ts +1 -2
  17. package/dist/databases/all/orderby.spec.js +2 -191
  18. package/dist/databases/all/orderby.spec.js.map +1 -1
  19. package/dist/databases/all/problems.spec.d.ts +1 -2
  20. package/dist/databases/all/problems.spec.js +2 -80
  21. package/dist/databases/all/problems.spec.js.map +1 -1
  22. package/dist/databases/all/sql_expressions.spec.d.ts +1 -2
  23. package/dist/databases/all/sql_expressions.spec.js +2 -62
  24. package/dist/databases/all/sql_expressions.spec.js.map +1 -1
  25. package/dist/databases/all/time.spec.d.ts +1 -3
  26. package/dist/databases/all/time.spec.js +2 -615
  27. package/dist/databases/all/time.spec.js.map +1 -1
  28. package/dist/databases/{all/index.spec.d.ts → shared/db_index.d.ts} +1 -0
  29. package/dist/databases/{all/index.spec.js → shared/db_index.js} +2 -33
  30. package/dist/databases/shared/db_index.js.map +1 -0
  31. package/dist/databases/shared/expr.d.ts +3 -0
  32. package/dist/databases/shared/expr.js +551 -0
  33. package/dist/databases/shared/expr.js.map +1 -0
  34. package/dist/databases/shared/functions.d.ts +3 -0
  35. package/dist/databases/shared/functions.js +754 -0
  36. package/dist/databases/shared/functions.js.map +1 -0
  37. package/dist/databases/shared/join.d.ts +3 -0
  38. package/dist/databases/shared/join.js +302 -0
  39. package/dist/databases/shared/join.js.map +1 -0
  40. package/dist/databases/shared/nomodel.d.ts +3 -0
  41. package/dist/databases/shared/nomodel.js +950 -0
  42. package/dist/databases/shared/nomodel.js.map +1 -0
  43. package/dist/databases/shared/orderby.d.ts +3 -0
  44. package/dist/databases/shared/orderby.js +217 -0
  45. package/dist/databases/shared/orderby.js.map +1 -0
  46. package/dist/databases/shared/problems.d.ts +3 -0
  47. package/dist/databases/shared/problems.js +106 -0
  48. package/dist/databases/shared/problems.js.map +1 -0
  49. package/dist/databases/shared/sql_expressions.d.ts +3 -0
  50. package/dist/databases/shared/sql_expressions.js +88 -0
  51. package/dist/databases/shared/sql_expressions.js.map +1 -0
  52. package/dist/databases/shared/test_list.js +18 -18
  53. package/dist/databases/shared/test_list.js.map +1 -1
  54. package/dist/databases/shared/time.d.ts +3 -0
  55. package/dist/databases/shared/time.js +640 -0
  56. package/dist/databases/shared/time.js.map +1 -0
  57. package/dist/index.d.ts +9 -10
  58. package/dist/index.js +19 -21
  59. package/dist/index.js.map +1 -1
  60. package/package.json +6 -6
  61. package/src/databases/all/db_index.spec.ts +37 -0
  62. package/src/databases/all/expr.spec.ts +2 -670
  63. package/src/databases/all/functions.spec.ts +1 -1101
  64. package/src/databases/all/join.spec.ts +1 -315
  65. package/src/databases/all/nomodel.spec.ts +2 -1124
  66. package/src/databases/all/orderby.spec.ts +1 -234
  67. package/src/databases/all/problems.spec.ts +1 -87
  68. package/src/databases/all/sql_expressions.spec.ts +1 -71
  69. package/src/databases/all/time.spec.ts +1 -761
  70. package/src/databases/{all/index.spec.ts → shared/db_index.ts} +2 -13
  71. package/src/databases/shared/expr.ts +695 -0
  72. package/src/databases/shared/functions.ts +1126 -0
  73. package/src/databases/shared/join.ts +340 -0
  74. package/src/databases/shared/nomodel.ts +1150 -0
  75. package/src/databases/shared/orderby.ts +260 -0
  76. package/src/databases/shared/problems.ts +113 -0
  77. package/src/databases/shared/sql_expressions.ts +96 -0
  78. package/src/databases/shared/test_list.ts +9 -9
  79. package/src/databases/shared/time.ts +786 -0
  80. package/src/index.ts +10 -11
  81. package/dist/databases/all/index.spec.js.map +0 -1
@@ -23,935 +23,14 @@
23
23
  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
24
  */
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.noModelSharedTests = void 0;
27
26
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
28
27
  const runtimes_1 = require("../../runtimes");
29
28
  const util_1 = require("../../util");
30
- // No prebuilt shared model, each test is complete. Makes debugging easier.
31
- const noModelSharedTests = (runtimes, splitFunction) => {
32
- function rootDbPath(databaseName) {
33
- return databaseName === 'bigquery' ? 'malloy-data.' : '';
34
- }
35
- // TODO: Figure out how to generalize this.
36
- function getSplitFunction(db) {
37
- return (splitFunction !== null && splitFunction !== void 0 ? splitFunction : {
38
- 'bigquery': (column, splitChar) => `split(${column}, '${splitChar}')`,
39
- 'postgres': (column, splitChar) => `string_to_array(${column}, '${splitChar}')`,
40
- 'duckdb': (column, splitChar) => `string_to_array(${column}, '${splitChar}')`,
41
- 'duckdb_wasm': (column, splitChar) => `string_to_array(${column}, '${splitChar}')`,
42
- }[db]);
43
- }
44
- afterAll(async () => {
45
- await runtimes.closeAll();
46
- });
47
- runtimes.runtimeMap.forEach((runtime, databaseName) => {
48
- // Issue: #151
49
- it(`unknown dialect - ${databaseName}`, async () => {
50
- const result = await runtime
51
- .loadQuery(`
52
- query: q is table('malloytest.aircraft')->{
53
- where: state != null
54
- group_by: state
55
- }
56
-
57
- source: r is from(->q){
58
- query: foo is {
59
- order_by: 1 desc
60
- group_by: state
61
- }
62
- }
63
-
64
- query: r->foo
65
- `)
66
- .run();
67
- // console.log(result.data.toObject());
68
- expect(result.data.path(0, 'state').value).toBe('WY');
69
- });
70
- // Issue #149
71
- it(`refine query from query - ${databaseName}`, async () => {
72
- const result = await runtime
73
- .loadQuery(`
74
- query: from(
75
- table('malloytest.state_facts')->{group_by: state; order_by: 1 desc; limit: 1}
76
- )
77
- {
78
- dimension: lower_state is lower(state)
79
- }
80
- -> {project: lower_state}
81
- `)
82
- .run();
83
- // console.log(result.data.toObject());
84
- expect(result.data.path(0, 'lower_state').value).toBe('wy');
85
- });
86
- // issue #157
87
- it(`source- not -found - ${databaseName}`, async () => {
88
- // console.log(result.data.toObject());
89
- let error;
90
- try {
91
- await runtime
92
- .loadQuery(`
93
- source: foo is table('malloytest.state_facts'){primary_key: state}
94
- query: foox->{aggregate: c is count()}
95
- `)
96
- .run();
97
- }
98
- catch (e) {
99
- error = e;
100
- }
101
- expect(error.toString()).not.toContain('Unknown Dialect');
102
- });
103
- it(`join_many - ${databaseName}`, async () => {
104
- const result = await runtime
105
- .loadQuery(`
106
- source: a is table('malloytest.aircraft'){
107
- measure: avg_year is floor(avg(year_built))
108
- }
109
- source: m is table('malloytest.aircraft_models'){
110
- join_many: a on a.aircraft_model_code=aircraft_model_code
111
- measure: avg_seats is floor(avg(seats))
112
- }
113
- query: m->{aggregate: avg_seats, a.avg_year}
114
- `)
115
- .run();
116
- expect(result.data.value[0]['avg_year']).toBe(1969);
117
- expect(result.data.value[0]['avg_seats']).toBe(7);
118
- });
119
- it(`join_many condition no primary key - ${databaseName}`, async () => {
120
- const result = await runtime
121
- .loadQuery(`
122
- source: a is table('malloytest.airports'){}
123
- source: b is table('malloytest.state_facts') {
124
- join_many: a on state=a.state
125
- }
126
- query: b->{aggregate: c is airport_count.sum()}
127
- `)
128
- .run();
129
- expect(result.data.value[0]['c']).toBe(19701);
130
- });
131
- it(`join_many filter multiple values - ${databaseName}`, async () => {
132
- const result = await runtime
133
- .loadQuery(`
134
- source: a is table('malloytest.airports'){
135
- where: state = 'NH' | 'CA'
136
- }
137
- source: b is table('malloytest.state_facts') {
138
- join_many: a on state=a.state
139
- }
140
- query: b->{
141
- aggregate: c is airport_count.sum()
142
- group_by: a.state
143
- }
144
- `)
145
- .run();
146
- expect(result.data.value[0]['c']).toBe(18605);
147
- expect(result.data.value[0]['state']).toBeNull();
148
- expect(result.data.value[1]['c']).toBe(984);
149
- expect(result.data.value[1]['state']).toBe('CA');
150
- expect(result.data.value[2]['c']).toBe(112);
151
- expect(result.data.value[2]['state']).toBe('NH');
152
- });
153
- it(`join_one condition no primary key - ${databaseName}`, async () => {
154
- const result = await runtime
155
- .loadQuery(`
156
- source: a is table('malloytest.state_facts'){}
157
- source: b is table('malloytest.airports') {
158
- join_one: a on state=a.state
159
- }
160
- query: b->{aggregate: c is a.airport_count.sum()}
161
-
162
- `)
163
- .run();
164
- expect(result.data.value[0]['c']).toBe(19701);
165
- });
166
- it(`join_one filter multiple values - ${databaseName}`, async () => {
167
- const result = await runtime
168
- .loadQuery(`
169
- source: a is table('malloytest.state_facts'){
170
- where: state = 'TX' | 'LA'
171
- }
172
- source: b is table('malloytest.airports') {
173
- join_one: a on state=a.state
174
- }
175
- query: b->{
176
- aggregate: c is a.airport_count.sum()
177
- group_by: a.state
178
- }
179
- `)
180
- .run();
181
- // https://github.com/malloydata/malloy/pull/501#discussion_r861022857
182
- expect(result.data.value).toHaveLength(3);
183
- expect(result.data.value).toContainEqual({ c: 1845, state: 'TX' });
184
- expect(result.data.value).toContainEqual({ c: 500, state: 'LA' });
185
- expect(result.data.value).toContainEqual({ c: 0, state: null });
186
- });
187
- it(`join_many cross from - ${databaseName}`, async () => {
188
- // a cross join produces a Many to Many result.
189
- // symmetric aggregate are needed on both sides of the join
190
- // Check the row count and that sums on each side work properly.
191
- const result = await runtime
192
- .loadQuery(`
193
- source: a is table('malloytest.state_facts')
194
- source: f is a{
195
- join_cross: a
196
- }
197
- query: f->{
198
- aggregate:
199
- row_count is count(distinct concat(state,a.state))
200
- left_count is count()
201
- right_count is a.count()
202
- left_sum is airport_count.sum()
203
- right_sum is a.airport_count.sum()
204
- }
205
- `)
206
- .run();
207
- expect(result.data.value[0]['row_count']).toBe(51 * 51);
208
- expect(result.data.value[0]['left_sum']).toBe(19701);
209
- expect(result.data.value[0]['right_sum']).toBe(19701);
210
- });
211
- it(`join_one only - ${databaseName}`, async () => {
212
- // a cross join produces a Many to Many result.
213
- // symmetric aggregate are needed on both sides of the join
214
- // Check the row count and that sums on each side work properly.
215
- const result = await runtime
216
- .loadQuery(`
217
- query: q is table('malloytest.state_facts')->{
218
- aggregate: r is airport_count.sum()
219
- }
220
- source: f is table('malloytest.state_facts'){
221
- join_one: a is from(->q)
222
- }
223
- query: f->{
224
- aggregate:
225
- row_count is count(distinct concat(state,a.r))
226
- left_sum is airport_count.sum()
227
- right_sum is a.r.sum()
228
- sum_sum is sum(airport_count + a.r)
229
- }
230
- `)
231
- .run();
232
- expect(result.data.value[0]['row_count']).toBe(51);
233
- expect(result.data.value[0]['left_sum']).toBe(19701);
234
- expect(result.data.value[0]['right_sum']).toBe(19701);
235
- expect(result.data.value[0]['sum_sum']).toBe(19701 + 51 * 19701);
236
- });
237
- it(`join_many cross ON - ${databaseName}`, async () => {
238
- // a cross join produces a Many to Many result.
239
- // symmetric aggregate are needed on both sides of the join
240
- // Check the row count and that sums on each side work properly.
241
- const result = await runtime
242
- .loadQuery(`
243
- source: a is table('malloytest.state_facts')
244
- source: f is a{
245
- join_cross: a on a.state = 'CA' | 'NY'
246
- }
247
- query: f->{
248
- aggregate:
249
- row_count is count(distinct concat(state,a.state))
250
- left_sum is airport_count.sum()
251
- right_sum is a.airport_count.sum()
252
- }
253
- `)
254
- .run();
255
- expect(result.data.value[0]['row_count']).toBe(51 * 2);
256
- expect(result.data.value[0]['left_sum']).toBe(19701);
257
- expect(result.data.value[0]['right_sum']).toBe(1560);
258
- });
259
- it(`limit - provided - ${databaseName}`, async () => {
260
- // a cross join produces a Many to Many result.
261
- // symmetric aggregate are needed on both sides of the join
262
- // Check the row count and that sums on each side work properly.
263
- const result = await runtime
264
- .loadQuery(`
265
- query: table('malloytest.state_facts') -> {
266
- group_by: state
267
- aggregate: c is count()
268
- limit: 3
269
- }
270
- `)
271
- .run();
272
- expect(result.resultExplore.limit).toBe(3);
273
- });
274
- (0, util_1.testIf)(runtime.supportsNesting)(`number as null- ${databaseName}`, async () => {
275
- // a cross join produces a Many to Many result.
276
- // symmetric aggregate are needed on both sides of the join
277
- // Check the row count and that sums on each side work properly.
278
- const result = await runtime
279
- .loadQuery(`
280
- source: s is table('malloytest.state_facts') + {
281
- }
282
- query: s-> {
283
- group_by: state
284
- nest: ugly is {
285
- group_by: popular_name
286
- aggregate: foo is NULLIF(sum(airport_count)*0,0)+1
287
- }
288
- }
289
- `)
290
- .run();
291
- expect(result.data.path(0, 'ugly', 0, 'foo').value).toBe(null);
292
- });
293
- // average should only include non-null values in the denominator
294
- it(`avg ignore null- ${databaseName}`, async () => {
295
- const result = await runtime
296
- .loadQuery(`
297
- sql: one is { select: """
298
- SELECT 2 as a
299
- UNION ALL SELECT 4
300
- UNION ALL SELECT null
301
- """}
302
-
303
- query: from_sql(one) -> {
304
- join_cross: b is from_sql(one)
305
- aggregate:
306
- avg_a is a.avg()
307
- avg_b is b.a.avg()
308
- }
309
- `)
310
- .run();
311
- expect(result.data.value[0]['avg_a']).toBe(3);
312
- });
313
- it(`limit - not provided - ${databaseName}`, async () => {
314
- // a cross join produces a Many to Many result.
315
- // symmetric aggregate are needed on both sides of the join
316
- // Check the row count and that sums on each side work properly.
317
- const result = await runtime
318
- .loadQuery(`
319
- query: table('malloytest.state_facts') -> {
320
- group_by: state
321
- aggregate: c is count()
322
- }
323
- `)
324
- .run();
325
- expect(result.resultExplore.limit).toBe(undefined);
326
- });
327
- it(`limit pipeline - provided - ${databaseName}`, async () => {
328
- // a cross join produces a Many to Many result.
329
- // symmetric aggregate are needed on both sides of the join
330
- // Check the row count and that sums on each side work properly.
331
- const result = await runtime
332
- .loadQuery(`
333
- query: table('malloytest.state_facts') -> {
334
- project: state
335
- limit: 10
336
- }
337
- -> {
338
- project: state
339
- limit: 3
340
- }
341
- `)
342
- .run();
343
- expect(result.resultExplore.limit).toBe(3);
344
- });
345
- it(`ungrouped top level - ${databaseName}`, async () => {
346
- const result = await runtime
347
- .loadQuery(`
348
- source: s is table('malloytest.state_facts') + {
349
- measure: total_births is births.sum()
350
- measure: births_per_100k is floor(total_births/ all(total_births) * 100000)
351
- }
352
-
353
- query:s-> {
354
- group_by: state
355
- aggregate: births_per_100k
356
- }
357
- `)
358
- .run();
359
- // console.log(result.sql);
360
- expect(result.data.path(0, 'births_per_100k').value).toBe(9742);
361
- });
362
- (0, util_1.testIf)(runtime.supportsNesting)(`ungrouped top level with nested - ${databaseName}`, async () => {
363
- const result = await runtime
364
- .loadQuery(`
365
- source: s is table('malloytest.state_facts') + {
366
- measure: total_births is births.sum()
367
- measure: births_per_100k is floor(total_births/ all(total_births) * 100000)
368
- }
369
-
370
- query:s-> {
371
- group_by: state
372
- aggregate: births_per_100k
373
- nest: by_name is {
374
- group_by: popular_name
375
- aggregate: total_births
376
- }
377
- limit: 1000
378
- }
379
- `)
380
- .run();
381
- // console.log(result.sql);
382
- expect(result.data.path(0, 'births_per_100k').value).toBe(9742);
383
- });
384
- it(`ungrouped - eliminate rows - ${databaseName}`, async () => {
385
- const result = await runtime
386
- .loadQuery(`
387
- source: s is table('malloytest.state_facts') + {
388
- measure: m is all(births.sum())
389
- where: state='CA' | 'NY'
390
- }
391
-
392
- query:s-> {
393
- group_by: state
394
- aggregate: m
395
- }
396
- `)
397
- .run();
398
- // console.log(result.sql);
399
- expect(result.data.toObject().length).toBe(2);
400
- });
401
- (0, util_1.testIf)(runtime.supportsNesting)(`ungrouped nested with no grouping above - ${databaseName}`, async () => {
402
- const result = await runtime
403
- .loadQuery(`
404
- source: s is table('malloytest.state_facts') + {
405
- measure: total_births is births.sum()
406
- measure: births_per_100k is floor(total_births/ all(total_births) * 100000)
407
- }
408
-
409
- query: s-> {
410
- aggregate: total_births
411
- nest: by_name is {
412
- group_by: popular_name
413
- aggregate: births_per_100k
414
- }
415
- }
416
-
417
- `)
418
- .run();
419
- // console.log(result.sql);
420
- expect(result.data.path(0, 'by_name', 0, 'births_per_100k').value).toBe(66703);
421
- });
422
- (0, util_1.testIf)(runtime.supportsNesting)(`ungrouped - partial grouping - ${databaseName}`, async () => {
423
- const result = await runtime
424
- .loadQuery(`
425
- source: airports is table('malloytest.airports') {
426
- measure: c is count()
427
- }
428
-
429
-
430
- query: airports -> {
431
- where: state = 'TX' | 'NY'
432
- group_by:
433
- faa_region
434
- state
435
- aggregate:
436
- c
437
- all_ is all(c)
438
- airport_count is c {? fac_type = 'AIRPORT'}
439
- nest: fac_type is {
440
- group_by: fac_type
441
- aggregate:
442
- c
443
- all_ is all(c)
444
- all_state_region is exclude(c,fac_type)
445
- all_of_this_type is exclude(c, state, faa_region)
446
- all_top is exclude(c, state, faa_region, fac_type)
447
- }
448
- }
449
-
450
- `)
451
- .run();
452
- // console.log(result.sql);
453
- expect(result.data.path(0, 'fac_type', 0, 'all_').value).toBe(1845);
454
- expect(result.data.path(0, 'fac_type', 0, 'all_state_region').value).toBe(1845);
455
- expect(result.data.path(0, 'fac_type', 0, 'all_of_this_type').value).toBe(1782);
456
- expect(result.data.path(0, 'fac_type', 0, 'all_top').value).toBe(2421);
457
- });
458
- (0, util_1.testIf)(runtime.supportsNesting)(`ungrouped - all nested - ${databaseName}`, async () => {
459
- const result = await runtime
460
- .loadQuery(`
461
- source: airports is table('malloytest.airports') {
462
- measure: c is count()
463
- }
464
-
465
-
466
- query: airports -> {
467
- where: state = 'TX' | 'NY'
468
- group_by:
469
- state
470
- aggregate:
471
- c
472
- all_ is all(c)
473
- airport_count is c {? fac_type = 'AIRPORT'}
474
- nest: fac_type is {
475
- group_by: fac_type, major
476
- aggregate:
477
- c
478
- all_ is all(c)
479
- all_major is all(c,major)
480
- }
481
- }
482
-
483
-
484
- `)
485
- .run();
486
- // console.log(result.sql);
487
- expect(result.data.path(0, 'fac_type', 0, 'all_').value).toBe(1845);
488
- expect(result.data.path(0, 'fac_type', 0, 'all_major').value).toBe(1819);
489
- });
490
- (0, util_1.testIf)(runtime.supportsNesting)(`ungrouped nested - ${databaseName}`, async () => {
491
- const result = await runtime
492
- .loadQuery(`
493
- source: s is table('malloytest.state_facts') + {
494
- measure: total_births is births.sum()
495
- measure: births_per_100k is floor(total_births/ all(total_births) * 100000)
496
- }
497
-
498
- query:s -> {
499
- group_by: popular_name
500
- nest: by_state is {
501
- group_by: state
502
- aggregate: births_per_100k
503
- }
504
- }
505
-
506
- `)
507
- .run();
508
- // console.log(result.sql);
509
- expect(result.data.path(0, 'by_state', 0, 'births_per_100k').value).toBe(36593);
510
- });
511
- (0, util_1.testIf)(runtime.supportsNesting)(`ungrouped nested expression - ${databaseName}`, async () => {
512
- const result = await runtime
513
- .loadQuery(`
514
- source: s is table('malloytest.state_facts') + {
515
- measure: total_births is births.sum()
516
- measure: births_per_100k is floor(total_births/ all(total_births) * 100000)
517
- }
518
-
519
- query:s -> {
520
- group_by: upper_name is upper(popular_name)
521
- nest: by_state is {
522
- group_by: state
523
- aggregate: births_per_100k
524
- }
525
- }
526
-
527
- `)
528
- .run();
529
- // console.log(result.sql);
530
- expect(result.data.path(0, 'by_state', 0, 'births_per_100k').value).toBe(36593);
531
- });
532
- (0, util_1.testIf)(runtime.supportsNesting)(`ungrouped nested group by float - ${databaseName}`, async () => {
533
- const result = await runtime
534
- .loadQuery(`
535
- source: s is table('malloytest.state_facts') + {
536
- measure: total_births is births.sum()
537
- measure: ug is all(total_births)
538
- }
539
-
540
- query:s -> {
541
- group_by: f is floor(airport_count/300.0)
542
- nest: by_state is {
543
- group_by: state
544
- aggregate: ug
545
- }
546
- }
547
-
548
- `)
549
- .run();
550
- // console.log(result.sql);
551
- // console.log(JSON.stringify(result.data.toObject(), null, 2));
552
- expect(result.data.path(0, 'by_state', 0, 'ug').value).toBe(62742230);
553
- });
554
- it(`all with parameters - basic - ${databaseName}`, async () => {
555
- const result = await runtime
556
- .loadQuery(`
557
- source: s is table('malloytest.state_facts') + {
558
- measure: total_births is births.sum()
559
- }
560
-
561
- query: s -> {
562
- group_by: popular_name, state
563
- aggregate:
564
- total_births
565
- all_births is all(total_births)
566
- all_name is exclude(total_births, state)
567
- }
568
-
569
- `)
570
- .run();
571
- // console.log(result.sql);
572
- // console.log(JSON.stringify(result.data.toObject(), null, 2));
573
- expect(result.data.path(0, 'all_births').value).toBe(295727065);
574
- expect(result.data.path(0, 'all_name').value).toBe(197260594);
575
- });
576
- (0, util_1.testIf)(runtime.supportsNesting)(`all with parameters - nest - ${databaseName}`, async () => {
577
- const result = await runtime
578
- .loadQuery(`
579
- source: s is table('malloytest.state_facts') + {
580
- measure: total_births is births.sum()
581
- dimension: abc is floor(airport_count/300)
582
- }
583
-
584
- query: s -> {
585
- group_by: abc
586
- aggregate: total_births
587
- nest: by_stuff is {
588
- group_by: popular_name, state
589
- aggregate:
590
- total_births
591
- all_births is all(total_births)
592
- all_name is exclude(total_births, state)
593
- }
594
- }
595
-
596
- `)
597
- .run();
598
- // console.log(result.sql);
599
- // console.log(JSON.stringify(result.data.toObject(), null, 2));
600
- expect(result.data.path(0, 'by_stuff', 0, 'all_births').value).toBe(119809719);
601
- expect(result.data.path(0, 'by_stuff', 0, 'all_name').value).toBe(61091215);
602
- });
603
- (0, util_1.testIf)(runtime.supportsNesting)(`single value to udf - ${databaseName}`, async () => {
604
- const result = await runtime
605
- .loadQuery(`
606
- source: f is table('malloytest.state_facts') {
607
- query: fun is {
608
- aggregate: t is count()
609
- }
610
- -> {
611
- project: t1 is t+1
612
- }
613
- }
614
- query: f-> {
615
- nest: fun
616
- }
617
- `)
618
- .run();
619
- // console.log(result.sql);
620
- expect(result.data.path(0, 'fun', 0, 't1').value).toBe(52);
621
- });
622
- (0, util_1.testIf)(runtime.supportsNesting)(`Multi value to udf - ${databaseName}`, async () => {
623
- const result = await runtime
624
- .loadQuery(`
625
- source: f is table('malloytest.state_facts') {
626
- query: fun is {
627
- group_by: one is 1
628
- aggregate: t is count()
629
- }
630
- -> {
631
- project: t1 is t+1
632
- }
633
- }
634
- query: f-> {
635
- nest: fun
636
- }
637
- `)
638
- .run();
639
- // console.log(result.sql);
640
- // console.log(result.data.toObject());
641
- expect(result.data.path(0, 'fun', 0, 't1').value).toBe(52);
642
- });
643
- (0, util_1.testIf)(runtime.supportsNesting)(`Multi value to udf group by - ${databaseName}`, async () => {
644
- const result = await runtime
645
- .loadQuery(`
646
- source: f is table('malloytest.state_facts') {
647
- query: fun is {
648
- group_by: one is 1
649
- aggregate: t is count()
650
- }
651
- -> {
652
- group_by: t1 is t+1
653
- }
654
- }
655
- query: f-> {
656
- nest: fun
657
- }
658
- `)
659
- .run();
660
- // console.log(result.sql);
661
- // console.log(result.data.toObject());
662
- expect(result.data.path(0, 'fun', 0, 't1').value).toBe(52);
663
- });
664
- const sql1234 = `
665
- sql: one is {select: """
666
- SELECT 1 as a, 2 as b
667
- UNION ALL SELECT 3, 4
668
- """}`;
669
- it(`sql_block - ${databaseName}`, async () => {
670
- const result = await runtime
671
- .loadQuery(`
672
- ${sql1234}
673
- source: eone is from_sql(one) {}
674
-
675
- query: eone -> { project: a }
676
- `)
677
- .run();
678
- expect(result.data.value[0]['a']).toBe(1);
679
- });
680
- it(`sql_block no explore- ${databaseName}`, async () => {
681
- const result = await runtime
682
- .loadQuery(`
683
- ${sql1234}
684
- query: from_sql(one) -> { project: a }
685
- `)
686
- .run();
687
- expect(result.data.value[0]['a']).toBe(1);
688
- });
689
- it(`sql_block with turducken- ${databaseName}`, async () => {
690
- if (databaseName !== 'postgres') {
691
- const turduckenQuery = `
692
- sql: state_as_sql is {
693
- select: """
694
- SELECT
695
- ROW_NUMBER() OVER (ORDER BY state_count) as row_number,
696
- *
697
- FROM (%{
698
- table('malloytest.state_facts')
699
- -> {
700
- group_by: popular_name
701
- aggregate: state_count is count()
702
- }
703
- }%)
704
- """
705
- }
706
- query: from_sql(state_as_sql) -> {
707
- project: *; where: popular_name = 'Emma'
708
- }`;
709
- const result = await runtime.loadQuery(turduckenQuery).run();
710
- expect(result.data.value[0]['state_count']).toBe(6);
711
- }
712
- });
713
- // it(`sql_block version- ${databaseName}`, async () => {
714
- // const result = await runtime
715
- // .loadQuery(
716
- // `
717
- // sql: one is ||
718
- // select version() as version
719
- // ;;
720
- // query: from_sql(one) -> { project: version }
721
- // `
722
- // )
723
- // .run();
724
- // expect(result.data.value[0].version).toBe("something");
725
- // });
726
- // local declarations
727
- it(`local declarations external query - ${databaseName}`, async () => {
728
- const result = await runtime
729
- .loadQuery(`
730
- ${sql1234}
731
- query: from_sql(one) -> {
732
- declare: c is a + 1
733
- project: c
734
- }
735
- `)
736
- .run();
737
- expect(result.data.value[0]['c']).toBe(2);
738
- });
739
- it(`local declarations named query - ${databaseName}`, async () => {
740
- const result = await runtime
741
- .loadQuery(`
742
- ${sql1234}
743
- source: foo is from_sql(one) + {
744
- query: bar is {
745
- declare: c is a + 1
746
- project: c
747
- }
748
- }
749
-
750
- query: foo-> bar
751
- `)
752
- .run();
753
- expect(result.data.value[0]['c']).toBe(2);
754
- });
755
- it(`local declarations refined named query - ${databaseName}`, async () => {
756
- const result = await runtime
757
- .loadQuery(`
758
- ${sql1234}
759
- source: foo is from_sql(one) + {
760
- query: bar is {
761
- declare: c is a + 1
762
- project: c
763
- }
764
-
765
- query: baz is bar + {
766
- declare: d is c + 1
767
- project: d
768
- }
769
- }
770
-
771
- query: foo-> baz
772
- `)
773
- .run();
774
- expect(result.data.value[0]['d']).toBe(3);
775
- });
776
- it(`regexp match- ${databaseName}`, async () => {
777
- const result = await runtime
778
- .loadQuery(`
779
- sql: one is { select: """
780
- SELECT 'hello mom' as a, 'cheese tastes good' as b
781
- UNION ALL SELECT 'lloyd is a bozo', 'michael likes poetry'
782
- """}
783
-
784
- query: from_sql(one) -> {
785
- aggregate: llo is count() {? a ~ r'llo'}
786
- aggregate: m2 is count() {? a !~ r'bozo'}
787
- }
788
- `)
789
- .run();
790
- expect(result.data.value[0]['llo']).toBe(2);
791
- expect(result.data.value[0]['m2']).toBe(1);
792
- });
793
- it(`substitution precidence- ${databaseName}`, async () => {
794
- const result = await runtime
795
- .loadQuery(`
796
- sql: one is {select: """
797
- SELECT 5 as a, 2 as b
798
- UNION ALL SELECT 3, 4
799
- """}
800
-
801
- query: from_sql(one) -> {
802
- declare: c is b + 4
803
- project: x is a * c
804
- }
805
- `)
806
- .run();
807
- expect(result.data.value[0]['x']).toBe(30);
808
- });
809
- it(`array unnest - ${databaseName}`, async () => {
810
- const result = await runtime
811
- .loadQuery(`
812
- sql: atitle is {select:"""
813
- SELECT
814
- city,
815
- ${getSplitFunction(databaseName)('city', ' ')} as words
816
- FROM ${rootDbPath(databaseName)}malloytest.aircraft
817
- """}
818
-
819
- source: title is from_sql(atitle){}
820
-
821
- query: title -> {
822
- where: words.value != null
823
- group_by: words.value
824
- aggregate: c is count()
825
- }
826
- `)
827
- .run();
828
- expect(result.data.value[0]['c']).toBe(145);
829
- });
830
- // make sure we can count the total number of elements when fanning out.
831
- it(`array unnest x 2 - ${databaseName}`, async () => {
832
- const result = await runtime
833
- .loadQuery(`
834
- sql: atitle is {select: """
835
- SELECT
836
- city,
837
- ${getSplitFunction(databaseName)('city', ' ')} as words,
838
- ${getSplitFunction(databaseName)('city', 'A')} as abreak
839
- FROM ${rootDbPath(databaseName)}malloytest.aircraft
840
- where city IS NOT null
841
- """}
842
-
843
- source: title is from_sql(atitle){}
844
-
845
- query: title -> {
846
- aggregate:
847
- b is count()
848
- c is words.count()
849
- a is abreak.count()
850
- }
851
- `)
852
- .run();
853
- expect(result.data.value[0]['b']).toBe(3552);
854
- expect(result.data.value[0]['c']).toBe(4586);
855
- expect(result.data.value[0]['a']).toBe(6601);
856
- });
857
- (0, util_1.testIf)(runtime.supportsNesting)(`nest null - ${databaseName}`, async () => {
858
- const result = await runtime
859
- .loadQuery(`
860
- query: table('malloytest.airports') -> {
861
- where: faa_region = null
862
- group_by: faa_region
863
- aggregate: airport_count is count()
864
- nest: by_state is {
865
- where: state != null
866
- group_by: state
867
- aggregate: airport_count is count()
868
- }
869
- nest: by_state1 is {
870
- where: state != null
871
- group_by: state
872
- aggregate: airport_count is count()
873
- limit: 1
874
- }
875
- }
876
- `)
877
- .run();
878
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
879
- const d = result.data.toObject();
880
- expect(d[0]['by_state']).not.toBe(null);
881
- expect(d[0]['by_state1']).not.toBe(null);
882
- });
883
- (0, util_1.testIf)(runtime.supportsNesting)(`number as null- ${databaseName}`, async () => {
884
- const result = await runtime
885
- .loadQuery(`
886
- source: s is table('malloytest.state_facts') + {
887
- }
888
- query: s-> {
889
- group_by: state
890
- nest: ugly is {
891
- group_by: popular_name
892
- aggregate: foo is NULLIF(sum(airport_count)*0,0)+1
893
- }
894
- }
895
- `)
896
- .run();
897
- expect(result.data.path(0, 'ugly', 0, 'foo').value).toBe(null);
898
- });
899
- describe('quoting and strings', () => {
900
- const tick = "'";
901
- const back = '\\';
902
- test('backslash quote', async () => {
903
- const result = await runtime
904
- .loadQuery(`
905
- query: table('malloytest.state_facts') -> {
906
- project: tick is '${back}${tick}'
907
- }
908
- `)
909
- .run();
910
- expect(result.data.value[0]['tick']).toBe(tick);
911
- });
912
- test('backslash backslash', async () => {
913
- const result = await runtime
914
- .loadQuery(`
915
- query: table('malloytest.state_facts') -> {
916
- project: back is '${back}${back}'
917
- }
918
- `)
919
- .run();
920
- expect(result.data.value[0]['back']).toBe(back);
921
- });
922
- (0, util_1.testIf)(runtime.supportsNesting)('spaces in names', async () => {
923
- const result = await runtime
924
- .loadQuery(`
925
- source: \`space race\` is table('malloytest.state_facts') {
926
- join_one: \`j space\` is table('malloytest.state_facts') on \`j space\`.state=state
927
- query: \`q u e r y\` is {
928
- group_by:
929
- \`P O P\` is popular_name
930
- \`J P O P\` is \`j space\`.popular_name
931
- aggregate: \`c o u n t\` is count()
932
- calculate:
933
- \`R O W\` is row_number()
934
- \`l a g\` is lag(\`P O P\`, 1)
935
- nest: \`by state\` is {
936
- group_by: \`J S\` is \`j space\`.state
937
- aggregate: \`c o u n t\` is count()
938
- }
939
- }
940
- }
941
-
942
- query: \`space race\` -> \`q u e r y\`
943
- `)
944
- .run();
945
- expect(result.data.value[0]['c o u n t']).toBe(24);
946
- });
947
- });
948
- });
949
- };
950
- exports.noModelSharedTests = noModelSharedTests;
29
+ const nomodel_1 = require("../shared/nomodel");
951
30
  const runtimes = new runtimes_1.RuntimeList((0, util_1.databasesFromEnvironmentOr)(runtimes_1.allDatabases));
952
31
  /*
953
32
  * This test file reuses common tests definitions.
954
33
  * For actual test development please go to: test/src/databases/shared/nomodel.spec.ts
955
34
  */
956
- (0, exports.noModelSharedTests)(runtimes);
35
+ (0, nomodel_1.noModelSharedTests)(runtimes);
957
36
  //# sourceMappingURL=nomodel.spec.js.map