@malloydata/malloy-tests 0.0.66-dev230807232724
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +29 -0
- package/bin/dump_malloytest.sh +1 -0
- package/bin/postgres_init.sh +9 -0
- package/bin/postgres_start.sh +2 -0
- package/bin/postgres_stop.sh +2 -0
- package/data/duckdb/README.md +4 -0
- package/data/duckdb/aircraft.parquet +0 -0
- package/data/duckdb/aircraft_models.parquet +0 -0
- package/data/duckdb/airports.parquet +0 -0
- package/data/duckdb/alltypes.parquet +0 -0
- package/data/duckdb/alltypes2.parquet +0 -0
- package/data/duckdb/bq_medicare_test.parquet +0 -0
- package/data/duckdb/carriers.parquet +0 -0
- package/data/duckdb/flights/part.0.parquet +0 -0
- package/data/duckdb/flights/part.1.parquet +0 -0
- package/data/duckdb/flights/part.2.parquet +0 -0
- package/data/duckdb/flights.parquet +0 -0
- package/data/duckdb/flights_partitioned.parquet +0 -0
- package/data/duckdb/ga_sample.parquet +0 -0
- package/data/duckdb/numbers.parquet +0 -0
- package/data/duckdb/state_facts.parquet +0 -0
- package/data/duckdb/test.json +3 -0
- package/data/duckdb/words.parquet +0 -0
- package/data/duckdb/words_bigger.parquet +0 -0
- package/data/postgres/malloytest-postgres.sql.gz +0 -0
- package/data/postgres/state_facts.sql +366 -0
- package/dist/api.spec.d.ts +1 -0
- package/dist/api.spec.js +77 -0
- package/dist/api.spec.js.map +1 -0
- package/dist/databases/all/expr.spec.d.ts +3 -0
- package/dist/databases/all/expr.spec.js +581 -0
- package/dist/databases/all/expr.spec.js.map +1 -0
- package/dist/databases/all/functions.spec.d.ts +2 -0
- package/dist/databases/all/functions.spec.js +784 -0
- package/dist/databases/all/functions.spec.js.map +1 -0
- package/dist/databases/all/index.spec.d.ts +2 -0
- package/dist/databases/all/index.spec.js +154 -0
- package/dist/databases/all/index.spec.js.map +1 -0
- package/dist/databases/all/join.spec.d.ts +2 -0
- package/dist/databases/all/join.spec.js +309 -0
- package/dist/databases/all/join.spec.js.map +1 -0
- package/dist/databases/all/nomodel.spec.d.ts +2 -0
- package/dist/databases/all/nomodel.spec.js +957 -0
- package/dist/databases/all/nomodel.spec.js.map +1 -0
- package/dist/databases/all/orderby.spec.d.ts +2 -0
- package/dist/databases/all/orderby.spec.js +224 -0
- package/dist/databases/all/orderby.spec.js.map +1 -0
- package/dist/databases/all/problems.spec.d.ts +2 -0
- package/dist/databases/all/problems.spec.js +113 -0
- package/dist/databases/all/problems.spec.js.map +1 -0
- package/dist/databases/all/sql_expressions.spec.d.ts +2 -0
- package/dist/databases/all/sql_expressions.spec.js +96 -0
- package/dist/databases/all/sql_expressions.spec.js.map +1 -0
- package/dist/databases/all/time.spec.d.ts +3 -0
- package/dist/databases/all/time.spec.js +647 -0
- package/dist/databases/all/time.spec.js.map +1 -0
- package/dist/databases/bigquery/double_truncation.spec.d.ts +1 -0
- package/dist/databases/bigquery/double_truncation.spec.js +50 -0
- package/dist/databases/bigquery/double_truncation.spec.js.map +1 -0
- package/dist/databases/bigquery/handexpr.spec.d.ts +1 -0
- package/dist/databases/bigquery/handexpr.spec.js +713 -0
- package/dist/databases/bigquery/handexpr.spec.js.map +1 -0
- package/dist/databases/bigquery/injestion_time_partitioning.spec.d.ts +1 -0
- package/dist/databases/bigquery/injestion_time_partitioning.spec.js +235 -0
- package/dist/databases/bigquery/injestion_time_partitioning.spec.js.map +1 -0
- package/dist/databases/bigquery/joined_filters.spec.d.ts +1 -0
- package/dist/databases/bigquery/joined_filters.spec.js +72 -0
- package/dist/databases/bigquery/joined_filters.spec.js.map +1 -0
- package/dist/databases/bigquery/json.spec.d.ts +1 -0
- package/dist/databases/bigquery/json.spec.js +86 -0
- package/dist/databases/bigquery/json.spec.js.map +1 -0
- package/dist/databases/bigquery/malloy_query.spec.d.ts +1 -0
- package/dist/databases/bigquery/malloy_query.spec.js +906 -0
- package/dist/databases/bigquery/malloy_query.spec.js.map +1 -0
- package/dist/databases/bigquery/performance.skipped.spec.d.ts +1 -0
- package/dist/databases/bigquery/performance.skipped.spec.js +70 -0
- package/dist/databases/bigquery/performance.skipped.spec.js.map +1 -0
- package/dist/databases/bigquery/time.spec.d.ts +1 -0
- package/dist/databases/bigquery/time.spec.js +55 -0
- package/dist/databases/bigquery/time.spec.js.map +1 -0
- package/dist/databases/bigquery/wildcard_table_names.spec.d.ts +1 -0
- package/dist/databases/bigquery/wildcard_table_names.spec.js +212 -0
- package/dist/databases/bigquery/wildcard_table_names.spec.js.map +1 -0
- package/dist/databases/bigquery-duckdb/nested_source_table.spec.d.ts +1 -0
- package/dist/databases/bigquery-duckdb/nested_source_table.spec.js +247 -0
- package/dist/databases/bigquery-duckdb/nested_source_table.spec.js.map +1 -0
- package/dist/databases/bigquery-postgres/multi_connection.spec.d.ts +1 -0
- package/dist/databases/bigquery-postgres/multi_connection.spec.js +138 -0
- package/dist/databases/bigquery-postgres/multi_connection.spec.js.map +1 -0
- package/dist/databases/bigquery-postgres/streaming.spec.d.ts +1 -0
- package/dist/databases/bigquery-postgres/streaming.spec.js +88 -0
- package/dist/databases/bigquery-postgres/streaming.spec.js.map +1 -0
- package/dist/databases/duckdb/duckdb.spec.d.ts +1 -0
- package/dist/databases/duckdb/duckdb.spec.js +116 -0
- package/dist/databases/duckdb/duckdb.spec.js.map +1 -0
- package/dist/databases/postgres/postgres.spec.d.ts +1 -0
- package/dist/databases/postgres/postgres.spec.js +137 -0
- package/dist/databases/postgres/postgres.spec.js.map +1 -0
- package/dist/databases/shared/test_list.d.ts +3 -0
- package/dist/databases/shared/test_list.js +24 -0
- package/dist/databases/shared/test_list.js.map +1 -0
- package/dist/dependencies.spec.d.ts +1 -0
- package/dist/dependencies.spec.js +63 -0
- package/dist/dependencies.spec.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +49 -0
- package/dist/index.js.map +1 -0
- package/dist/model/utils.spec.d.ts +1 -0
- package/dist/model/utils.spec.js +38 -0
- package/dist/model/utils.spec.js.map +1 -0
- package/dist/models/faa_model.d.ts +5 -0
- package/dist/models/faa_model.js +977 -0
- package/dist/models/faa_model.js.map +1 -0
- package/dist/models/medicare_model.d.ts +4 -0
- package/dist/models/medicare_model.js +243 -0
- package/dist/models/medicare_model.js.map +1 -0
- package/dist/render/render.spec.d.ts +1 -0
- package/dist/render/render.spec.js +551 -0
- package/dist/render/render.spec.js.map +1 -0
- package/dist/runtimes.d.ts +33 -0
- package/dist/runtimes.js +147 -0
- package/dist/runtimes.js.map +1 -0
- package/dist/tags.spec.d.ts +1 -0
- package/dist/tags.spec.js +259 -0
- package/dist/tags.spec.js.map +1 -0
- package/dist/util/db-jest-matchers.d.ts +19 -0
- package/dist/util/db-jest-matchers.js +90 -0
- package/dist/util/db-jest-matchers.js.map +1 -0
- package/dist/util/index.d.ts +16 -0
- package/dist/util/index.js +171 -0
- package/dist/util/index.js.map +1 -0
- package/package.json +35 -0
- package/src/api.spec.ts +84 -0
- package/src/databases/all/expr.spec.ts +704 -0
- package/src/databases/all/functions.spec.ts +1135 -0
- package/src/databases/all/index.spec.ts +178 -0
- package/src/databases/all/join.spec.ts +350 -0
- package/src/databases/all/nomodel.spec.ts +1159 -0
- package/src/databases/all/orderby.spec.ts +268 -0
- package/src/databases/all/problems.spec.ts +121 -0
- package/src/databases/all/sql_expressions.spec.ts +107 -0
- package/src/databases/all/time.spec.ts +793 -0
- package/src/databases/bigquery/double_truncation.spec.ts +51 -0
- package/src/databases/bigquery/handexpr.spec.ts +782 -0
- package/src/databases/bigquery/injestion_time_partitioning.spec.ts +268 -0
- package/src/databases/bigquery/joined_filters.spec.ts +75 -0
- package/src/databases/bigquery/json.spec.ts +95 -0
- package/src/databases/bigquery/malloy_query.spec.ts +1036 -0
- package/src/databases/bigquery/performance.skipped.spec.ts +73 -0
- package/src/databases/bigquery/time.spec.ts +59 -0
- package/src/databases/bigquery/wildcard_table_names.spec.ts +233 -0
- package/src/databases/bigquery-duckdb/nested_source_table.spec.ts +268 -0
- package/src/databases/bigquery-postgres/multi_connection.spec.ts +143 -0
- package/src/databases/bigquery-postgres/streaming.spec.ts +100 -0
- package/src/databases/duckdb/duckdb.spec.ts +131 -0
- package/src/databases/postgres/postgres.spec.ts +167 -0
- package/src/databases/shared/test_list.ts +24 -0
- package/src/dependencies.spec.ts +62 -0
- package/src/index.ts +36 -0
- package/src/model/utils.spec.ts +37 -0
- package/src/models/faa_model.ts +995 -0
- package/src/models/medicare_model.ts +246 -0
- package/src/render/__snapshots__/render.spec.ts.snap +12574 -0
- package/src/render/render.spec.ts +670 -0
- package/src/runtimes.ts +182 -0
- package/src/tags.spec.ts +277 -0
- package/src/util/db-jest-matchers.ts +128 -0
- package/src/util/index.ts +191 -0
- package/tsconfig.json +25 -0
|
@@ -0,0 +1,793 @@
|
|
|
1
|
+
/* eslint-disable no-console */
|
|
2
|
+
/*
|
|
3
|
+
* Copyright 2023 Google LLC
|
|
4
|
+
*
|
|
5
|
+
* Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
* a copy of this software and associated documentation files
|
|
7
|
+
* (the "Software"), to deal in the Software without restriction,
|
|
8
|
+
* including without limitation the rights to use, copy, modify, merge,
|
|
9
|
+
* publish, distribute, sublicense, and/or sell copies of the Software,
|
|
10
|
+
* and to permit persons to whom the Software is furnished to do so,
|
|
11
|
+
* subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be
|
|
14
|
+
* included in all copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
19
|
+
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
20
|
+
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
21
|
+
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
22
|
+
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import {RuntimeList, allDatabases} from '../../runtimes';
|
|
26
|
+
import '../../util/db-jest-matchers';
|
|
27
|
+
import {mkSqlEqWith, runQuery, testIf} from '../../util';
|
|
28
|
+
import {DateTime as LuxonDateTime} from 'luxon';
|
|
29
|
+
|
|
30
|
+
export const timeSharedTests = (
|
|
31
|
+
runtimes: RuntimeList,
|
|
32
|
+
_splitFunction?: (column: string, splitChar: string) => string
|
|
33
|
+
) => {
|
|
34
|
+
const timeSQL =
|
|
35
|
+
"SELECT DATE '2021-02-24' as t_date, TIMESTAMP '2021-02-24 03:05:06' as t_timestamp";
|
|
36
|
+
|
|
37
|
+
// MTOY todo look at this list for timezone problems, I know there are some
|
|
38
|
+
describe.each(runtimes.runtimeList)('%s date and time', (dbName, runtime) => {
|
|
39
|
+
const sqlEq = mkSqlEqWith(runtime, {sql: timeSQL});
|
|
40
|
+
|
|
41
|
+
describe('interval measurement', () => {
|
|
42
|
+
test('forwards is positive', async () => {
|
|
43
|
+
const eq = sqlEq('day(@2000-01-01 to @2000-01-02)', '1');
|
|
44
|
+
expect(await eq).isSqlEq();
|
|
45
|
+
});
|
|
46
|
+
test('reverse is negative', async () => {
|
|
47
|
+
const eq = sqlEq('day(@2000-01-02 to @2000-01-01)', '-1');
|
|
48
|
+
expect(await eq).isSqlEq();
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
test('seconds', async () => {
|
|
52
|
+
expect(await sqlEq('seconds(now to now + 1 second)', 1)).isSqlEq();
|
|
53
|
+
expect(await sqlEq('seconds(now to now)', 0)).isSqlEq();
|
|
54
|
+
expect(await sqlEq('seconds(now to now + 2 seconds)', 2)).isSqlEq();
|
|
55
|
+
expect(await sqlEq('seconds(now to now - 2 seconds)', -2)).isSqlEq();
|
|
56
|
+
const a = '@2001-01-01 00:00:00';
|
|
57
|
+
const b = '@2001-01-01 00:00:00.999';
|
|
58
|
+
expect(await sqlEq(`seconds(${a} to ${b})`, 0)).isSqlEq();
|
|
59
|
+
expect(
|
|
60
|
+
await sqlEq(`seconds(${b} to @2001-01-01 00:00:01)`, 0)
|
|
61
|
+
).isSqlEq();
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
test('minutes', async () => {
|
|
65
|
+
expect(
|
|
66
|
+
await sqlEq(
|
|
67
|
+
'minutes(@2022-10-03 10:23:08 to @2022-10-03 10:24:07)',
|
|
68
|
+
0
|
|
69
|
+
)
|
|
70
|
+
).isSqlEq();
|
|
71
|
+
|
|
72
|
+
expect(await sqlEq('minutes(now to now + 1 minute)', 1)).isSqlEq();
|
|
73
|
+
expect(await sqlEq('minutes(now to now + 59 seconds)', 0)).isSqlEq();
|
|
74
|
+
expect(await sqlEq('minutes(now to now + 2 minutes)', 2)).isSqlEq();
|
|
75
|
+
expect(await sqlEq('minutes(now to now - 2 minutes)', -2)).isSqlEq();
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
test('hours', async () => {
|
|
79
|
+
expect(
|
|
80
|
+
await sqlEq('hours(@2022-10-03 10:23:00 to @2022-10-03 11:22:00)', 0)
|
|
81
|
+
).isSqlEq();
|
|
82
|
+
expect(await sqlEq('hours(now to now + 1 hour)', 1)).isSqlEq();
|
|
83
|
+
expect(await sqlEq('hours(now to now + 59 minutes)', 0)).isSqlEq();
|
|
84
|
+
expect(await sqlEq('hours(now to now + 120 minutes)', 2)).isSqlEq();
|
|
85
|
+
expect(await sqlEq('hours(now to now - 2 hours)', -2)).isSqlEq();
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
test('days', async () => {
|
|
89
|
+
expect(await sqlEq('days(now.day to now.day + 1 day)', 1)).isSqlEq();
|
|
90
|
+
expect(await sqlEq('days(now.day to now.day + 23 hours)', 0)).isSqlEq();
|
|
91
|
+
expect(await sqlEq('days(now.day to now.day + 48 hours)', 2)).isSqlEq();
|
|
92
|
+
expect(
|
|
93
|
+
await sqlEq('days(now.day to now.day - 48 hours)', -2)
|
|
94
|
+
).isSqlEq();
|
|
95
|
+
expect(
|
|
96
|
+
await sqlEq('days(@2022-10-03 10:23:00 to @2022-10-04 09:23:00)', 0)
|
|
97
|
+
).isSqlEq();
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
// MTOY TODO remove or implment
|
|
101
|
+
// These all are complicated by civul time issues, skipping for now
|
|
102
|
+
// test.skip('weeks', async () => {
|
|
103
|
+
// expect(await sqlEq('week(now.week to now.week + 6 days)', 0)).isSqlEq();
|
|
104
|
+
// expect(await sqlEq('week(now.week to now.week + 7 days)', 1)).isSqlEq();
|
|
105
|
+
// expect(
|
|
106
|
+
// await sqlEq('week(now.week to now.week + 7 days - 1 second)', 0)
|
|
107
|
+
// ).isSqlEq();
|
|
108
|
+
// expect(await sqlEq('weeks(@2022-10-01 to @2022-10-07)', 0)).isSqlEq();
|
|
109
|
+
// expect(await sqlEq('weeks(@2022-10-01 to @2022-10-08)', 1)).isSqlEq();
|
|
110
|
+
// expect(await sqlEq('weeks(@2022-10-15 to @2022-10-01)', -2)).isSqlEq();
|
|
111
|
+
// expect(await sqlEq('weeks(@2022-10-02 to @2023-10-02)', 52)).isSqlEq();
|
|
112
|
+
// expect(
|
|
113
|
+
// await sqlEq('weeks(@2022-10-01 12:00 to @2022-10-08 11:59)', 0)
|
|
114
|
+
// ).isSqlEq();
|
|
115
|
+
// });
|
|
116
|
+
|
|
117
|
+
// test.skip('months', async () => {
|
|
118
|
+
// expect(await sqlEq('months(now to now)', 0)).isSqlEq();
|
|
119
|
+
// expect(await sqlEq('months(@2001-01-01 to @2001-02-01)', 1)).isSqlEq();
|
|
120
|
+
// expect(await sqlEq('months(@2001-01-01 to @2001-03-01)', 2)).isSqlEq();
|
|
121
|
+
// expect(await sqlEq('months(@2001-01-01 to @2002-02-01)', 13)).isSqlEq();
|
|
122
|
+
// expect(
|
|
123
|
+
// await sqlEq('months(@2022-10-02 12:00 to @2022-11-02 11:59)', 0)
|
|
124
|
+
// ).isSqlEq();
|
|
125
|
+
// });
|
|
126
|
+
|
|
127
|
+
// test.skip('quarters', async () => {
|
|
128
|
+
// expect(await sqlEq('quarters(now to now + 1 quarter)', 1)).isSqlEq();
|
|
129
|
+
// expect(
|
|
130
|
+
// await sqlEq('quarters(now.quarter to now.quarter + 27 days)', 0)
|
|
131
|
+
// ).isSqlEq();
|
|
132
|
+
// expect(await sqlEq('quarters(now to now + 2 quarters)', 2)).isSqlEq();
|
|
133
|
+
// expect(await sqlEq('quarters(now to now - 2 quarters)', -2)).isSqlEq();
|
|
134
|
+
// expect(
|
|
135
|
+
// await sqlEq('quarters(@2022-01-01 12:00 to @2022-04-01 12:00)', 1)
|
|
136
|
+
// ).isSqlEq();
|
|
137
|
+
// expect(
|
|
138
|
+
// await sqlEq('quarters(@2022-01-01 12:00 to @2022-04-01 11:59)', 0)
|
|
139
|
+
// ).isSqlEq();
|
|
140
|
+
// });
|
|
141
|
+
|
|
142
|
+
// test.skip('years', async () => {
|
|
143
|
+
// expect(await sqlEq('years(@2022 to @2023)', 1)).isSqlEq();
|
|
144
|
+
// expect(await sqlEq('years(@2022-01-01 to @2022-12-31)', 0)).isSqlEq();
|
|
145
|
+
// expect(await sqlEq('years(@2022 to @2024)', 2)).isSqlEq();
|
|
146
|
+
// expect(await sqlEq('years(@2024 to @2022)', -2)).isSqlEq();
|
|
147
|
+
// expect(
|
|
148
|
+
// await sqlEq('years(@2022-01-01 12:00 to @2024-01-01 11:59)', 1)
|
|
149
|
+
// ).isSqlEq();
|
|
150
|
+
// });
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
describe('timestamp truncation', () => {
|
|
154
|
+
// 2021-02-24 03:05:06
|
|
155
|
+
test('trunc second', async () => {
|
|
156
|
+
const eq = sqlEq('t_timestamp.second', '@2021-02-24 03:05:06');
|
|
157
|
+
expect(await eq).isSqlEq();
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
test('trunc minute', async () => {
|
|
161
|
+
const eq = sqlEq('t_timestamp.minute', '@2021-02-24 03:05:00');
|
|
162
|
+
expect(await eq).isSqlEq();
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
test('trunc hour', async () => {
|
|
166
|
+
const eq = sqlEq('t_timestamp.hour', '@2021-02-24 03:00:00');
|
|
167
|
+
expect(await eq).isSqlEq();
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
test('trunc day', async () => {
|
|
171
|
+
const eq = sqlEq('t_timestamp.day', '@2021-02-24 00:00:00');
|
|
172
|
+
expect(await eq).isSqlEq();
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
test('trunc week', async () => {
|
|
176
|
+
const eq = sqlEq('t_timestamp.week', '@2021-02-21 00:00:00');
|
|
177
|
+
expect(await eq).isSqlEq();
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
test('trunc month', async () => {
|
|
181
|
+
const eq = sqlEq('t_timestamp.month', '@2021-02-01 00:00:00');
|
|
182
|
+
expect(await eq).isSqlEq();
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
test('trunc quarter', async () => {
|
|
186
|
+
const eq = sqlEq('t_timestamp.quarter', '@2021-01-01 00:00:00');
|
|
187
|
+
expect(await eq).isSqlEq();
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
test('trunc year', async () => {
|
|
191
|
+
const eq = sqlEq('t_timestamp.year', '@2021-01-01 00:00:00');
|
|
192
|
+
expect(await eq).isSqlEq();
|
|
193
|
+
});
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
describe('timestamp extraction', () => {
|
|
197
|
+
// 2021-02-24 03:05:06
|
|
198
|
+
test('extract second', async () => {
|
|
199
|
+
const eq = sqlEq('second(t_timestamp)', '6');
|
|
200
|
+
expect(await eq).isSqlEq();
|
|
201
|
+
});
|
|
202
|
+
test('extract minute', async () => {
|
|
203
|
+
const eq = sqlEq('minute(t_timestamp)', '5');
|
|
204
|
+
expect(await eq).isSqlEq();
|
|
205
|
+
});
|
|
206
|
+
test('extract hour', async () => {
|
|
207
|
+
const eq = sqlEq('hour(t_timestamp)', '3');
|
|
208
|
+
expect(await eq).isSqlEq();
|
|
209
|
+
});
|
|
210
|
+
test('extract day', async () => {
|
|
211
|
+
const eq = sqlEq('day(t_timestamp)', '24');
|
|
212
|
+
expect(await eq).isSqlEq();
|
|
213
|
+
});
|
|
214
|
+
test('extract day_of_week', async () => {
|
|
215
|
+
const eq = sqlEq('day_of_week(t_timestamp)', '4');
|
|
216
|
+
expect(await eq).isSqlEq();
|
|
217
|
+
});
|
|
218
|
+
test('first week day is one ', async () => {
|
|
219
|
+
const eq = sqlEq('day_of_week(t_timestamp.week)', '1');
|
|
220
|
+
expect(await eq).isSqlEq();
|
|
221
|
+
});
|
|
222
|
+
test('extract day_of_year', async () => {
|
|
223
|
+
const eq = sqlEq('day_of_year(t_timestamp)', '55');
|
|
224
|
+
expect(await eq).isSqlEq();
|
|
225
|
+
});
|
|
226
|
+
test('extract week', async () => {
|
|
227
|
+
const eq = sqlEq('week(t_timestamp)', '8');
|
|
228
|
+
expect(await eq).isSqlEq();
|
|
229
|
+
});
|
|
230
|
+
test('extract month', async () => {
|
|
231
|
+
const eq = sqlEq('month(t_timestamp)', '2');
|
|
232
|
+
expect(await eq).isSqlEq();
|
|
233
|
+
});
|
|
234
|
+
test('extract quarter', async () => {
|
|
235
|
+
const eq = sqlEq('quarter(t_timestamp)', '1');
|
|
236
|
+
expect(await eq).isSqlEq();
|
|
237
|
+
});
|
|
238
|
+
test('extract year', async () => {
|
|
239
|
+
const eq = sqlEq('year(t_timestamp)', '2021');
|
|
240
|
+
expect(await eq).isSqlEq();
|
|
241
|
+
});
|
|
242
|
+
});
|
|
243
|
+
describe('date truncation', () => {
|
|
244
|
+
test('date trunc day', async () => {
|
|
245
|
+
const eq = sqlEq('t_date.day', '@2021-02-24');
|
|
246
|
+
expect(await eq).isSqlEq();
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
test('date trunc week', async () => {
|
|
250
|
+
const eq = sqlEq('t_date.week', '@2021-02-21');
|
|
251
|
+
expect(await eq).isSqlEq();
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
test('date trunc month', async () => {
|
|
255
|
+
const eq = sqlEq('t_date.month', '@2021-02-01');
|
|
256
|
+
expect(await eq).isSqlEq();
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
test('date trunc quarter', async () => {
|
|
260
|
+
const eq = sqlEq('t_date.quarter', '@2021-01-01');
|
|
261
|
+
expect(await eq).isSqlEq();
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
test('date trunc year', async () => {
|
|
265
|
+
const eq = sqlEq('t_date.year', '@2021');
|
|
266
|
+
expect(await eq).isSqlEq();
|
|
267
|
+
});
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
describe('date extraction', () => {
|
|
271
|
+
test('date extract day', async () => {
|
|
272
|
+
const eq = sqlEq('day(t_date)', '24');
|
|
273
|
+
expect(await eq).isSqlEq();
|
|
274
|
+
});
|
|
275
|
+
test('date extract day_of_week', async () => {
|
|
276
|
+
const eq = sqlEq('day_of_week(t_date)', '4');
|
|
277
|
+
expect(await eq).isSqlEq();
|
|
278
|
+
});
|
|
279
|
+
test('date extract day_of_year', async () => {
|
|
280
|
+
const eq = sqlEq('day_of_year(t_date)', '55');
|
|
281
|
+
expect(await eq).isSqlEq();
|
|
282
|
+
});
|
|
283
|
+
test('date extract week', async () => {
|
|
284
|
+
const eq = sqlEq('week(t_date)', '8');
|
|
285
|
+
expect(await eq).isSqlEq();
|
|
286
|
+
});
|
|
287
|
+
test('date extract month', async () => {
|
|
288
|
+
const eq = sqlEq('month(t_date)', '2');
|
|
289
|
+
expect(await eq).isSqlEq();
|
|
290
|
+
});
|
|
291
|
+
test('date extract quarter', async () => {
|
|
292
|
+
const eq = sqlEq('quarter(t_date)', '1');
|
|
293
|
+
expect(await eq).isSqlEq();
|
|
294
|
+
});
|
|
295
|
+
test('date extract year', async () => {
|
|
296
|
+
const eq = sqlEq('year(t_date)', '2021');
|
|
297
|
+
expect(await eq).isSqlEq();
|
|
298
|
+
});
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
describe('delta computations', () => {
|
|
302
|
+
test('timestamp delta second', async () => {
|
|
303
|
+
const eq = sqlEq('t_timestamp + 10 seconds', '@2021-02-24 03:05:16');
|
|
304
|
+
expect(await eq).isSqlEq();
|
|
305
|
+
});
|
|
306
|
+
test('timestamp delta negative second', async () => {
|
|
307
|
+
const eq = sqlEq('t_timestamp - 6 seconds', '@2021-02-24 03:05:00');
|
|
308
|
+
expect(await eq).isSqlEq();
|
|
309
|
+
});
|
|
310
|
+
test('timestamp delta minute', async () => {
|
|
311
|
+
const eq = sqlEq('t_timestamp + 10 minutes', '@2021-02-24 03:15:06');
|
|
312
|
+
expect(await eq).isSqlEq();
|
|
313
|
+
});
|
|
314
|
+
test('timestamp delta hours', async () => {
|
|
315
|
+
const eq = await sqlEq(
|
|
316
|
+
't_timestamp + 10 hours',
|
|
317
|
+
'@2021-02-24 13:05:06'
|
|
318
|
+
);
|
|
319
|
+
expect(eq).isSqlEq();
|
|
320
|
+
});
|
|
321
|
+
test('timestamp delta week', async () => {
|
|
322
|
+
const eq = sqlEq('(t_timestamp - 2 weeks)::date', '@2021-02-10');
|
|
323
|
+
expect(await eq).isSqlEq();
|
|
324
|
+
});
|
|
325
|
+
test('timestamp delta month', async () => {
|
|
326
|
+
const eq = sqlEq('(t_timestamp + 9 months)::date', '@2021-11-24');
|
|
327
|
+
expect(await eq).isSqlEq();
|
|
328
|
+
});
|
|
329
|
+
test('timestamp delta quarter', async () => {
|
|
330
|
+
const eq = sqlEq('(t_timestamp + 2 quarters)::date', '@2021-08-24');
|
|
331
|
+
expect(await eq).isSqlEq();
|
|
332
|
+
});
|
|
333
|
+
test('timestamp delta year', async () => {
|
|
334
|
+
const eq = sqlEq('(t_timestamp + 10 years)::date', '@2031-02-24');
|
|
335
|
+
expect(await eq).isSqlEq();
|
|
336
|
+
});
|
|
337
|
+
test('date delta week', async () => {
|
|
338
|
+
const eq = sqlEq('t_date - 2 weeks', '@2021-02-10');
|
|
339
|
+
expect(await eq).isSqlEq();
|
|
340
|
+
});
|
|
341
|
+
test('date delta month', async () => {
|
|
342
|
+
const eq = sqlEq('t_date + 9 months', '@2021-11-24');
|
|
343
|
+
expect(await eq).isSqlEq();
|
|
344
|
+
});
|
|
345
|
+
test('date delta quarter', async () => {
|
|
346
|
+
const eq = sqlEq('t_date + 2 quarters', '@2021-08-24');
|
|
347
|
+
expect(await eq).isSqlEq();
|
|
348
|
+
});
|
|
349
|
+
test('date delta year', async () => {
|
|
350
|
+
const eq = sqlEq('t_date + 10 years', '@2031-02-24');
|
|
351
|
+
expect(await eq).isSqlEq();
|
|
352
|
+
});
|
|
353
|
+
});
|
|
354
|
+
|
|
355
|
+
describe('for range edge tests', () => {
|
|
356
|
+
describe('date', () => {
|
|
357
|
+
test('before for-range is outside', async () => {
|
|
358
|
+
const eq = sqlEq('t_date ? @2021-02-25 for 1 day', false);
|
|
359
|
+
expect(await eq).isSqlEq();
|
|
360
|
+
});
|
|
361
|
+
test('first for-range is inside', async () => {
|
|
362
|
+
const eq = sqlEq('t_date ? @2021-02-24 for 1 day', true);
|
|
363
|
+
expect(await eq).isSqlEq();
|
|
364
|
+
});
|
|
365
|
+
test('last for-range is outside', async () => {
|
|
366
|
+
const eq = sqlEq('t_date ? @2021-02-23 for 1 day', false);
|
|
367
|
+
expect(await eq).isSqlEq();
|
|
368
|
+
});
|
|
369
|
+
});
|
|
370
|
+
describe('timestamp', () => {
|
|
371
|
+
test('before for-range is outside', async () => {
|
|
372
|
+
const eq = sqlEq(
|
|
373
|
+
't_timestamp ? @2021-02-25 00:00:00 for 1 day',
|
|
374
|
+
false
|
|
375
|
+
);
|
|
376
|
+
expect(await eq).isSqlEq();
|
|
377
|
+
});
|
|
378
|
+
test('first for-range is inside', async () => {
|
|
379
|
+
const eq = sqlEq(
|
|
380
|
+
't_timestamp ? @2021-02-24 03:04:05 for 1 day',
|
|
381
|
+
true
|
|
382
|
+
);
|
|
383
|
+
expect(await eq).isSqlEq();
|
|
384
|
+
});
|
|
385
|
+
test('last for-range is outside', async () => {
|
|
386
|
+
const eq = sqlEq(
|
|
387
|
+
't_timestamp ? @2021-02-23 03:05:06 for 1 day',
|
|
388
|
+
false
|
|
389
|
+
);
|
|
390
|
+
expect(await eq).isSqlEq();
|
|
391
|
+
});
|
|
392
|
+
});
|
|
393
|
+
});
|
|
394
|
+
|
|
395
|
+
describe('to range edge tests', () => {
|
|
396
|
+
describe('date', () => {
|
|
397
|
+
test('before to is outside', async () => {
|
|
398
|
+
const eq = sqlEq('t_date ? @2021-02-25 to @2021-03-01', false);
|
|
399
|
+
expect(await eq).isSqlEq();
|
|
400
|
+
});
|
|
401
|
+
test('first to is inside', async () => {
|
|
402
|
+
const eq = sqlEq('t_date ? @2021-02-24 to @2021-03-01', true);
|
|
403
|
+
expect(await eq).isSqlEq();
|
|
404
|
+
});
|
|
405
|
+
test('last to is outside', async () => {
|
|
406
|
+
const eq = sqlEq('t_date ? @2021-02-01 to @2021-02-24', false);
|
|
407
|
+
expect(await eq).isSqlEq();
|
|
408
|
+
});
|
|
409
|
+
});
|
|
410
|
+
describe('timestamp', () => {
|
|
411
|
+
test('before to is outside', async () => {
|
|
412
|
+
const eq = sqlEq(
|
|
413
|
+
't_timestamp ? @2021-02-25 00:00:00 to @2021-02-26 00:00:00',
|
|
414
|
+
false
|
|
415
|
+
);
|
|
416
|
+
expect(await eq).isSqlEq();
|
|
417
|
+
});
|
|
418
|
+
test('first to is inside', async () => {
|
|
419
|
+
const eq = sqlEq(
|
|
420
|
+
't_timestamp ? @2021-02-24 03:04:05 to @2021-02-26 00:00:00',
|
|
421
|
+
true
|
|
422
|
+
);
|
|
423
|
+
expect(await eq).isSqlEq();
|
|
424
|
+
});
|
|
425
|
+
test('last to is outside', async () => {
|
|
426
|
+
const eq = sqlEq(
|
|
427
|
+
't_timestamp ? @2021-02-24 00:00:00 to @2021-02-24 03:05:06',
|
|
428
|
+
false
|
|
429
|
+
);
|
|
430
|
+
expect(await eq).isSqlEq();
|
|
431
|
+
});
|
|
432
|
+
});
|
|
433
|
+
});
|
|
434
|
+
|
|
435
|
+
test('date in sql_block no explore', async () => {
|
|
436
|
+
const eq = sqlEq('t_date', '@2021-02-24');
|
|
437
|
+
expect(await eq).isSqlEq();
|
|
438
|
+
});
|
|
439
|
+
|
|
440
|
+
test('timestamp in sql_block no explore', async () => {
|
|
441
|
+
const eq = sqlEq('t_timestamp', '@2021-02-24 03:05:06');
|
|
442
|
+
expect(await eq).isSqlEq();
|
|
443
|
+
});
|
|
444
|
+
|
|
445
|
+
test('valid timestamp without seconds', async () => {
|
|
446
|
+
// discovered this writing tests ...
|
|
447
|
+
const eq = sqlEq('year(@2000-01-01 00:00)', '2000');
|
|
448
|
+
expect(await eq).isSqlEq();
|
|
449
|
+
});
|
|
450
|
+
|
|
451
|
+
describe('granular time range checks', () => {
|
|
452
|
+
const tsMoment = '@2021-02-24 03:05:06';
|
|
453
|
+
test('minute implied truncated range', async () => {
|
|
454
|
+
const tsBefore = '@2021-03-24 03:04:59';
|
|
455
|
+
expect(await sqlEq(`${tsMoment} ? t_timestamp.minute`, true)).isSqlEq();
|
|
456
|
+
expect(
|
|
457
|
+
await sqlEq(`${tsBefore} ? t_timestamp.minute`, false)
|
|
458
|
+
).isSqlEq();
|
|
459
|
+
});
|
|
460
|
+
test('day implied truncated range', async () => {
|
|
461
|
+
expect(await sqlEq(`${tsMoment} ? t_timestamp.day`, true)).isSqlEq();
|
|
462
|
+
});
|
|
463
|
+
test('year implied truncated range', async () => {
|
|
464
|
+
expect(await sqlEq(`${tsMoment} ? t_timestamp.year`, true)).isSqlEq();
|
|
465
|
+
});
|
|
466
|
+
test('timestamp in literal minute', async () => {
|
|
467
|
+
expect(await sqlEq('t_timestamp ? @2021-02-24 03:05', true)).isSqlEq();
|
|
468
|
+
});
|
|
469
|
+
test('timestamp in literal day', async () => {
|
|
470
|
+
expect(await sqlEq('t_timestamp ? @2021-02-24', true)).isSqlEq();
|
|
471
|
+
});
|
|
472
|
+
test('date in literal month', async () => {
|
|
473
|
+
expect(await sqlEq('t_date ? @2021-02', true)).isSqlEq();
|
|
474
|
+
});
|
|
475
|
+
test('timestamp in literal month', async () => {
|
|
476
|
+
expect(await sqlEq('t_timestamp ? @2021-02', true)).isSqlEq();
|
|
477
|
+
});
|
|
478
|
+
test('timestamp in literal year', async () => {
|
|
479
|
+
expect(await sqlEq('t_timestamp ? @2021', true)).isSqlEq();
|
|
480
|
+
});
|
|
481
|
+
});
|
|
482
|
+
|
|
483
|
+
test('dependant join dialect fragments', async () => {
|
|
484
|
+
await expect(runtime).queryMatches(
|
|
485
|
+
`
|
|
486
|
+
sql: timeData is { connection: "${dbName}" select: """${timeSQL}""" }
|
|
487
|
+
query: from_sql(timeData) -> {
|
|
488
|
+
join_one: joined is from_sql(timeData) on t_date = joined.t_date
|
|
489
|
+
group_by: t_month is joined.t_timestamp.month
|
|
490
|
+
}
|
|
491
|
+
`,
|
|
492
|
+
{t_month: new Date('2021-02-01')}
|
|
493
|
+
);
|
|
494
|
+
});
|
|
495
|
+
|
|
496
|
+
describe('timezone set correctly', () => {
|
|
497
|
+
test('timezone set in source used by query', async () => {
|
|
498
|
+
expect(
|
|
499
|
+
(
|
|
500
|
+
await runQuery(
|
|
501
|
+
runtime,
|
|
502
|
+
`sql: timeData is { connection: "${dbName}" select: """SELECT 1"""}
|
|
503
|
+
source: timezone is from_sql(timeData) + {
|
|
504
|
+
timezone: 'America/Los_Angeles'
|
|
505
|
+
dimension: la_time is @2021-02-24 03:05:06
|
|
506
|
+
}
|
|
507
|
+
query: timezone -> {
|
|
508
|
+
group_by: la_time
|
|
509
|
+
}
|
|
510
|
+
`
|
|
511
|
+
)
|
|
512
|
+
).resultExplore.queryTimezone
|
|
513
|
+
).toBe('America/Los_Angeles');
|
|
514
|
+
});
|
|
515
|
+
|
|
516
|
+
testIf(runtime.supportsNesting)(
|
|
517
|
+
'timezone set in query inside source',
|
|
518
|
+
async () => {
|
|
519
|
+
expect(
|
|
520
|
+
(
|
|
521
|
+
await runQuery(
|
|
522
|
+
runtime,
|
|
523
|
+
`sql: timeData is { connection: "${dbName}" select: """SELECT 1"""}
|
|
524
|
+
source: timezone is from_sql(timeData) + {
|
|
525
|
+
dimension: default_time is @2021-02-24 03:05:06
|
|
526
|
+
query: la_query is {
|
|
527
|
+
timezone: 'America/Los_Angeles'
|
|
528
|
+
project: la_time is @2021-02-24 03:05:06
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
query: timezone -> {
|
|
533
|
+
group_by: default_time
|
|
534
|
+
nest: la_query
|
|
535
|
+
}
|
|
536
|
+
`
|
|
537
|
+
)
|
|
538
|
+
).resultExplore.structDef
|
|
539
|
+
).toMatchObject({
|
|
540
|
+
fields: [
|
|
541
|
+
{},
|
|
542
|
+
{name: 'la_query', queryTimezone: 'America/Los_Angeles'},
|
|
543
|
+
],
|
|
544
|
+
});
|
|
545
|
+
}
|
|
546
|
+
);
|
|
547
|
+
|
|
548
|
+
testIf(runtime.supportsNesting)(
|
|
549
|
+
'timezone set in query using source',
|
|
550
|
+
async () => {
|
|
551
|
+
expect(
|
|
552
|
+
(
|
|
553
|
+
await runQuery(
|
|
554
|
+
runtime,
|
|
555
|
+
`sql: timeData is { connection: "${dbName}" select: """SELECT 1"""}
|
|
556
|
+
source: timezone is from_sql(timeData) + {
|
|
557
|
+
dimension: default_time is @2021-02-24 03:05:06
|
|
558
|
+
query: undef_query is {
|
|
559
|
+
project: undef_time is @2021-02-24 03:05:06
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
query: timezone -> {
|
|
564
|
+
timezone: 'America/Los_Angeles'
|
|
565
|
+
group_by: default_time
|
|
566
|
+
nest: undef_query
|
|
567
|
+
}
|
|
568
|
+
`
|
|
569
|
+
)
|
|
570
|
+
).resultExplore.queryTimezone
|
|
571
|
+
).toBe('America/Los_Angeles');
|
|
572
|
+
}
|
|
573
|
+
);
|
|
574
|
+
|
|
575
|
+
testIf(runtime.supportsNesting)('multiple timezones', async () => {
|
|
576
|
+
expect(
|
|
577
|
+
(
|
|
578
|
+
await runQuery(
|
|
579
|
+
runtime,
|
|
580
|
+
`sql: timeData is { connection: "${dbName}" select: """SELECT 1"""}
|
|
581
|
+
source: timezone is from_sql(timeData) + {
|
|
582
|
+
timezone: 'America/New_York'
|
|
583
|
+
dimension: ny_time is @2021-02-24 03:05:06
|
|
584
|
+
query: la_query is {
|
|
585
|
+
timezone: 'America/Los_Angeles'
|
|
586
|
+
project: la_time is @2021-02-24 03:05:06
|
|
587
|
+
}
|
|
588
|
+
query: mex_query is {
|
|
589
|
+
timezone: 'America/Mexico_City'
|
|
590
|
+
project: mex_time is @2021-02-24 03:05:06
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
query: timezone -> {
|
|
595
|
+
group_by: ny_time
|
|
596
|
+
nest: la_query, mex_query
|
|
597
|
+
}
|
|
598
|
+
`
|
|
599
|
+
)
|
|
600
|
+
).resultExplore.structDef
|
|
601
|
+
).toMatchObject({
|
|
602
|
+
queryTimezone: 'America/New_York',
|
|
603
|
+
fields: [
|
|
604
|
+
{},
|
|
605
|
+
{name: 'la_query', queryTimezone: 'America/Los_Angeles'},
|
|
606
|
+
{name: 'mex_query', queryTimezone: 'America/Mexico_City'},
|
|
607
|
+
],
|
|
608
|
+
});
|
|
609
|
+
});
|
|
610
|
+
});
|
|
611
|
+
});
|
|
612
|
+
|
|
613
|
+
/*
|
|
614
|
+
not entirely sure what to test here so i am going to free-wheel a bit
|
|
615
|
+
|
|
616
|
+
1) All of the extraction and truncation functions need to work
|
|
617
|
+
in the query timezone.
|
|
618
|
+
2) All rendering needs to happen in the query time zone
|
|
619
|
+
3) If we feed rendered data back into a query, it needs to retain
|
|
620
|
+
offsets on all timestamps. Worried that rendering it in the query
|
|
621
|
+
time zone would somehow confuse bigquery which is always in UTC
|
|
622
|
+
4) when we filter on a binned time, that we generate a filter between
|
|
623
|
+
the edges of the bin, instead of computing the bin and use '='
|
|
624
|
+
5) connection, model, and query time zone setting
|
|
625
|
+
6) piping a query in one time zone into a query in another
|
|
626
|
+
7) graphs neeed to respect query time zone
|
|
627
|
+
*/
|
|
628
|
+
|
|
629
|
+
const zone = 'America/Mexico_City'; // -06:00 no DST
|
|
630
|
+
const zone_2020 = LuxonDateTime.fromObject({
|
|
631
|
+
year: 2020,
|
|
632
|
+
month: 2,
|
|
633
|
+
day: 20,
|
|
634
|
+
hour: 0,
|
|
635
|
+
minute: 0,
|
|
636
|
+
second: 0,
|
|
637
|
+
zone,
|
|
638
|
+
});
|
|
639
|
+
const utc_2020 = LuxonDateTime.fromObject({
|
|
640
|
+
year: 2020,
|
|
641
|
+
month: 2,
|
|
642
|
+
day: 20,
|
|
643
|
+
hour: 0,
|
|
644
|
+
minute: 0,
|
|
645
|
+
second: 0,
|
|
646
|
+
zone: 'UTC',
|
|
647
|
+
});
|
|
648
|
+
|
|
649
|
+
describe.each(runtimes.runtimeList)('%s: tz literals', (dbName, runtime) => {
|
|
650
|
+
test(`${dbName} - default timezone is UTC`, async () => {
|
|
651
|
+
// this makes sure that the tests which use the test timezome are actually
|
|
652
|
+
// testing something ... file this under "abundance of caution". It
|
|
653
|
+
// really tests nothing, but I feel calmer with this here.
|
|
654
|
+
const query = runtime.loadQuery(
|
|
655
|
+
`
|
|
656
|
+
sql: tzTest is { connection: "${dbName}" select: """SELECT 1 as one""" }
|
|
657
|
+
query: from_sql(tzTest) -> {
|
|
658
|
+
group_by: literalTime is @2020-02-20 00:00:00
|
|
659
|
+
}
|
|
660
|
+
`
|
|
661
|
+
);
|
|
662
|
+
const result = await query.run();
|
|
663
|
+
const literal = result.data.path(0, 'literalTime').value as Date;
|
|
664
|
+
const have = LuxonDateTime.fromJSDate(literal);
|
|
665
|
+
expect(have.valueOf()).toEqual(utc_2020.valueOf());
|
|
666
|
+
});
|
|
667
|
+
|
|
668
|
+
test('literal with zone name', async () => {
|
|
669
|
+
const query = runtime.loadQuery(
|
|
670
|
+
`
|
|
671
|
+
sql: tzTest is { connection: "${dbName}" select: """SELECT 1 as one""" }
|
|
672
|
+
query: from_sql(tzTest) -> {
|
|
673
|
+
group_by: literalTime is @2020-02-20 00:00:00[America/Mexico_City]
|
|
674
|
+
}
|
|
675
|
+
`
|
|
676
|
+
);
|
|
677
|
+
const result = await query.run();
|
|
678
|
+
const literal = result.data.path(0, 'literalTime').value as Date;
|
|
679
|
+
const have = LuxonDateTime.fromJSDate(literal);
|
|
680
|
+
expect(have.valueOf()).toEqual(zone_2020.valueOf());
|
|
681
|
+
});
|
|
682
|
+
});
|
|
683
|
+
|
|
684
|
+
describe.each(runtimes.runtimeList)('%s: query tz', (dbName, runtime) => {
|
|
685
|
+
test('literal timestamps', async () => {
|
|
686
|
+
const query = runtime.loadQuery(
|
|
687
|
+
`
|
|
688
|
+
sql: tzTest is { connection: "${dbName}" select: """SELECT 1 as one""" }
|
|
689
|
+
query: from_sql(tzTest) -> {
|
|
690
|
+
timezone: '${zone}'
|
|
691
|
+
group_by: literalTime is @2020-02-20 00:00:00
|
|
692
|
+
}
|
|
693
|
+
`
|
|
694
|
+
);
|
|
695
|
+
const result = await query.run();
|
|
696
|
+
const literal = result.data.path(0, 'literalTime').value as Date;
|
|
697
|
+
const have = LuxonDateTime.fromJSDate(literal);
|
|
698
|
+
expect(have.valueOf()).toEqual(zone_2020.valueOf());
|
|
699
|
+
});
|
|
700
|
+
|
|
701
|
+
test('extract', async () => {
|
|
702
|
+
await expect(runtime).queryMatches(
|
|
703
|
+
`sql: tzTest is { connection: "${dbName}" select: """SELECT 1 as one""" }
|
|
704
|
+
query: from_sql(tzTest) -> {
|
|
705
|
+
timezone: '${zone}'
|
|
706
|
+
declare: utc_midnight is @2020-02-20 00:00:00[UTC]
|
|
707
|
+
project:
|
|
708
|
+
mex_midnight is hour(utc_midnight)
|
|
709
|
+
mex_day is day(utc_midnight)
|
|
710
|
+
}`,
|
|
711
|
+
{mex_midnight: 18, mex_day: 19}
|
|
712
|
+
);
|
|
713
|
+
});
|
|
714
|
+
|
|
715
|
+
test('truncate day', async () => {
|
|
716
|
+
// At midnight in london it the 19th in Mexico, so that truncates to
|
|
717
|
+
// midnight on the 19th
|
|
718
|
+
const mex_19 = LuxonDateTime.fromISO('2020-02-19T00:00:00', {zone});
|
|
719
|
+
await expect(runtime).queryMatches(
|
|
720
|
+
`sql: tzTest is { connection: "${dbName}" select: """SELECT 1 as one""" }
|
|
721
|
+
query: from_sql(tzTest) -> {
|
|
722
|
+
timezone: '${zone}'
|
|
723
|
+
declare: utc_midnight is @2020-02-20 00:00:00[UTC]
|
|
724
|
+
project:
|
|
725
|
+
mex_day is utc_midnight.day
|
|
726
|
+
}`,
|
|
727
|
+
{mex_day: mex_19.toJSDate()}
|
|
728
|
+
);
|
|
729
|
+
});
|
|
730
|
+
|
|
731
|
+
test('cast timestamp to date', async () => {
|
|
732
|
+
// At midnight in london it the 19th in Mexico, so when we cast that
|
|
733
|
+
// to a date, it should be the 19th.
|
|
734
|
+
await expect(runtime).queryMatches(
|
|
735
|
+
`sql: tzTest is { connection: "${dbName}" select: """SELECT 1 as one""" }
|
|
736
|
+
query: from_sql(tzTest) -> {
|
|
737
|
+
timezone: '${zone}'
|
|
738
|
+
declare: utc_midnight is @2020-02-20 00:00:00[UTC]
|
|
739
|
+
project: mex_day is day(utc_midnight::date)
|
|
740
|
+
}`,
|
|
741
|
+
{mex_day: 19}
|
|
742
|
+
);
|
|
743
|
+
});
|
|
744
|
+
|
|
745
|
+
test('cast date to timestamp', async () => {
|
|
746
|
+
await expect(runtime).queryMatches(
|
|
747
|
+
`sql: tzTest is { connection: "${dbName}" select: """
|
|
748
|
+
SELECT DATE '2020-02-20' AS mex_20
|
|
749
|
+
""" }
|
|
750
|
+
query: from_sql(tzTest) -> {
|
|
751
|
+
timezone: '${zone}'
|
|
752
|
+
project: mex_ts is mex_20::timestamp
|
|
753
|
+
}`,
|
|
754
|
+
{mex_ts: zone_2020.toJSDate()}
|
|
755
|
+
);
|
|
756
|
+
});
|
|
757
|
+
|
|
758
|
+
test('can use unsupported types', async () => {
|
|
759
|
+
if (dbName === 'bigquery') {
|
|
760
|
+
await expect(runtime).queryMatches(
|
|
761
|
+
`sql: timeData is { connection: "${dbName}" select: """
|
|
762
|
+
SELECT DATETIME '2020-02-20 00:00:00' as t_datetime
|
|
763
|
+
"""}
|
|
764
|
+
query: from_sql(timeData) -> {
|
|
765
|
+
project: mex_220 is t_datetime::timestamp
|
|
766
|
+
}`,
|
|
767
|
+
{mex_220: utc_2020.toJSDate()}
|
|
768
|
+
);
|
|
769
|
+
} else if (dbName === 'duckdb' || dbName === 'postgres') {
|
|
770
|
+
await expect(runtime).queryMatches(
|
|
771
|
+
`sql: timeData is { connection: "duckdb" select: """
|
|
772
|
+
SELECT TIMESTAMPTZ '2020-02-20 00:00:00 ${zone}' as t_tstz
|
|
773
|
+
"""}
|
|
774
|
+
query: from_sql(timeData) -> {
|
|
775
|
+
project: mex_220 is t_tstz::timestamp
|
|
776
|
+
}`,
|
|
777
|
+
{mex_220: zone_2020.toJSDate()}
|
|
778
|
+
);
|
|
779
|
+
}
|
|
780
|
+
});
|
|
781
|
+
});
|
|
782
|
+
|
|
783
|
+
afterAll(async () => {
|
|
784
|
+
await runtimes.closeAll();
|
|
785
|
+
});
|
|
786
|
+
};
|
|
787
|
+
|
|
788
|
+
const runtimes = new RuntimeList(allDatabases);
|
|
789
|
+
/*
|
|
790
|
+
* This test file reuses common tests definitions.
|
|
791
|
+
* For actual test development please go to: test/src/databases/shared/time.spec.ts
|
|
792
|
+
*/
|
|
793
|
+
timeSharedTests(runtimes);
|