@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,625 +23,12 @@
23
23
  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
24
  */
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.timeSharedTests = void 0;
27
26
  const runtimes_1 = require("../../runtimes");
28
- require("../../util/db-jest-matchers");
29
- const util_1 = require("../../util");
30
- const luxon_1 = require("luxon");
31
- const timeSharedTests = (runtimes, _splitFunction) => {
32
- const timeSQL = "SELECT DATE '2021-02-24' as t_date, TIMESTAMP '2021-02-24 03:05:06' as t_timestamp";
33
- // MTOY todo look at this list for timezone problems, I know there are some
34
- describe.each(runtimes.runtimeList)('%s date and time', (dbName, runtime) => {
35
- const sqlEq = (0, util_1.mkSqlEqWith)(runtime, { sql: timeSQL });
36
- describe('interval measurement', () => {
37
- test('forwards is positive', async () => {
38
- const eq = sqlEq('day(@2000-01-01 to @2000-01-02)', '1');
39
- expect(await eq).isSqlEq();
40
- });
41
- test('reverse is negative', async () => {
42
- const eq = sqlEq('day(@2000-01-02 to @2000-01-01)', '-1');
43
- expect(await eq).isSqlEq();
44
- });
45
- test('seconds', async () => {
46
- expect(await sqlEq('seconds(now to now + 1 second)', 1)).isSqlEq();
47
- expect(await sqlEq('seconds(now to now)', 0)).isSqlEq();
48
- expect(await sqlEq('seconds(now to now + 2 seconds)', 2)).isSqlEq();
49
- expect(await sqlEq('seconds(now to now - 2 seconds)', -2)).isSqlEq();
50
- const a = '@2001-01-01 00:00:00';
51
- const b = '@2001-01-01 00:00:00.999';
52
- expect(await sqlEq(`seconds(${a} to ${b})`, 0)).isSqlEq();
53
- expect(await sqlEq(`seconds(${b} to @2001-01-01 00:00:01)`, 0)).isSqlEq();
54
- });
55
- test('minutes', async () => {
56
- expect(await sqlEq('minutes(@2022-10-03 10:23:08 to @2022-10-03 10:24:07)', 0)).isSqlEq();
57
- expect(await sqlEq('minutes(now to now + 1 minute)', 1)).isSqlEq();
58
- expect(await sqlEq('minutes(now to now + 59 seconds)', 0)).isSqlEq();
59
- expect(await sqlEq('minutes(now to now + 2 minutes)', 2)).isSqlEq();
60
- expect(await sqlEq('minutes(now to now - 2 minutes)', -2)).isSqlEq();
61
- });
62
- test('hours', async () => {
63
- expect(await sqlEq('hours(@2022-10-03 10:23:00 to @2022-10-03 11:22:00)', 0)).isSqlEq();
64
- expect(await sqlEq('hours(now to now + 1 hour)', 1)).isSqlEq();
65
- expect(await sqlEq('hours(now to now + 59 minutes)', 0)).isSqlEq();
66
- expect(await sqlEq('hours(now to now + 120 minutes)', 2)).isSqlEq();
67
- expect(await sqlEq('hours(now to now - 2 hours)', -2)).isSqlEq();
68
- });
69
- test('days', async () => {
70
- expect(await sqlEq('days(now.day to now.day + 1 day)', 1)).isSqlEq();
71
- expect(await sqlEq('days(now.day to now.day + 23 hours)', 0)).isSqlEq();
72
- expect(await sqlEq('days(now.day to now.day + 48 hours)', 2)).isSqlEq();
73
- expect(await sqlEq('days(now.day to now.day - 48 hours)', -2)).isSqlEq();
74
- expect(await sqlEq('days(@2022-10-03 10:23:00 to @2022-10-04 09:23:00)', 0)).isSqlEq();
75
- });
76
- // MTOY TODO remove or implment
77
- // These all are complicated by civul time issues, skipping for now
78
- // test.skip('weeks', async () => {
79
- // expect(await sqlEq('week(now.week to now.week + 6 days)', 0)).isSqlEq();
80
- // expect(await sqlEq('week(now.week to now.week + 7 days)', 1)).isSqlEq();
81
- // expect(
82
- // await sqlEq('week(now.week to now.week + 7 days - 1 second)', 0)
83
- // ).isSqlEq();
84
- // expect(await sqlEq('weeks(@2022-10-01 to @2022-10-07)', 0)).isSqlEq();
85
- // expect(await sqlEq('weeks(@2022-10-01 to @2022-10-08)', 1)).isSqlEq();
86
- // expect(await sqlEq('weeks(@2022-10-15 to @2022-10-01)', -2)).isSqlEq();
87
- // expect(await sqlEq('weeks(@2022-10-02 to @2023-10-02)', 52)).isSqlEq();
88
- // expect(
89
- // await sqlEq('weeks(@2022-10-01 12:00 to @2022-10-08 11:59)', 0)
90
- // ).isSqlEq();
91
- // });
92
- // test.skip('months', async () => {
93
- // expect(await sqlEq('months(now to now)', 0)).isSqlEq();
94
- // expect(await sqlEq('months(@2001-01-01 to @2001-02-01)', 1)).isSqlEq();
95
- // expect(await sqlEq('months(@2001-01-01 to @2001-03-01)', 2)).isSqlEq();
96
- // expect(await sqlEq('months(@2001-01-01 to @2002-02-01)', 13)).isSqlEq();
97
- // expect(
98
- // await sqlEq('months(@2022-10-02 12:00 to @2022-11-02 11:59)', 0)
99
- // ).isSqlEq();
100
- // });
101
- // test.skip('quarters', async () => {
102
- // expect(await sqlEq('quarters(now to now + 1 quarter)', 1)).isSqlEq();
103
- // expect(
104
- // await sqlEq('quarters(now.quarter to now.quarter + 27 days)', 0)
105
- // ).isSqlEq();
106
- // expect(await sqlEq('quarters(now to now + 2 quarters)', 2)).isSqlEq();
107
- // expect(await sqlEq('quarters(now to now - 2 quarters)', -2)).isSqlEq();
108
- // expect(
109
- // await sqlEq('quarters(@2022-01-01 12:00 to @2022-04-01 12:00)', 1)
110
- // ).isSqlEq();
111
- // expect(
112
- // await sqlEq('quarters(@2022-01-01 12:00 to @2022-04-01 11:59)', 0)
113
- // ).isSqlEq();
114
- // });
115
- // test.skip('years', async () => {
116
- // expect(await sqlEq('years(@2022 to @2023)', 1)).isSqlEq();
117
- // expect(await sqlEq('years(@2022-01-01 to @2022-12-31)', 0)).isSqlEq();
118
- // expect(await sqlEq('years(@2022 to @2024)', 2)).isSqlEq();
119
- // expect(await sqlEq('years(@2024 to @2022)', -2)).isSqlEq();
120
- // expect(
121
- // await sqlEq('years(@2022-01-01 12:00 to @2024-01-01 11:59)', 1)
122
- // ).isSqlEq();
123
- // });
124
- });
125
- describe('timestamp truncation', () => {
126
- // 2021-02-24 03:05:06
127
- test('trunc second', async () => {
128
- const eq = sqlEq('t_timestamp.second', '@2021-02-24 03:05:06');
129
- expect(await eq).isSqlEq();
130
- });
131
- test('trunc minute', async () => {
132
- const eq = sqlEq('t_timestamp.minute', '@2021-02-24 03:05:00');
133
- expect(await eq).isSqlEq();
134
- });
135
- test('trunc hour', async () => {
136
- const eq = sqlEq('t_timestamp.hour', '@2021-02-24 03:00:00');
137
- expect(await eq).isSqlEq();
138
- });
139
- test('trunc day', async () => {
140
- const eq = sqlEq('t_timestamp.day', '@2021-02-24 00:00:00');
141
- expect(await eq).isSqlEq();
142
- });
143
- test('trunc week', async () => {
144
- const eq = sqlEq('t_timestamp.week', '@2021-02-21 00:00:00');
145
- expect(await eq).isSqlEq();
146
- });
147
- test('trunc month', async () => {
148
- const eq = sqlEq('t_timestamp.month', '@2021-02-01 00:00:00');
149
- expect(await eq).isSqlEq();
150
- });
151
- test('trunc quarter', async () => {
152
- const eq = sqlEq('t_timestamp.quarter', '@2021-01-01 00:00:00');
153
- expect(await eq).isSqlEq();
154
- });
155
- test('trunc year', async () => {
156
- const eq = sqlEq('t_timestamp.year', '@2021-01-01 00:00:00');
157
- expect(await eq).isSqlEq();
158
- });
159
- });
160
- describe('timestamp extraction', () => {
161
- // 2021-02-24 03:05:06
162
- test('extract second', async () => {
163
- const eq = sqlEq('second(t_timestamp)', '6');
164
- expect(await eq).isSqlEq();
165
- });
166
- test('extract minute', async () => {
167
- const eq = sqlEq('minute(t_timestamp)', '5');
168
- expect(await eq).isSqlEq();
169
- });
170
- test('extract hour', async () => {
171
- const eq = sqlEq('hour(t_timestamp)', '3');
172
- expect(await eq).isSqlEq();
173
- });
174
- test('extract day', async () => {
175
- const eq = sqlEq('day(t_timestamp)', '24');
176
- expect(await eq).isSqlEq();
177
- });
178
- test('extract day_of_week', async () => {
179
- const eq = sqlEq('day_of_week(t_timestamp)', '4');
180
- expect(await eq).isSqlEq();
181
- });
182
- test('first week day is one ', async () => {
183
- const eq = sqlEq('day_of_week(t_timestamp.week)', '1');
184
- expect(await eq).isSqlEq();
185
- });
186
- test('extract day_of_year', async () => {
187
- const eq = sqlEq('day_of_year(t_timestamp)', '55');
188
- expect(await eq).isSqlEq();
189
- });
190
- test('extract week', async () => {
191
- const eq = sqlEq('week(t_timestamp)', '8');
192
- expect(await eq).isSqlEq();
193
- });
194
- test('extract month', async () => {
195
- const eq = sqlEq('month(t_timestamp)', '2');
196
- expect(await eq).isSqlEq();
197
- });
198
- test('extract quarter', async () => {
199
- const eq = sqlEq('quarter(t_timestamp)', '1');
200
- expect(await eq).isSqlEq();
201
- });
202
- test('extract year', async () => {
203
- const eq = sqlEq('year(t_timestamp)', '2021');
204
- expect(await eq).isSqlEq();
205
- });
206
- });
207
- describe('date truncation', () => {
208
- test('date trunc day', async () => {
209
- const eq = sqlEq('t_date.day', '@2021-02-24');
210
- expect(await eq).isSqlEq();
211
- });
212
- test('date trunc week', async () => {
213
- const eq = sqlEq('t_date.week', '@2021-02-21');
214
- expect(await eq).isSqlEq();
215
- });
216
- test('date trunc month', async () => {
217
- const eq = sqlEq('t_date.month', '@2021-02-01');
218
- expect(await eq).isSqlEq();
219
- });
220
- test('date trunc quarter', async () => {
221
- const eq = sqlEq('t_date.quarter', '@2021-01-01');
222
- expect(await eq).isSqlEq();
223
- });
224
- test('date trunc year', async () => {
225
- const eq = sqlEq('t_date.year', '@2021');
226
- expect(await eq).isSqlEq();
227
- });
228
- });
229
- describe('date extraction', () => {
230
- test('date extract day', async () => {
231
- const eq = sqlEq('day(t_date)', '24');
232
- expect(await eq).isSqlEq();
233
- });
234
- test('date extract day_of_week', async () => {
235
- const eq = sqlEq('day_of_week(t_date)', '4');
236
- expect(await eq).isSqlEq();
237
- });
238
- test('date extract day_of_year', async () => {
239
- const eq = sqlEq('day_of_year(t_date)', '55');
240
- expect(await eq).isSqlEq();
241
- });
242
- test('date extract week', async () => {
243
- const eq = sqlEq('week(t_date)', '8');
244
- expect(await eq).isSqlEq();
245
- });
246
- test('date extract month', async () => {
247
- const eq = sqlEq('month(t_date)', '2');
248
- expect(await eq).isSqlEq();
249
- });
250
- test('date extract quarter', async () => {
251
- const eq = sqlEq('quarter(t_date)', '1');
252
- expect(await eq).isSqlEq();
253
- });
254
- test('date extract year', async () => {
255
- const eq = sqlEq('year(t_date)', '2021');
256
- expect(await eq).isSqlEq();
257
- });
258
- });
259
- describe('delta computations', () => {
260
- test('timestamp delta second', async () => {
261
- const eq = sqlEq('t_timestamp + 10 seconds', '@2021-02-24 03:05:16');
262
- expect(await eq).isSqlEq();
263
- });
264
- test('timestamp delta negative second', async () => {
265
- const eq = sqlEq('t_timestamp - 6 seconds', '@2021-02-24 03:05:00');
266
- expect(await eq).isSqlEq();
267
- });
268
- test('timestamp delta minute', async () => {
269
- const eq = sqlEq('t_timestamp + 10 minutes', '@2021-02-24 03:15:06');
270
- expect(await eq).isSqlEq();
271
- });
272
- test('timestamp delta hours', async () => {
273
- const eq = await sqlEq('t_timestamp + 10 hours', '@2021-02-24 13:05:06');
274
- expect(eq).isSqlEq();
275
- });
276
- test('timestamp delta week', async () => {
277
- const eq = sqlEq('(t_timestamp - 2 weeks)::date', '@2021-02-10');
278
- expect(await eq).isSqlEq();
279
- });
280
- test('timestamp delta month', async () => {
281
- const eq = sqlEq('(t_timestamp + 9 months)::date', '@2021-11-24');
282
- expect(await eq).isSqlEq();
283
- });
284
- test('timestamp delta quarter', async () => {
285
- const eq = sqlEq('(t_timestamp + 2 quarters)::date', '@2021-08-24');
286
- expect(await eq).isSqlEq();
287
- });
288
- test('timestamp delta year', async () => {
289
- const eq = sqlEq('(t_timestamp + 10 years)::date', '@2031-02-24');
290
- expect(await eq).isSqlEq();
291
- });
292
- test('date delta week', async () => {
293
- const eq = sqlEq('t_date - 2 weeks', '@2021-02-10');
294
- expect(await eq).isSqlEq();
295
- });
296
- test('date delta month', async () => {
297
- const eq = sqlEq('t_date + 9 months', '@2021-11-24');
298
- expect(await eq).isSqlEq();
299
- });
300
- test('date delta quarter', async () => {
301
- const eq = sqlEq('t_date + 2 quarters', '@2021-08-24');
302
- expect(await eq).isSqlEq();
303
- });
304
- test('date delta year', async () => {
305
- const eq = sqlEq('t_date + 10 years', '@2031-02-24');
306
- expect(await eq).isSqlEq();
307
- });
308
- });
309
- describe('for range edge tests', () => {
310
- describe('date', () => {
311
- test('before for-range is outside', async () => {
312
- const eq = sqlEq('t_date ? @2021-02-25 for 1 day', false);
313
- expect(await eq).isSqlEq();
314
- });
315
- test('first for-range is inside', async () => {
316
- const eq = sqlEq('t_date ? @2021-02-24 for 1 day', true);
317
- expect(await eq).isSqlEq();
318
- });
319
- test('last for-range is outside', async () => {
320
- const eq = sqlEq('t_date ? @2021-02-23 for 1 day', false);
321
- expect(await eq).isSqlEq();
322
- });
323
- });
324
- describe('timestamp', () => {
325
- test('before for-range is outside', async () => {
326
- const eq = sqlEq('t_timestamp ? @2021-02-25 00:00:00 for 1 day', false);
327
- expect(await eq).isSqlEq();
328
- });
329
- test('first for-range is inside', async () => {
330
- const eq = sqlEq('t_timestamp ? @2021-02-24 03:04:05 for 1 day', true);
331
- expect(await eq).isSqlEq();
332
- });
333
- test('last for-range is outside', async () => {
334
- const eq = sqlEq('t_timestamp ? @2021-02-23 03:05:06 for 1 day', false);
335
- expect(await eq).isSqlEq();
336
- });
337
- });
338
- });
339
- describe('to range edge tests', () => {
340
- describe('date', () => {
341
- test('before to is outside', async () => {
342
- const eq = sqlEq('t_date ? @2021-02-25 to @2021-03-01', false);
343
- expect(await eq).isSqlEq();
344
- });
345
- test('first to is inside', async () => {
346
- const eq = sqlEq('t_date ? @2021-02-24 to @2021-03-01', true);
347
- expect(await eq).isSqlEq();
348
- });
349
- test('last to is outside', async () => {
350
- const eq = sqlEq('t_date ? @2021-02-01 to @2021-02-24', false);
351
- expect(await eq).isSqlEq();
352
- });
353
- });
354
- describe('timestamp', () => {
355
- test('before to is outside', async () => {
356
- const eq = sqlEq('t_timestamp ? @2021-02-25 00:00:00 to @2021-02-26 00:00:00', false);
357
- expect(await eq).isSqlEq();
358
- });
359
- test('first to is inside', async () => {
360
- const eq = sqlEq('t_timestamp ? @2021-02-24 03:04:05 to @2021-02-26 00:00:00', true);
361
- expect(await eq).isSqlEq();
362
- });
363
- test('last to is outside', async () => {
364
- const eq = sqlEq('t_timestamp ? @2021-02-24 00:00:00 to @2021-02-24 03:05:06', false);
365
- expect(await eq).isSqlEq();
366
- });
367
- });
368
- });
369
- test('date in sql_block no explore', async () => {
370
- const eq = sqlEq('t_date', '@2021-02-24');
371
- expect(await eq).isSqlEq();
372
- });
373
- test('timestamp in sql_block no explore', async () => {
374
- const eq = sqlEq('t_timestamp', '@2021-02-24 03:05:06');
375
- expect(await eq).isSqlEq();
376
- });
377
- test('valid timestamp without seconds', async () => {
378
- // discovered this writing tests ...
379
- const eq = sqlEq('year(@2000-01-01 00:00)', '2000');
380
- expect(await eq).isSqlEq();
381
- });
382
- describe('granular time range checks', () => {
383
- const tsMoment = '@2021-02-24 03:05:06';
384
- test('minute implied truncated range', async () => {
385
- const tsBefore = '@2021-03-24 03:04:59';
386
- expect(await sqlEq(`${tsMoment} ? t_timestamp.minute`, true)).isSqlEq();
387
- expect(await sqlEq(`${tsBefore} ? t_timestamp.minute`, false)).isSqlEq();
388
- });
389
- test('day implied truncated range', async () => {
390
- expect(await sqlEq(`${tsMoment} ? t_timestamp.day`, true)).isSqlEq();
391
- });
392
- test('year implied truncated range', async () => {
393
- expect(await sqlEq(`${tsMoment} ? t_timestamp.year`, true)).isSqlEq();
394
- });
395
- test('timestamp in literal minute', async () => {
396
- expect(await sqlEq('t_timestamp ? @2021-02-24 03:05', true)).isSqlEq();
397
- });
398
- test('timestamp in literal day', async () => {
399
- expect(await sqlEq('t_timestamp ? @2021-02-24', true)).isSqlEq();
400
- });
401
- test('date in literal month', async () => {
402
- expect(await sqlEq('t_date ? @2021-02', true)).isSqlEq();
403
- });
404
- test('timestamp in literal month', async () => {
405
- expect(await sqlEq('t_timestamp ? @2021-02', true)).isSqlEq();
406
- });
407
- test('timestamp in literal year', async () => {
408
- expect(await sqlEq('t_timestamp ? @2021', true)).isSqlEq();
409
- });
410
- });
411
- test('dependant join dialect fragments', async () => {
412
- await expect(runtime).queryMatches(`
413
- sql: timeData is { connection: "${dbName}" select: """${timeSQL}""" }
414
- query: from_sql(timeData) -> {
415
- join_one: joined is from_sql(timeData) on t_date = joined.t_date
416
- group_by: t_month is joined.t_timestamp.month
417
- }
418
- `, { t_month: new Date('2021-02-01') });
419
- });
420
- describe('timezone set correctly', () => {
421
- test('timezone set in source used by query', async () => {
422
- expect((await (0, util_1.runQuery)(runtime, `sql: timeData is { connection: "${dbName}" select: """SELECT 1"""}
423
- source: timezone is from_sql(timeData) + {
424
- timezone: 'America/Los_Angeles'
425
- dimension: la_time is @2021-02-24 03:05:06
426
- }
427
- query: timezone -> {
428
- group_by: la_time
429
- }
430
- `)).resultExplore.queryTimezone).toBe('America/Los_Angeles');
431
- });
432
- (0, util_1.testIf)(runtime.supportsNesting)('timezone set in query inside source', async () => {
433
- expect((await (0, util_1.runQuery)(runtime, `sql: timeData is { connection: "${dbName}" select: """SELECT 1"""}
434
- source: timezone is from_sql(timeData) + {
435
- dimension: default_time is @2021-02-24 03:05:06
436
- query: la_query is {
437
- timezone: 'America/Los_Angeles'
438
- project: la_time is @2021-02-24 03:05:06
439
- }
440
- }
441
-
442
- query: timezone -> {
443
- group_by: default_time
444
- nest: la_query
445
- }
446
- `)).resultExplore.structDef).toMatchObject({
447
- fields: [
448
- {},
449
- { name: 'la_query', queryTimezone: 'America/Los_Angeles' },
450
- ],
451
- });
452
- });
453
- (0, util_1.testIf)(runtime.supportsNesting)('timezone set in query using source', async () => {
454
- expect((await (0, util_1.runQuery)(runtime, `sql: timeData is { connection: "${dbName}" select: """SELECT 1"""}
455
- source: timezone is from_sql(timeData) + {
456
- dimension: default_time is @2021-02-24 03:05:06
457
- query: undef_query is {
458
- project: undef_time is @2021-02-24 03:05:06
459
- }
460
- }
461
-
462
- query: timezone -> {
463
- timezone: 'America/Los_Angeles'
464
- group_by: default_time
465
- nest: undef_query
466
- }
467
- `)).resultExplore.queryTimezone).toBe('America/Los_Angeles');
468
- });
469
- (0, util_1.testIf)(runtime.supportsNesting)('multiple timezones', async () => {
470
- expect((await (0, util_1.runQuery)(runtime, `sql: timeData is { connection: "${dbName}" select: """SELECT 1"""}
471
- source: timezone is from_sql(timeData) + {
472
- timezone: 'America/New_York'
473
- dimension: ny_time is @2021-02-24 03:05:06
474
- query: la_query is {
475
- timezone: 'America/Los_Angeles'
476
- project: la_time is @2021-02-24 03:05:06
477
- }
478
- query: mex_query is {
479
- timezone: 'America/Mexico_City'
480
- project: mex_time is @2021-02-24 03:05:06
481
- }
482
- }
483
-
484
- query: timezone -> {
485
- group_by: ny_time
486
- nest: la_query, mex_query
487
- }
488
- `)).resultExplore.structDef).toMatchObject({
489
- queryTimezone: 'America/New_York',
490
- fields: [
491
- {},
492
- { name: 'la_query', queryTimezone: 'America/Los_Angeles' },
493
- { name: 'mex_query', queryTimezone: 'America/Mexico_City' },
494
- ],
495
- });
496
- });
497
- });
498
- });
499
- /*
500
- not entirely sure what to test here so i am going to free-wheel a bit
501
-
502
- 1) All of the extraction and truncation functions need to work
503
- in the query timezone.
504
- 2) All rendering needs to happen in the query time zone
505
- 3) If we feed rendered data back into a query, it needs to retain
506
- offsets on all timestamps. Worried that rendering it in the query
507
- time zone would somehow confuse bigquery which is always in UTC
508
- 4) when we filter on a binned time, that we generate a filter between
509
- the edges of the bin, instead of computing the bin and use '='
510
- 5) connection, model, and query time zone setting
511
- 6) piping a query in one time zone into a query in another
512
- 7) graphs neeed to respect query time zone
513
- */
514
- const zone = 'America/Mexico_City'; // -06:00 no DST
515
- const zone_2020 = luxon_1.DateTime.fromObject({
516
- year: 2020,
517
- month: 2,
518
- day: 20,
519
- hour: 0,
520
- minute: 0,
521
- second: 0,
522
- zone,
523
- });
524
- const utc_2020 = luxon_1.DateTime.fromObject({
525
- year: 2020,
526
- month: 2,
527
- day: 20,
528
- hour: 0,
529
- minute: 0,
530
- second: 0,
531
- zone: 'UTC',
532
- });
533
- describe.each(runtimes.runtimeList)('%s: tz literals', (dbName, runtime) => {
534
- test(`${dbName} - default timezone is UTC`, async () => {
535
- // this makes sure that the tests which use the test timezome are actually
536
- // testing something ... file this under "abundance of caution". It
537
- // really tests nothing, but I feel calmer with this here.
538
- const query = runtime.loadQuery(`
539
- sql: tzTest is { connection: "${dbName}" select: """SELECT 1 as one""" }
540
- query: from_sql(tzTest) -> {
541
- group_by: literalTime is @2020-02-20 00:00:00
542
- }
543
- `);
544
- const result = await query.run();
545
- const literal = result.data.path(0, 'literalTime').value;
546
- const have = luxon_1.DateTime.fromJSDate(literal);
547
- expect(have.valueOf()).toEqual(utc_2020.valueOf());
548
- });
549
- test('literal with zone name', async () => {
550
- const query = runtime.loadQuery(`
551
- sql: tzTest is { connection: "${dbName}" select: """SELECT 1 as one""" }
552
- query: from_sql(tzTest) -> {
553
- group_by: literalTime is @2020-02-20 00:00:00[America/Mexico_City]
554
- }
555
- `);
556
- const result = await query.run();
557
- const literal = result.data.path(0, 'literalTime').value;
558
- const have = luxon_1.DateTime.fromJSDate(literal);
559
- expect(have.valueOf()).toEqual(zone_2020.valueOf());
560
- });
561
- });
562
- describe.each(runtimes.runtimeList)('%s: query tz', (dbName, runtime) => {
563
- test('literal timestamps', async () => {
564
- const query = runtime.loadQuery(`
565
- sql: tzTest is { connection: "${dbName}" select: """SELECT 1 as one""" }
566
- query: from_sql(tzTest) -> {
567
- timezone: '${zone}'
568
- group_by: literalTime is @2020-02-20 00:00:00
569
- }
570
- `);
571
- const result = await query.run();
572
- const literal = result.data.path(0, 'literalTime').value;
573
- const have = luxon_1.DateTime.fromJSDate(literal);
574
- expect(have.valueOf()).toEqual(zone_2020.valueOf());
575
- });
576
- test('extract', async () => {
577
- await expect(runtime).queryMatches(`sql: tzTest is { connection: "${dbName}" select: """SELECT 1 as one""" }
578
- query: from_sql(tzTest) -> {
579
- timezone: '${zone}'
580
- declare: utc_midnight is @2020-02-20 00:00:00[UTC]
581
- project:
582
- mex_midnight is hour(utc_midnight)
583
- mex_day is day(utc_midnight)
584
- }`, { mex_midnight: 18, mex_day: 19 });
585
- });
586
- test('truncate day', async () => {
587
- // At midnight in london it the 19th in Mexico, so that truncates to
588
- // midnight on the 19th
589
- const mex_19 = luxon_1.DateTime.fromISO('2020-02-19T00:00:00', { zone });
590
- await expect(runtime).queryMatches(`sql: tzTest is { connection: "${dbName}" select: """SELECT 1 as one""" }
591
- query: from_sql(tzTest) -> {
592
- timezone: '${zone}'
593
- declare: utc_midnight is @2020-02-20 00:00:00[UTC]
594
- project:
595
- mex_day is utc_midnight.day
596
- }`, { mex_day: mex_19.toJSDate() });
597
- });
598
- test('cast timestamp to date', async () => {
599
- // At midnight in london it the 19th in Mexico, so when we cast that
600
- // to a date, it should be the 19th.
601
- await expect(runtime).queryMatches(`sql: tzTest is { connection: "${dbName}" select: """SELECT 1 as one""" }
602
- query: from_sql(tzTest) -> {
603
- timezone: '${zone}'
604
- declare: utc_midnight is @2020-02-20 00:00:00[UTC]
605
- project: mex_day is day(utc_midnight::date)
606
- }`, { mex_day: 19 });
607
- });
608
- test('cast date to timestamp', async () => {
609
- await expect(runtime).queryMatches(`sql: tzTest is { connection: "${dbName}" select: """
610
- SELECT DATE '2020-02-20' AS mex_20
611
- """ }
612
- query: from_sql(tzTest) -> {
613
- timezone: '${zone}'
614
- project: mex_ts is mex_20::timestamp
615
- }`, { mex_ts: zone_2020.toJSDate() });
616
- });
617
- test('can use unsupported types', async () => {
618
- if (dbName === 'bigquery') {
619
- await expect(runtime).queryMatches(`sql: timeData is { connection: "${dbName}" select: """
620
- SELECT DATETIME '2020-02-20 00:00:00' as t_datetime
621
- """}
622
- query: from_sql(timeData) -> {
623
- project: mex_220 is t_datetime::timestamp
624
- }`, { mex_220: utc_2020.toJSDate() });
625
- }
626
- else if (dbName === 'duckdb' || dbName === 'postgres') {
627
- await expect(runtime).queryMatches(`sql: timeData is { connection: "duckdb" select: """
628
- SELECT TIMESTAMPTZ '2020-02-20 00:00:00 ${zone}' as t_tstz
629
- """}
630
- query: from_sql(timeData) -> {
631
- project: mex_220 is t_tstz::timestamp
632
- }`, { mex_220: zone_2020.toJSDate() });
633
- }
634
- });
635
- });
636
- afterAll(async () => {
637
- await runtimes.closeAll();
638
- });
639
- };
640
- exports.timeSharedTests = timeSharedTests;
27
+ const time_1 = require("../shared/time");
641
28
  const runtimes = new runtimes_1.RuntimeList(runtimes_1.allDatabases);
642
29
  /*
643
30
  * This test file reuses common tests definitions.
644
31
  * For actual test development please go to: test/src/databases/shared/time.spec.ts
645
32
  */
646
- (0, exports.timeSharedTests)(runtimes);
33
+ (0, time_1.timeSharedTests)(runtimes);
647
34
  //# sourceMappingURL=time.spec.js.map