@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.
Files changed (169) hide show
  1. package/README.md +29 -0
  2. package/bin/dump_malloytest.sh +1 -0
  3. package/bin/postgres_init.sh +9 -0
  4. package/bin/postgres_start.sh +2 -0
  5. package/bin/postgres_stop.sh +2 -0
  6. package/data/duckdb/README.md +4 -0
  7. package/data/duckdb/aircraft.parquet +0 -0
  8. package/data/duckdb/aircraft_models.parquet +0 -0
  9. package/data/duckdb/airports.parquet +0 -0
  10. package/data/duckdb/alltypes.parquet +0 -0
  11. package/data/duckdb/alltypes2.parquet +0 -0
  12. package/data/duckdb/bq_medicare_test.parquet +0 -0
  13. package/data/duckdb/carriers.parquet +0 -0
  14. package/data/duckdb/flights/part.0.parquet +0 -0
  15. package/data/duckdb/flights/part.1.parquet +0 -0
  16. package/data/duckdb/flights/part.2.parquet +0 -0
  17. package/data/duckdb/flights.parquet +0 -0
  18. package/data/duckdb/flights_partitioned.parquet +0 -0
  19. package/data/duckdb/ga_sample.parquet +0 -0
  20. package/data/duckdb/numbers.parquet +0 -0
  21. package/data/duckdb/state_facts.parquet +0 -0
  22. package/data/duckdb/test.json +3 -0
  23. package/data/duckdb/words.parquet +0 -0
  24. package/data/duckdb/words_bigger.parquet +0 -0
  25. package/data/postgres/malloytest-postgres.sql.gz +0 -0
  26. package/data/postgres/state_facts.sql +366 -0
  27. package/dist/api.spec.d.ts +1 -0
  28. package/dist/api.spec.js +77 -0
  29. package/dist/api.spec.js.map +1 -0
  30. package/dist/databases/all/expr.spec.d.ts +3 -0
  31. package/dist/databases/all/expr.spec.js +581 -0
  32. package/dist/databases/all/expr.spec.js.map +1 -0
  33. package/dist/databases/all/functions.spec.d.ts +2 -0
  34. package/dist/databases/all/functions.spec.js +784 -0
  35. package/dist/databases/all/functions.spec.js.map +1 -0
  36. package/dist/databases/all/index.spec.d.ts +2 -0
  37. package/dist/databases/all/index.spec.js +154 -0
  38. package/dist/databases/all/index.spec.js.map +1 -0
  39. package/dist/databases/all/join.spec.d.ts +2 -0
  40. package/dist/databases/all/join.spec.js +309 -0
  41. package/dist/databases/all/join.spec.js.map +1 -0
  42. package/dist/databases/all/nomodel.spec.d.ts +2 -0
  43. package/dist/databases/all/nomodel.spec.js +957 -0
  44. package/dist/databases/all/nomodel.spec.js.map +1 -0
  45. package/dist/databases/all/orderby.spec.d.ts +2 -0
  46. package/dist/databases/all/orderby.spec.js +224 -0
  47. package/dist/databases/all/orderby.spec.js.map +1 -0
  48. package/dist/databases/all/problems.spec.d.ts +2 -0
  49. package/dist/databases/all/problems.spec.js +113 -0
  50. package/dist/databases/all/problems.spec.js.map +1 -0
  51. package/dist/databases/all/sql_expressions.spec.d.ts +2 -0
  52. package/dist/databases/all/sql_expressions.spec.js +96 -0
  53. package/dist/databases/all/sql_expressions.spec.js.map +1 -0
  54. package/dist/databases/all/time.spec.d.ts +3 -0
  55. package/dist/databases/all/time.spec.js +647 -0
  56. package/dist/databases/all/time.spec.js.map +1 -0
  57. package/dist/databases/bigquery/double_truncation.spec.d.ts +1 -0
  58. package/dist/databases/bigquery/double_truncation.spec.js +50 -0
  59. package/dist/databases/bigquery/double_truncation.spec.js.map +1 -0
  60. package/dist/databases/bigquery/handexpr.spec.d.ts +1 -0
  61. package/dist/databases/bigquery/handexpr.spec.js +713 -0
  62. package/dist/databases/bigquery/handexpr.spec.js.map +1 -0
  63. package/dist/databases/bigquery/injestion_time_partitioning.spec.d.ts +1 -0
  64. package/dist/databases/bigquery/injestion_time_partitioning.spec.js +235 -0
  65. package/dist/databases/bigquery/injestion_time_partitioning.spec.js.map +1 -0
  66. package/dist/databases/bigquery/joined_filters.spec.d.ts +1 -0
  67. package/dist/databases/bigquery/joined_filters.spec.js +72 -0
  68. package/dist/databases/bigquery/joined_filters.spec.js.map +1 -0
  69. package/dist/databases/bigquery/json.spec.d.ts +1 -0
  70. package/dist/databases/bigquery/json.spec.js +86 -0
  71. package/dist/databases/bigquery/json.spec.js.map +1 -0
  72. package/dist/databases/bigquery/malloy_query.spec.d.ts +1 -0
  73. package/dist/databases/bigquery/malloy_query.spec.js +906 -0
  74. package/dist/databases/bigquery/malloy_query.spec.js.map +1 -0
  75. package/dist/databases/bigquery/performance.skipped.spec.d.ts +1 -0
  76. package/dist/databases/bigquery/performance.skipped.spec.js +70 -0
  77. package/dist/databases/bigquery/performance.skipped.spec.js.map +1 -0
  78. package/dist/databases/bigquery/time.spec.d.ts +1 -0
  79. package/dist/databases/bigquery/time.spec.js +55 -0
  80. package/dist/databases/bigquery/time.spec.js.map +1 -0
  81. package/dist/databases/bigquery/wildcard_table_names.spec.d.ts +1 -0
  82. package/dist/databases/bigquery/wildcard_table_names.spec.js +212 -0
  83. package/dist/databases/bigquery/wildcard_table_names.spec.js.map +1 -0
  84. package/dist/databases/bigquery-duckdb/nested_source_table.spec.d.ts +1 -0
  85. package/dist/databases/bigquery-duckdb/nested_source_table.spec.js +247 -0
  86. package/dist/databases/bigquery-duckdb/nested_source_table.spec.js.map +1 -0
  87. package/dist/databases/bigquery-postgres/multi_connection.spec.d.ts +1 -0
  88. package/dist/databases/bigquery-postgres/multi_connection.spec.js +138 -0
  89. package/dist/databases/bigquery-postgres/multi_connection.spec.js.map +1 -0
  90. package/dist/databases/bigquery-postgres/streaming.spec.d.ts +1 -0
  91. package/dist/databases/bigquery-postgres/streaming.spec.js +88 -0
  92. package/dist/databases/bigquery-postgres/streaming.spec.js.map +1 -0
  93. package/dist/databases/duckdb/duckdb.spec.d.ts +1 -0
  94. package/dist/databases/duckdb/duckdb.spec.js +116 -0
  95. package/dist/databases/duckdb/duckdb.spec.js.map +1 -0
  96. package/dist/databases/postgres/postgres.spec.d.ts +1 -0
  97. package/dist/databases/postgres/postgres.spec.js +137 -0
  98. package/dist/databases/postgres/postgres.spec.js.map +1 -0
  99. package/dist/databases/shared/test_list.d.ts +3 -0
  100. package/dist/databases/shared/test_list.js +24 -0
  101. package/dist/databases/shared/test_list.js.map +1 -0
  102. package/dist/dependencies.spec.d.ts +1 -0
  103. package/dist/dependencies.spec.js +63 -0
  104. package/dist/dependencies.spec.js.map +1 -0
  105. package/dist/index.d.ts +11 -0
  106. package/dist/index.js +49 -0
  107. package/dist/index.js.map +1 -0
  108. package/dist/model/utils.spec.d.ts +1 -0
  109. package/dist/model/utils.spec.js +38 -0
  110. package/dist/model/utils.spec.js.map +1 -0
  111. package/dist/models/faa_model.d.ts +5 -0
  112. package/dist/models/faa_model.js +977 -0
  113. package/dist/models/faa_model.js.map +1 -0
  114. package/dist/models/medicare_model.d.ts +4 -0
  115. package/dist/models/medicare_model.js +243 -0
  116. package/dist/models/medicare_model.js.map +1 -0
  117. package/dist/render/render.spec.d.ts +1 -0
  118. package/dist/render/render.spec.js +551 -0
  119. package/dist/render/render.spec.js.map +1 -0
  120. package/dist/runtimes.d.ts +33 -0
  121. package/dist/runtimes.js +147 -0
  122. package/dist/runtimes.js.map +1 -0
  123. package/dist/tags.spec.d.ts +1 -0
  124. package/dist/tags.spec.js +259 -0
  125. package/dist/tags.spec.js.map +1 -0
  126. package/dist/util/db-jest-matchers.d.ts +19 -0
  127. package/dist/util/db-jest-matchers.js +90 -0
  128. package/dist/util/db-jest-matchers.js.map +1 -0
  129. package/dist/util/index.d.ts +16 -0
  130. package/dist/util/index.js +171 -0
  131. package/dist/util/index.js.map +1 -0
  132. package/package.json +35 -0
  133. package/src/api.spec.ts +84 -0
  134. package/src/databases/all/expr.spec.ts +704 -0
  135. package/src/databases/all/functions.spec.ts +1135 -0
  136. package/src/databases/all/index.spec.ts +178 -0
  137. package/src/databases/all/join.spec.ts +350 -0
  138. package/src/databases/all/nomodel.spec.ts +1159 -0
  139. package/src/databases/all/orderby.spec.ts +268 -0
  140. package/src/databases/all/problems.spec.ts +121 -0
  141. package/src/databases/all/sql_expressions.spec.ts +107 -0
  142. package/src/databases/all/time.spec.ts +793 -0
  143. package/src/databases/bigquery/double_truncation.spec.ts +51 -0
  144. package/src/databases/bigquery/handexpr.spec.ts +782 -0
  145. package/src/databases/bigquery/injestion_time_partitioning.spec.ts +268 -0
  146. package/src/databases/bigquery/joined_filters.spec.ts +75 -0
  147. package/src/databases/bigquery/json.spec.ts +95 -0
  148. package/src/databases/bigquery/malloy_query.spec.ts +1036 -0
  149. package/src/databases/bigquery/performance.skipped.spec.ts +73 -0
  150. package/src/databases/bigquery/time.spec.ts +59 -0
  151. package/src/databases/bigquery/wildcard_table_names.spec.ts +233 -0
  152. package/src/databases/bigquery-duckdb/nested_source_table.spec.ts +268 -0
  153. package/src/databases/bigquery-postgres/multi_connection.spec.ts +143 -0
  154. package/src/databases/bigquery-postgres/streaming.spec.ts +100 -0
  155. package/src/databases/duckdb/duckdb.spec.ts +131 -0
  156. package/src/databases/postgres/postgres.spec.ts +167 -0
  157. package/src/databases/shared/test_list.ts +24 -0
  158. package/src/dependencies.spec.ts +62 -0
  159. package/src/index.ts +36 -0
  160. package/src/model/utils.spec.ts +37 -0
  161. package/src/models/faa_model.ts +995 -0
  162. package/src/models/medicare_model.ts +246 -0
  163. package/src/render/__snapshots__/render.spec.ts.snap +12574 -0
  164. package/src/render/render.spec.ts +670 -0
  165. package/src/runtimes.ts +182 -0
  166. package/src/tags.spec.ts +277 -0
  167. package/src/util/db-jest-matchers.ts +128 -0
  168. package/src/util/index.ts +191 -0
  169. package/tsconfig.json +25 -0
@@ -0,0 +1,268 @@
1
+ /*
2
+ * Copyright 2023 Google LLC
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining
5
+ * a copy of this software and associated documentation files
6
+ * (the "Software"), to deal in the Software without restriction,
7
+ * including without limitation the rights to use, copy, modify, merge,
8
+ * publish, distribute, sublicense, and/or sell copies of the Software,
9
+ * and to permit persons to whom the Software is furnished to do so,
10
+ * subject to the following conditions:
11
+ *
12
+ * The above copyright notice and this permission notice shall be
13
+ * included in all copies or substantial portions of the Software.
14
+ *
15
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ */
23
+
24
+ import {RuntimeList} from '../../runtimes';
25
+ import {describeIfDatabaseAvailable} from '../../util';
26
+
27
+ const [describe, databases] = describeIfDatabaseAvailable(['bigquery']);
28
+ describe('Wildcard BigQuery Tables', () => {
29
+ const runtimes = new RuntimeList(databases);
30
+
31
+ afterAll(async () => {
32
+ await runtimes.closeAll();
33
+ });
34
+
35
+ test('test ITP-hourly table name using _PARTITIONTIME', async () => {
36
+ const runtime = runtimes.runtimeMap.get('bigquery');
37
+ expect(runtime).toBeDefined();
38
+ if (runtime) {
39
+ const result = await runtime
40
+ .loadQuery(
41
+ `
42
+ source: aircraft is table('malloy-data.malloytest.itp_hourly_aircraft') {
43
+ primary_key: id
44
+ measure: aircraft_count is count()
45
+ where: _PARTITIONTIME = @2023-03-06 17:00:00 to @2023-03-06 19:00:00
46
+ }
47
+
48
+ query: aircraft -> {
49
+ aggregate: aircraft_count
50
+ }
51
+ `
52
+ )
53
+ .run();
54
+ expect(result.data.value[0]['aircraft_count']).toBe(9);
55
+ }
56
+ });
57
+
58
+ test('test ITP-daily table name using _PARTITIONTIME', async () => {
59
+ const runtime = runtimes.runtimeMap.get('bigquery');
60
+ expect(runtime).toBeDefined();
61
+ if (runtime) {
62
+ const result = await runtime
63
+ .loadQuery(
64
+ `
65
+ source: aircraft is table('malloy-data.malloytest.itp_daily_aircraft') {
66
+ primary_key: id
67
+ measure: aircraft_count is count()
68
+ where: _PARTITIONTIME = @2023-03-06 00:00:00
69
+ }
70
+
71
+ query: aircraft -> {
72
+ aggregate: aircraft_count
73
+ }
74
+ `
75
+ )
76
+ .run();
77
+ expect(result.data.value[0]['aircraft_count']).toBe(5);
78
+
79
+ const empty_result = await runtime
80
+ .loadQuery(
81
+ `
82
+ source: aircraft is table('malloy-data.malloytest.itp_daily_aircraft') {
83
+ primary_key: id
84
+ measure: aircraft_count is count()
85
+ where: _PARTITIONTIME = @2023-03-06 00:00:01
86
+ }
87
+
88
+ query: aircraft -> {
89
+ aggregate: aircraft_count
90
+ }
91
+ `
92
+ )
93
+ .run();
94
+ expect(empty_result.data.value[0]['aircraft_count']).toBe(0);
95
+ }
96
+ });
97
+
98
+ test('test ITP-monthly table name using _PARTITIONTIME', async () => {
99
+ const runtime = runtimes.runtimeMap.get('bigquery');
100
+ expect(runtime).toBeDefined();
101
+ if (runtime) {
102
+ const result = await runtime
103
+ .loadQuery(
104
+ `
105
+ source: aircraft is table('malloy-data.malloytest.itp_monthly_aircraft') {
106
+ primary_key: id
107
+ measure: aircraft_count is count()
108
+ where: _PARTITIONTIME = @2023-03-01 00:00:00
109
+ }
110
+
111
+ query: aircraft -> {
112
+ aggregate: aircraft_count
113
+ }
114
+ `
115
+ )
116
+ .run();
117
+ expect(result.data.value[0]['aircraft_count']).toBe(5);
118
+
119
+ const empty_result = await runtime
120
+ .loadQuery(
121
+ `
122
+ source: aircraft is table('malloy-data.malloytest.itp_monthly_aircraft') {
123
+ primary_key: id
124
+ measure: aircraft_count is count()
125
+ where: _PARTITIONTIME = @2023-03-01 00:00:01
126
+ }
127
+
128
+ query: aircraft -> {
129
+ aggregate: aircraft_count
130
+ }
131
+ `
132
+ )
133
+ .run();
134
+ expect(empty_result.data.value[0]['aircraft_count']).toBe(0);
135
+ }
136
+ });
137
+
138
+ test('test ITP-hourly table name using _PARTITIONTIME as a group-by key', async () => {
139
+ const runtime = runtimes.runtimeMap.get('bigquery');
140
+ expect(runtime).toBeDefined();
141
+ if (runtime) {
142
+ const result = await runtime
143
+ .loadQuery(
144
+ `
145
+ source: aircraft is table('malloy-data.malloytest.itp_hourly_aircraft') {
146
+ primary_key: id
147
+ measure: aircraft_count is count()
148
+ where: _PARTITIONTIME = @2023-03-06 17:00:00 to @2023-03-06 19:00:00
149
+ }
150
+ source: state_facts is table('malloy-data.malloytest.state_facts') {
151
+ join_many: aircraft on state = aircraft.state
152
+ }
153
+ query: state_facts -> {
154
+ group_by: aircraft.state
155
+ aggregate: aircraft_count is aircraft.count()
156
+ order_by: 1
157
+ }
158
+ `
159
+ )
160
+ .run();
161
+ expect(result.data.value).toStrictEqual([
162
+ {state: null, aircraft_count: 43},
163
+ {state: 'IA', aircraft_count: 1},
164
+ {state: 'KS', aircraft_count: 1},
165
+ {state: 'LA', aircraft_count: 1},
166
+ {state: 'MO', aircraft_count: 1},
167
+ {state: 'NH', aircraft_count: 1},
168
+ {state: 'OK', aircraft_count: 1},
169
+ {state: 'OR', aircraft_count: 2},
170
+ {state: 'TX', aircraft_count: 1},
171
+ ]);
172
+ }
173
+ });
174
+
175
+ test('test ITP-hourly table name using _PARTITIONTIME as a group-by key and a filter', async () => {
176
+ const runtime = runtimes.runtimeMap.get('bigquery');
177
+ expect(runtime).toBeDefined();
178
+ if (runtime) {
179
+ const result = await runtime
180
+ .loadQuery(
181
+ `
182
+ source: aircraft is table('malloy-data.malloytest.itp_hourly_aircraft') {
183
+ primary_key: id
184
+ measure: aircraft_count is count()
185
+ where: _PARTITIONTIME = @2023-03-06 17:00:00 to @2023-03-06 19:00:00
186
+ }
187
+ source: state_facts is table('malloy-data.malloytest.state_facts') {
188
+ join_many: aircraft on state = aircraft.state
189
+ }
190
+ query: state_facts -> {
191
+ group_by: aircraft.state
192
+ aggregate: aircraft_count is aircraft.count()
193
+ where: aircraft._PARTITIONTIME = @2023-03-06 18:00:00
194
+ order_by: 1
195
+ }
196
+ `
197
+ )
198
+ .run();
199
+ expect(result.data.value).toStrictEqual([
200
+ {state: 'KS', aircraft_count: 1},
201
+ {state: 'LA', aircraft_count: 1},
202
+ {state: 'OK', aircraft_count: 1},
203
+ {state: 'OR', aircraft_count: 1},
204
+ ]);
205
+ }
206
+ });
207
+
208
+ test('test ITP-daily table name using _PARTITIONDATE', async () => {
209
+ const runtime = runtimes.runtimeMap.get('bigquery');
210
+ expect(runtime).toBeDefined();
211
+ if (runtime) {
212
+ const result = await runtime
213
+ .loadQuery(
214
+ `
215
+ source: aircraft is table('malloy-data.malloytest.itp_daily_aircraft') {
216
+ primary_key: id
217
+ measure: aircraft_count is count()
218
+ where: _PARTITIONDATE = @2023-03-06
219
+ }
220
+ query: aircraft -> {
221
+ aggregate: aircraft_count
222
+ }
223
+ `
224
+ )
225
+ .run();
226
+ expect(result.data.value[0]['aircraft_count']).toBe(5);
227
+ }
228
+ });
229
+
230
+ test('test ITP-hourly/monthly table name using _PARTITIONDATE', async () => {
231
+ const runtime = runtimes.runtimeMap.get('bigquery');
232
+ expect(runtime).toBeDefined();
233
+ if (runtime) {
234
+ await expect(
235
+ runtime
236
+ .loadQuery(
237
+ `
238
+ source: aircraft is table('malloy-data.malloytest.itp_hourly_aircraft') {
239
+ primary_key: id
240
+ measure: aircraft_count is count()
241
+ where: _PARTITIONDATE = @2023-03-06
242
+ }
243
+ query: aircraft -> {
244
+ aggregate: aircraft_count
245
+ }
246
+ `
247
+ )
248
+ .run()
249
+ ).rejects.toThrow('_PARTITIONDATE');
250
+ await expect(
251
+ runtime
252
+ .loadQuery(
253
+ `
254
+ source: aircraft is table('malloy-data.malloytest.itp_monthly_aircraft') {
255
+ primary_key: id
256
+ measure: aircraft_count is count()
257
+ where: _PARTITIONDATE = @2023-03-06
258
+ }
259
+ query: aircraft -> {
260
+ aggregate: aircraft_count
261
+ }
262
+ `
263
+ )
264
+ .run()
265
+ ).rejects.toThrow('_PARTITIONDATE');
266
+ }
267
+ });
268
+ });
@@ -0,0 +1,75 @@
1
+ /*
2
+ * Copyright 2023 Google LLC
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining
5
+ * a copy of this software and associated documentation files
6
+ * (the "Software"), to deal in the Software without restriction,
7
+ * including without limitation the rights to use, copy, modify, merge,
8
+ * publish, distribute, sublicense, and/or sell copies of the Software,
9
+ * and to permit persons to whom the Software is furnished to do so,
10
+ * subject to the following conditions:
11
+ *
12
+ * The above copyright notice and this permission notice shall be
13
+ * included in all copies or substantial portions of the Software.
14
+ *
15
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ */
23
+
24
+ import {RuntimeList} from '../../runtimes';
25
+ import {describeIfDatabaseAvailable} from '../../util';
26
+
27
+ function sourceCodeWithFilter(filter: string) {
28
+ return `
29
+ source: aircraft_models is table('malloy-data.faa.aircraft_models') {
30
+ primary_key: aircraft_model_code
31
+ where: ${filter}
32
+ }
33
+
34
+ source: aircraft is table('malloy-data.faa.aircraft') {
35
+ primary_key: tail_num
36
+ measure: aircraft_count is count()
37
+ join_one: aircraft_models with aircraft_model_code
38
+ }
39
+
40
+ query: aircraft -> {
41
+ group_by: aircraft_models.aircraft_model_code
42
+ }
43
+ `;
44
+ }
45
+
46
+ const [describe, databases] = describeIfDatabaseAvailable(['bigquery']);
47
+ describe('Joined filters', () => {
48
+ const runtimes = new RuntimeList(databases);
49
+
50
+ afterAll(async () => {
51
+ await runtimes.closeAll();
52
+ });
53
+
54
+ test('work with comma', async () => {
55
+ const runtime = runtimes.runtimeMap.get('bigquery');
56
+ expect(runtime).toBeDefined();
57
+ if (runtime) {
58
+ const src = sourceCodeWithFilter('1 = 1, 2 = 2');
59
+ const result = await runtime.loadQuery(src).run();
60
+ expect(result.sql).toContain('1=1');
61
+ expect(result.sql).toContain('2=2');
62
+ }
63
+ });
64
+
65
+ test('work with and', async () => {
66
+ const runtime = runtimes.runtimeMap.get('bigquery');
67
+ expect(runtime).toBeDefined();
68
+ if (runtime) {
69
+ const src = sourceCodeWithFilter('1 = 1 and 2 = 2');
70
+ const result = await runtime.loadQuery(src).run();
71
+ expect(result.sql).toContain('1=1');
72
+ expect(result.sql).toContain('2=2');
73
+ }
74
+ });
75
+ });
@@ -0,0 +1,95 @@
1
+ /*
2
+ * Copyright 2023 Google LLC
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining
5
+ * a copy of this software and associated documentation files
6
+ * (the "Software"), to deal in the Software without restriction,
7
+ * including without limitation the rights to use, copy, modify, merge,
8
+ * publish, distribute, sublicense, and/or sell copies of the Software,
9
+ * and to permit persons to whom the Software is furnished to do so,
10
+ * subject to the following conditions:
11
+ *
12
+ * The above copyright notice and this permission notice shall be
13
+ * included in all copies or substantial portions of the Software.
14
+ *
15
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ */
23
+
24
+ /* eslint-disable no-console */
25
+
26
+ import {describeIfDatabaseAvailable} from '../../util';
27
+ import {RuntimeList} from '../../runtimes';
28
+
29
+ const [describe] = describeIfDatabaseAvailable(['bigquery']);
30
+
31
+ const modelString = `
32
+ sql: source_sql is {
33
+ select: """
34
+ SELECT *
35
+ FROM UNNEST([
36
+ STRUCT( JSON '{"class_name": "A", "class" : {"students" : [{"name" : "Jane"}]}}' as j, 1 as r),
37
+ STRUCT( JSON '{"class_name": "B", "class" : {"students" : []}}', 2),
38
+ STRUCT( JSON '{"class_name": "C", "class" : {"students" : [{"name" : "John"}, {"name": "Jamie"}]}}', 3)
39
+ ]) AS t
40
+ """
41
+ connection: "bigquery"
42
+ }
43
+
44
+ source: s is from_sql(source_sql) {
45
+
46
+ }
47
+
48
+ `;
49
+
50
+ describe('JSON tests', () => {
51
+ const runtimes = new RuntimeList(['bigquery']);
52
+
53
+ afterAll(async () => {
54
+ await runtimes.closeAll();
55
+ });
56
+
57
+ runtimes.runtimeMap.forEach((runtime, databaseName) => {
58
+ // Issue: #151
59
+ it(`JSON Scalar - ${databaseName}`, async () => {
60
+ //it(`model: do filters force dependant joins? - ${databaseName}`, async () => {
61
+ const result = await runtime
62
+ .loadQuery(
63
+ `
64
+ ${modelString}
65
+
66
+ query: s-> {
67
+ group_by: class_name is json_extract_scalar!(j, '$.class_name')
68
+ order_by: 1 desc
69
+ }
70
+ `
71
+ )
72
+ .run();
73
+ // console.log(result.data.toObject());
74
+ expect(result.data.path(0, 'class_name').value).toBe('C');
75
+ });
76
+
77
+ it(`Return Json - ${databaseName}`, async () => {
78
+ //it(`model: do filters force dependant joins? - ${databaseName}`, async () => {
79
+ const result = await runtime
80
+ .loadQuery(
81
+ `
82
+ ${modelString}
83
+
84
+ query: s-> {
85
+ project: j, r
86
+ order_by: 2 desc
87
+ }
88
+ `
89
+ )
90
+ .run();
91
+ // console.log(result.data.toObject());
92
+ expect(result.data.path(0, 'j').value).toContain('Jamie');
93
+ });
94
+ });
95
+ });