@malloydata/malloy-tests 0.0.95-dev231019211822 → 0.0.95

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