@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,670 @@
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 {ModelMaterializer} from '@malloydata/malloy';
25
+ import {RuntimeList} from '../runtimes';
26
+ import {describeIfDatabaseAvailable} from '../util';
27
+ import {HTMLView} from '@malloydata/render';
28
+ import {JSDOM} from 'jsdom';
29
+
30
+ async function runUnsupportedRenderTest(
31
+ connectionName: string,
32
+ runtimes: RuntimeList,
33
+ expr: string,
34
+ rendered: string
35
+ ) {
36
+ const runtime = runtimes.runtimeMap.get(connectionName);
37
+ expect(runtime).toBeDefined();
38
+ if (runtime) {
39
+ const src = `
40
+ sql: sql_block is {
41
+ select: """SELECT ${expr} AS test"""
42
+ connection: "${connectionName}"
43
+ }
44
+ query: q is from_sql(sql_block)->{ project: *}
45
+ `;
46
+ const result = await runtime.loadModel(src).loadQueryByName('q').run();
47
+ // console.log("DATA", result.data.toObject());
48
+ const document = new JSDOM().window.document;
49
+ const html = await new HTMLView(document).render(result, {
50
+ dataStyles: {},
51
+ });
52
+ expect(html.innerHTML).toContain('<thead>');
53
+ expect(html.innerHTML).toContain(rendered);
54
+ // console.log(html.innerHTML);
55
+ }
56
+ }
57
+
58
+ const [describe, databases] = describeIfDatabaseAvailable([
59
+ 'bigquery',
60
+ 'postgres',
61
+ 'duckdb',
62
+ ]);
63
+ describe('rendering results', () => {
64
+ const runtimes = new RuntimeList(databases);
65
+
66
+ afterAll(async () => {
67
+ await runtimes.closeAll();
68
+ });
69
+
70
+ test('can render table', async () => {
71
+ const runtime = runtimes.runtimeMap.get('bigquery');
72
+ expect(runtime).toBeDefined();
73
+ if (runtime) {
74
+ const src = `
75
+ query: table('malloy-data.faa.flights') -> {
76
+ group_by: carrier
77
+ aggregate: flight_count is count()
78
+ }
79
+ `;
80
+ const result = await runtime.loadQuery(src).run();
81
+ const document = new JSDOM().window.document;
82
+ await new HTMLView(document).render(result, {
83
+ dataStyles: {},
84
+ });
85
+ }
86
+ });
87
+
88
+ test('can render unsupported bigquery geo types', async () => {
89
+ await runUnsupportedRenderTest(
90
+ 'bigquery',
91
+ runtimes,
92
+ "ST_GEOGFROMTEXT('LINESTRING(1 2, 3 4)')",
93
+ 'LINESTRING(1 2, 3 4)'
94
+ );
95
+ });
96
+
97
+ test('can render unsupported bigquery ip types', async () => {
98
+ await runUnsupportedRenderTest(
99
+ 'bigquery',
100
+ runtimes,
101
+ "NET.IP_FROM_STRING('192.168.1.1')",
102
+ '{"type":"Buffer","data":[192,168,1,1]}'
103
+ );
104
+ });
105
+
106
+ test('can render unsupported bigquery interval types', async () => {
107
+ await runUnsupportedRenderTest(
108
+ 'bigquery',
109
+ runtimes,
110
+ 'INTERVAL 1 YEAR',
111
+ '1-0 0 0:0:0'
112
+ );
113
+ });
114
+
115
+ test('can render unsupported bigquery time types', async () => {
116
+ await runUnsupportedRenderTest(
117
+ 'bigquery',
118
+ runtimes,
119
+ 'TIME(10, 10, 1)',
120
+ '10:10:01'
121
+ );
122
+ });
123
+
124
+ test('can render unsupported postgres interval types', async () => {
125
+ await runUnsupportedRenderTest(
126
+ 'postgres',
127
+ runtimes,
128
+ 'make_interval(days => 12)',
129
+ '12 days'
130
+ );
131
+ });
132
+
133
+ test('can render unsupported postgres uuid types', async () => {
134
+ await runUnsupportedRenderTest(
135
+ 'postgres',
136
+ runtimes,
137
+ "CAST('a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11' AS UUID)",
138
+ 'a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11'
139
+ );
140
+ });
141
+
142
+ test('can render unsupported postgres inet types', async () => {
143
+ await runUnsupportedRenderTest(
144
+ 'postgres',
145
+ runtimes,
146
+ "'192.168.1.1'::inet",
147
+ '192.168.1.1'
148
+ );
149
+ });
150
+
151
+ test('can render unsupported postgres macaddr types', async () => {
152
+ await runUnsupportedRenderTest(
153
+ 'postgres',
154
+ runtimes,
155
+ "'00:04:E2:36:95:C0'::macaddr",
156
+ '00:04:e2:36:95:c0'
157
+ );
158
+ });
159
+
160
+ test('can render supported postgres types', async () => {
161
+ await runUnsupportedRenderTest('postgres', runtimes, '12345', '12,345');
162
+ });
163
+
164
+ test('can render supported duckdb types', async () => {
165
+ await runUnsupportedRenderTest('duckdb', runtimes, '12345', '12,345');
166
+ });
167
+
168
+ test('can render unsupported duckdb blob types', async () => {
169
+ await runUnsupportedRenderTest(
170
+ 'duckdb',
171
+ runtimes,
172
+ "'\\xAA'::BLOB",
173
+ '{"type":"Buffer","data":[170]}'
174
+ );
175
+ });
176
+
177
+ test('can render unsupported duckdb uuid types', async () => {
178
+ await runUnsupportedRenderTest(
179
+ 'duckdb',
180
+ runtimes,
181
+ "'a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11'::UUID",
182
+ 'a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11'
183
+ );
184
+ });
185
+
186
+ test('can render null unsupported types', async () => {
187
+ await runUnsupportedRenderTest(
188
+ 'bigquery',
189
+ runtimes,
190
+ 'CAST(NULL AS GEOGRAPHY)',
191
+ '<span class="value-null">∅</span>'
192
+ );
193
+ });
194
+
195
+ describe('html renderer', () => {
196
+ describe('complex query with tags', () => {
197
+ let model: ModelMaterializer;
198
+
199
+ beforeAll(async () => {
200
+ const connectionName = 'duckdb';
201
+ const runtime = runtimes.runtimeMap.get(connectionName);
202
+ expect(runtime).toBeDefined();
203
+ const src = `
204
+ sql: names_sql is { connection: "duckdb" select: """SELECT 'Pedro' as nm
205
+ UNION ALL SELECT 'Sebastian'
206
+ UNION ALL SELECT 'Alex'
207
+ UNION ALL SELECT 'Miguel'""" }
208
+
209
+
210
+ sql: height_sql is { connection: "duckdb" select: """SELECT 'Pedro' as nm, 1 as monthy, 20 as height, 3 as wt, 50 apptcost, 1 as vaccine
211
+ UNION ALL SELECT 'Pedro', 2, 25, 3.4, 100, 1
212
+ UNION ALL SELECT 'Pedro', 3, 38, 3.6, 200, 0
213
+ UNION ALL SELECT 'Pedro', 4, 45, 3.7, 300, 1
214
+ UNION ALL SELECT 'Sebastian', 1, 23, 2, 400, 1
215
+ UNION ALL SELECT 'Sebastian', 2, 28, 2.6, 500, 1
216
+ UNION ALL SELECT 'Sebastian', 3, 35, 3.6, 650, 0
217
+ UNION ALL SELECT 'Sebastian', 4, 47, 4.2, 70, 1
218
+ UNION ALL SELECT 'Alex', 1, 23, 2.5, 85, 0
219
+ UNION ALL SELECT 'Alex', 2, 28, 3, 42, 1
220
+ UNION ALL SELECT 'Alex', 3, 35, 3.2, 63, 1
221
+ UNION ALL SELECT 'Alex', 4, 47, 3.4, 81, 1
222
+ UNION ALL SELECT 'Miguel', 1, 23, 4, 34, 0
223
+ UNION ALL SELECT 'Miguel', 2, 28, 4.1, 64, 1
224
+ UNION ALL SELECT 'Miguel', 3, 35, 4.2, 31, 1
225
+ UNION ALL SELECT 'Miguel', 4, 47, 4.3, 76, 0 """ }
226
+
227
+ source: height
228
+ # line_chart
229
+ is from_sql(height_sql) + {
230
+
231
+ query: by_name is {
232
+ group_by: nm
233
+ nest: height_by_age
234
+ # line_chart
235
+ is {
236
+ project: monthy, height
237
+ }
238
+
239
+ nest: weight_by_age_bar_chart is {
240
+ project: monthy, wt
241
+ }
242
+
243
+ aggregate:
244
+ # currency
245
+ price is sum(apptcost)
246
+ # percent
247
+ visitcount is sum(vaccine) / count()
248
+ }
249
+ }
250
+
251
+ query: by_name is height -> by_name {
252
+ }
253
+
254
+ # transpose
255
+ query: by_name_transposed is height -> by_name {
256
+ }
257
+
258
+ source: names is from_sql(names_sql) + {
259
+ join_many: height on nm = height.nm
260
+ }
261
+ `;
262
+ model = await runtime!.loadModel(src);
263
+ });
264
+
265
+ test('regular table', async () => {
266
+ const result = await model.loadQueryByName('by_name').run();
267
+ const document = new JSDOM().window.document;
268
+ const html = await new HTMLView(document).render(result, {
269
+ dataStyles: {},
270
+ });
271
+
272
+ expect(html).toMatchSnapshot();
273
+ });
274
+
275
+ test('transposed table', async () => {
276
+ const result = await model.loadQueryByName('by_name_transposed').run();
277
+ const document = new JSDOM().window.document;
278
+ const html = await new HTMLView(document).render(result, {
279
+ dataStyles: {},
280
+ });
281
+
282
+ expect(html).toMatchSnapshot();
283
+ });
284
+ });
285
+
286
+ describe('hidden tags', () => {
287
+ let modelMaterializer: ModelMaterializer;
288
+ beforeAll(() => {
289
+ const connectionName = 'duckdb';
290
+ const runtime = runtimes.runtimeMap.get(connectionName);
291
+ expect(runtime).toBeDefined();
292
+ const src = `
293
+ sql: height_sql is { connection: "duckdb" select: """
294
+ SELECT 'Pedro' as nm, 1 as monthy, 20 as height, 3 as wt, 50 apptcost, 1 as vaccine
295
+ UNION ALL SELECT 'Pedro', 2, 25, 3.4, 100, 1
296
+ UNION ALL SELECT 'Sebastian', 1, 23, 2, 400, 1
297
+ UNION ALL SELECT 'Sebastian', 2, 28, 2.6, 500, 1 """ }
298
+
299
+ source: height
300
+ # line_chart
301
+ is from_sql(height_sql) + {
302
+
303
+ measure: visitcount is sum(vaccine) / count();
304
+
305
+ # currency
306
+ # hidden
307
+ dimension: price is apptcost
308
+
309
+ query: by_name is {
310
+ group_by: nm
311
+ order_by: nm
312
+ nest: height_by_age
313
+ is {
314
+ project:
315
+ # hidden
316
+ monthy,
317
+ height
318
+ }
319
+
320
+ # hidden
321
+ nest: height_by_age_hidden
322
+ is {
323
+ project: monthy, height
324
+ }
325
+
326
+ # list
327
+ nest: monthy is {
328
+ project: price
329
+ }
330
+
331
+ aggregate:
332
+ visitcount
333
+ # hidden
334
+ noshowvc is visitcount
335
+ }
336
+
337
+ # dashboard
338
+ query: by_name_db is by_name {}
339
+ }
340
+
341
+ query: by_name is height -> by_name {}
342
+ query: by_name_db is height -> by_name_db {}
343
+ `;
344
+ modelMaterializer = runtime!.loadModel(src);
345
+ });
346
+
347
+ test('rendered correctly table', async () => {
348
+ const result = await modelMaterializer.loadQueryByName('by_name').run();
349
+ const document = new JSDOM().window.document;
350
+ const html = await new HTMLView(document).render(result, {
351
+ dataStyles: {},
352
+ });
353
+
354
+ expect(html).toMatchSnapshot();
355
+ });
356
+
357
+ test('rendered correctly dashboard', async () => {
358
+ const result = await modelMaterializer
359
+ .loadQueryByName('by_name_db')
360
+ .run();
361
+ const document = new JSDOM().window.document;
362
+ const html = await new HTMLView(document).render(result, {
363
+ dataStyles: {},
364
+ });
365
+
366
+ expect(html).toMatchSnapshot();
367
+ });
368
+ });
369
+
370
+ test('pivot table renders correctly', async () => {
371
+ const connectionName = 'duckdb';
372
+ const runtime = runtimes.runtimeMap.get(connectionName);
373
+ expect(runtime).toBeDefined();
374
+ const src = `
375
+ sql: height_sql is { connection: "${connectionName}" select: """SELECT 'Pedro' as nm, 'Monday' as dayito, 1 as loc, 2 as lac, 1 as monthy, 20 as height, 3 as wt, 50 apptcost, 1 as vaccine, 'A' as btype
376
+ UNION ALL SELECT 'Pedro', 'Tuesday', 1, 2, 2, 25, 3.4, 100, 1, 'B'
377
+ UNION ALL SELECT 'Pedro', 'Tuesday', 1, 2, 3, 38, 3.6, 200, 0, 'A'
378
+ UNION ALL SELECT 'Pedro', 'Wednesday', 1, 2, 4, 45, 3.7, 300, 1, 'O'
379
+ UNION ALL SELECT 'Sebastian', 'Thursday', 1, 2, 1, 23, 2, 400, 1, 'C'
380
+ UNION ALL SELECT 'Sebastian', 'Thursday', 1, 2, 2, 28, 2.6, 500, 1, 'A'
381
+ UNION ALL SELECT 'Sebastian', 'Monday', 1, 2, 3, 35, 3.6, 650, 0, 'A'
382
+ UNION ALL SELECT 'Sebastian', 'Monday', 1, 2, 4, 47, 4.2, 70, 1, 'B'
383
+ UNION ALL SELECT 'Alex', 'Tuesday', 1, 2, 1, 23, 2.5, 85, 0, 'X'
384
+ UNION ALL SELECT 'Alex', 'Thursday', 1, 2, 2, 28, 3, 42, 1, 'P'
385
+ UNION ALL SELECT 'Alex', 'Thursday', 1, 2, 3, 35, 3.2, 63, 1, 'A'
386
+ UNION ALL SELECT 'Alex', 'Monday', 1, 2, 4, 47, 3.4, 81, 1, 'D'
387
+ UNION ALL SELECT 'Miguel', 'Monday', 1, 2, 1, 23, 4, 34, 0, 'E'
388
+ UNION ALL SELECT 'Miguel', 'Monday', 1, 2, 2, 28, 4.1, 64, 1, 'R'
389
+ UNION ALL SELECT 'Miguel', 'Wednesday', 1, 2, 3, 35, 4.2, 31, 1, 'E'
390
+ UNION ALL SELECT 'Miguel', 'Wednesday', 1, 2, 4, 47, 4.3, 76, 0, 'F' """ }
391
+
392
+
393
+ source: height
394
+ is from_sql(height_sql) + {
395
+
396
+ # percent
397
+ dimension: flac is lac
398
+
399
+ # currency
400
+ dimension: floc is loc
401
+
402
+ query: by_name is {
403
+ group_by: nm
404
+ # pivot pivot_dimensions="dayito"
405
+ nest: pivot_f is {
406
+ group_by: dayito
407
+ aggregate:
408
+ ht is avg(height),
409
+ price is sum(apptcost)
410
+ mbtype is max(btype)
411
+ }
412
+
413
+ aggregate: pricepu is sum(apptcost)
414
+ # pivot
415
+ nest: pivot_f2 is {
416
+ group_by: floc, flac
417
+ aggregate:
418
+ ht is avg(height)
419
+ price is sum(apptcost)
420
+ }
421
+ }
422
+ }
423
+
424
+ query: by_name is height -> by_name {}
425
+ `;
426
+ const result = await (
427
+ await runtime!.loadModel(src).loadQueryByName('by_name')
428
+ ).run();
429
+ const document = new JSDOM().window.document;
430
+ const html = await new HTMLView(document).render(result, {
431
+ dataStyles: {},
432
+ });
433
+
434
+ expect(html).toMatchSnapshot();
435
+ });
436
+ });
437
+
438
+ describe('date renderer', () => {
439
+ test('date with timezone rendered correctly', async () => {
440
+ const connectionName = 'duckdb';
441
+ const runtime = runtimes.runtimeMap.get(connectionName);
442
+ expect(runtime).toBeDefined();
443
+ const src = `sql: one is { connection: "${connectionName}" select: """SELECT 1"""}
444
+ query: mex_query is from_sql(one) -> {
445
+ timezone: 'America/Mexico_City'
446
+ project: mex_time is @2021-02-24 03:05:06
447
+ }
448
+ `;
449
+ const result = await (
450
+ await runtime!.loadModel(src).loadQueryByName('mex_query')
451
+ ).run();
452
+ const document = new JSDOM().window.document;
453
+ const html = await new HTMLView(document).render(result, {
454
+ dataStyles: {},
455
+ });
456
+
457
+ expect(html).toMatchSnapshot();
458
+ });
459
+
460
+ test('truncated date no explicit timezone rendered correctly', async () => {
461
+ const connectionName = 'duckdb';
462
+ const runtime = runtimes.runtimeMap.get(connectionName);
463
+ expect(runtime).toBeDefined();
464
+ const src = `
465
+ sql: timeDataTrunc is { connection: "duckdb" select: """
466
+ SELECT CAST('2021-12-11 10:20:00' AS datetime) as times
467
+ UNION ALL SELECT CAST('2021-01-01 05:40:00' AS datetime)
468
+ UNION ALL SELECT CAST('2021-04-01 00:59:00' AS datetime)"""}
469
+
470
+
471
+ query:
472
+ data_trunc is from_sql(timeDataTrunc) -> {
473
+ project: yr is times.year, qt is times.quarter, mt is times.month, dy is times.day
474
+ }
475
+ `;
476
+ const result = await (
477
+ await runtime!.loadModel(src).loadQueryByName('data_trunc')
478
+ ).run();
479
+ const document = new JSDOM().window.document;
480
+ const html = await new HTMLView(document).render(result, {
481
+ dataStyles: {},
482
+ });
483
+
484
+ expect(html).toMatchSnapshot();
485
+ });
486
+ });
487
+
488
+ describe('bar chart renderer', () => {
489
+ test('date with timezone rendered correctly', async () => {
490
+ const connectionName = 'duckdb';
491
+ const runtime = runtimes.runtimeMap.get(connectionName);
492
+ expect(runtime).toBeDefined();
493
+ const src = `sql: one is { connection: "${connectionName}" select: """SELECT 1"""}
494
+ query: mex_query
495
+ # bar_chart
496
+ is from_sql(one) -> {
497
+ timezone: 'America/Mexico_City'
498
+ project: mex_time is @2021-02-24 03:05:06
499
+ }
500
+ `;
501
+ const result = await (
502
+ await runtime!.loadModel(src).loadQueryByName('mex_query')
503
+ ).run();
504
+ const document = new JSDOM().window.document;
505
+ const html = await new HTMLView(document).render(result, {
506
+ dataStyles: {},
507
+ });
508
+
509
+ expect(html).toMatchSnapshot();
510
+ });
511
+ });
512
+
513
+ describe('point map renderer', () => {
514
+ test('date with timezone rendered correctly', async () => {
515
+ const connectionName = 'duckdb';
516
+ const runtime = runtimes.runtimeMap.get(connectionName);
517
+ expect(runtime).toBeDefined();
518
+ const src = `sql: timeData is { connection: "${connectionName}" select: """
519
+ SELECT 43.839187 as latitude, -113.849795 as longitude, CAST('2021-11-10' AS datetime) as times, 200 as size
520
+ UNION ALL SELECT 32.8647113, -117.1998042, CAST('2021-11-12' AS datetime), 400 as size"""}
521
+
522
+ query: mexico_point_map is from_sql(timeData) -> {
523
+ timezone: 'America/Mexico_City'
524
+ group_by: latitude, longitude, times
525
+ aggregate:
526
+ sizeSum is sum(size)
527
+ }`;
528
+ const result = await (
529
+ await runtime!.loadModel(src).loadQueryByName('mexico_point_map')
530
+ ).run();
531
+ const document = new JSDOM().window.document;
532
+ const html = await new HTMLView(document).render(result, {
533
+ dataStyles: {},
534
+ });
535
+
536
+ expect(html).toMatchSnapshot();
537
+ });
538
+ });
539
+
540
+ describe('number renderer', () => {
541
+ test('value format tags works correctly', async () => {
542
+ const connectionName = 'duckdb';
543
+ const runtime = runtimes.runtimeMap.get(connectionName);
544
+ expect(runtime).toBeDefined();
545
+ const src = `
546
+ sql: number_sql is { connection: "${connectionName}" select: """SELECT 12.345 as anumber""" }
547
+
548
+ query: number_query is from_sql(number_sql) -> {
549
+ project:
550
+ anumber
551
+ # number= "#,##0.0000"
552
+ larger is anumber
553
+ # number= "#,##0.00"
554
+ shorter is anumber
555
+ }
556
+ `;
557
+ const result = await (
558
+ await runtime!.loadModel(src).loadQueryByName('number_query')
559
+ ).run();
560
+ const document = new JSDOM().window.document;
561
+ const html = await new HTMLView(document).render(result, {
562
+ dataStyles: {},
563
+ });
564
+
565
+ expect(html).toMatchSnapshot();
566
+ });
567
+ });
568
+
569
+ describe('data volume renderer', () => {
570
+ test('data volume tags works correctly', async () => {
571
+ const connectionName = 'duckdb';
572
+ const runtime = runtimes.runtimeMap.get(connectionName);
573
+ expect(runtime).toBeDefined();
574
+ const src = `
575
+ sql: number_sql is { connection: "${connectionName}" select: """SELECT 1""" }
576
+
577
+ query: bytes_query is from_sql(number_sql) -> {
578
+ project:
579
+ # data_volume = bytes
580
+ usage_b is 3758
581
+ # data_volume = kb
582
+ usage_kb is 3758
583
+ # data_volume = mb
584
+ usage_mb is 3758096
585
+ # data_volume = gb
586
+ usage_gb is 3758096384
587
+ # data_volume = tb
588
+ usage_tb is 3758096384000
589
+ }
590
+ `;
591
+ const result = await (
592
+ await runtime!.loadModel(src).loadQueryByName('bytes_query')
593
+ ).run();
594
+ const document = new JSDOM().window.document;
595
+ const html = await new HTMLView(document).render(result, {
596
+ dataStyles: {},
597
+ });
598
+
599
+ expect(html).toMatchSnapshot();
600
+ });
601
+ });
602
+
603
+ describe('duration renderer', () => {
604
+ test('duration tags works correctly', async () => {
605
+ const connectionName = 'duckdb';
606
+ const runtime = runtimes.runtimeMap.get(connectionName);
607
+ expect(runtime).toBeDefined();
608
+ const src = `
609
+ sql: number_sql is { connection: "${connectionName}" select: """SELECT 1""" }
610
+
611
+ query: duration_query is from_sql(number_sql) -> {
612
+ project:
613
+ # duration = nanoseconds
614
+ ns1 is 1
615
+ # duration = nanoseconds
616
+ ns2 is 1002
617
+ # duration = nanoseconds
618
+ ns3 is 1002003
619
+ # duration = microseconds
620
+ mis1 is 1
621
+ # duration = microseconds
622
+ mis2 is 1002
623
+ # duration = microseconds
624
+ mis3 is 1002003
625
+ # duration = milliseconds
626
+ ms1 is 1
627
+ # duration = milliseconds
628
+ ms2 is 1002
629
+ # duration = milliseconds
630
+ ms3 is 1002003
631
+ # duration = seconds
632
+ s1 is 1
633
+ # duration = seconds
634
+ s2 is 61
635
+ # duration = seconds
636
+ s3 is 121
637
+ # duration = seconds
638
+ s4 is 3610
639
+ # duration = seconds
640
+ s5 is 1728015
641
+ # duration = minutes
642
+ m1 is 1
643
+ # duration = minutes
644
+ m2 is 62
645
+ # duration = minutes
646
+ m3 is 1445
647
+ # duration = hours
648
+ h1 is 1
649
+ # duration = hours
650
+ h2 is 26
651
+ # duration = hours
652
+ h3 is 48
653
+ # duration = days
654
+ d1 is 1
655
+ # duration = days
656
+ d2 is 300
657
+ }
658
+ `;
659
+ const result = await (
660
+ await runtime!.loadModel(src).loadQueryByName('duration_query')
661
+ ).run();
662
+ const document = new JSDOM().window.document;
663
+ const html = await new HTMLView(document).render(result, {
664
+ dataStyles: {},
665
+ });
666
+
667
+ expect(html).toMatchSnapshot();
668
+ });
669
+ });
670
+ });