@malloydata/malloy-tests 0.0.74-dev230812015425 → 0.0.74-dev230815162117
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/dist/render/render.spec.js +51 -100
- package/dist/render/render.spec.js.map +1 -1
- package/dist/tags.spec.js +90 -152
- package/dist/tags.spec.js.map +1 -1
- package/package.json +6 -6
- package/src/render/render.spec.ts +52 -101
- package/src/tags.spec.ts +93 -164
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
*/
|
|
23
23
|
|
|
24
24
|
import {ModelMaterializer} from '@malloydata/malloy';
|
|
25
|
-
import {RuntimeList} from '../runtimes';
|
|
25
|
+
import {RuntimeList, runtimeFor} from '../runtimes';
|
|
26
26
|
import {describeIfDatabaseAvailable} from '../util';
|
|
27
27
|
import {HTMLView} from '@malloydata/render';
|
|
28
28
|
import {JSDOM} from 'jsdom';
|
|
@@ -37,11 +37,9 @@ async function runUnsupportedRenderTest(
|
|
|
37
37
|
expect(runtime).toBeDefined();
|
|
38
38
|
if (runtime) {
|
|
39
39
|
const src = `
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
44
|
-
query: q is from_sql(sql_block)->{ project: *}
|
|
40
|
+
query: q is
|
|
41
|
+
${connectionName}.sql("""SELECT ${expr} AS test""")
|
|
42
|
+
-> { project: * }
|
|
45
43
|
`;
|
|
46
44
|
const result = await runtime.loadModel(src).loadQueryByName('q').run();
|
|
47
45
|
// console.log("DATA", result.data.toObject());
|
|
@@ -60,6 +58,7 @@ const [describe, databases] = describeIfDatabaseAvailable([
|
|
|
60
58
|
'postgres',
|
|
61
59
|
'duckdb',
|
|
62
60
|
]);
|
|
61
|
+
const duckdb = runtimeFor('duckdb');
|
|
63
62
|
describe('rendering results', () => {
|
|
64
63
|
const runtimes = new RuntimeList(databases);
|
|
65
64
|
|
|
@@ -197,17 +196,10 @@ describe('rendering results', () => {
|
|
|
197
196
|
let model: ModelMaterializer;
|
|
198
197
|
|
|
199
198
|
beforeAll(async () => {
|
|
200
|
-
const connectionName = 'duckdb';
|
|
201
|
-
const runtime = runtimes.runtimeMap.get(connectionName);
|
|
202
|
-
expect(runtime).toBeDefined();
|
|
203
199
|
const src = `
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
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
|
|
200
|
+
# line_chart
|
|
201
|
+
source: height is duckdb.sql("""
|
|
202
|
+
SELECT 'Pedro' as nm, 1 as monthy, 20 as height, 3 as wt, 50 apptcost, 1 as vaccine
|
|
211
203
|
UNION ALL SELECT 'Pedro', 2, 25, 3.4, 100, 1
|
|
212
204
|
UNION ALL SELECT 'Pedro', 3, 38, 3.6, 200, 0
|
|
213
205
|
UNION ALL SELECT 'Pedro', 4, 45, 3.7, 300, 1
|
|
@@ -222,11 +214,7 @@ describe('rendering results', () => {
|
|
|
222
214
|
UNION ALL SELECT 'Miguel', 1, 23, 4, 34, 0
|
|
223
215
|
UNION ALL SELECT 'Miguel', 2, 28, 4.1, 64, 1
|
|
224
216
|
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) + {
|
|
217
|
+
UNION ALL SELECT 'Miguel', 4, 47, 4.3, 76, 0 """) extend {
|
|
230
218
|
|
|
231
219
|
query: by_name is {
|
|
232
220
|
group_by: nm
|
|
@@ -255,11 +243,14 @@ describe('rendering results', () => {
|
|
|
255
243
|
query: by_name_transposed is height -> by_name {
|
|
256
244
|
}
|
|
257
245
|
|
|
258
|
-
source: names is
|
|
246
|
+
source: names is duckdb.sql("""SELECT 'Pedro' as nm
|
|
247
|
+
UNION ALL SELECT 'Sebastian'
|
|
248
|
+
UNION ALL SELECT 'Alex'
|
|
249
|
+
UNION ALL SELECT 'Miguel'""") extend {
|
|
259
250
|
join_many: height on nm = height.nm
|
|
260
251
|
}
|
|
261
252
|
`;
|
|
262
|
-
model = await
|
|
253
|
+
model = await duckdb.loadModel(src);
|
|
263
254
|
});
|
|
264
255
|
|
|
265
256
|
test('regular table', async () => {
|
|
@@ -286,19 +277,13 @@ describe('rendering results', () => {
|
|
|
286
277
|
describe('hidden tags', () => {
|
|
287
278
|
let modelMaterializer: ModelMaterializer;
|
|
288
279
|
beforeAll(() => {
|
|
289
|
-
const connectionName = 'duckdb';
|
|
290
|
-
const runtime = runtimes.runtimeMap.get(connectionName);
|
|
291
|
-
expect(runtime).toBeDefined();
|
|
292
280
|
const src = `
|
|
293
|
-
|
|
294
|
-
|
|
281
|
+
source: height
|
|
282
|
+
# line_chart
|
|
283
|
+
is duckdb.sql("""SELECT 'Pedro' as nm, 1 as monthy, 20 as height, 3 as wt, 50 apptcost, 1 as vaccine
|
|
295
284
|
UNION ALL SELECT 'Pedro', 2, 25, 3.4, 100, 1
|
|
296
285
|
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) + {
|
|
286
|
+
UNION ALL SELECT 'Sebastian', 2, 28, 2.6, 500, 1 """) extend {
|
|
302
287
|
|
|
303
288
|
measure: visitcount is sum(vaccine) / count();
|
|
304
289
|
|
|
@@ -341,7 +326,7 @@ describe('rendering results', () => {
|
|
|
341
326
|
query: by_name is height -> by_name {}
|
|
342
327
|
query: by_name_db is height -> by_name_db {}
|
|
343
328
|
`;
|
|
344
|
-
modelMaterializer =
|
|
329
|
+
modelMaterializer = duckdb.loadModel(src);
|
|
345
330
|
});
|
|
346
331
|
|
|
347
332
|
test('rendered correctly table', async () => {
|
|
@@ -368,11 +353,9 @@ describe('rendering results', () => {
|
|
|
368
353
|
});
|
|
369
354
|
|
|
370
355
|
test('pivot table renders correctly', async () => {
|
|
371
|
-
const connectionName = 'duckdb';
|
|
372
|
-
const runtime = runtimes.runtimeMap.get(connectionName);
|
|
373
|
-
expect(runtime).toBeDefined();
|
|
374
356
|
const src = `
|
|
375
|
-
|
|
357
|
+
source: height
|
|
358
|
+
is duckdb.sql("""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
359
|
UNION ALL SELECT 'Pedro', 'Tuesday', 1, 2, 2, 25, 3.4, 100, 1, 'B'
|
|
377
360
|
UNION ALL SELECT 'Pedro', 'Tuesday', 1, 2, 3, 38, 3.6, 200, 0, 'A'
|
|
378
361
|
UNION ALL SELECT 'Pedro', 'Wednesday', 1, 2, 4, 45, 3.7, 300, 1, 'O'
|
|
@@ -387,11 +370,7 @@ describe('rendering results', () => {
|
|
|
387
370
|
UNION ALL SELECT 'Miguel', 'Monday', 1, 2, 1, 23, 4, 34, 0, 'E'
|
|
388
371
|
UNION ALL SELECT 'Miguel', 'Monday', 1, 2, 2, 28, 4.1, 64, 1, 'R'
|
|
389
372
|
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) + {
|
|
373
|
+
UNION ALL SELECT 'Miguel', 'Wednesday', 1, 2, 4, 47, 4.3, 76, 0, 'F' """) extend {
|
|
395
374
|
|
|
396
375
|
# percent
|
|
397
376
|
dimension: flac is lac
|
|
@@ -424,7 +403,7 @@ describe('rendering results', () => {
|
|
|
424
403
|
query: by_name is height -> by_name {}
|
|
425
404
|
`;
|
|
426
405
|
const result = await (
|
|
427
|
-
await
|
|
406
|
+
await duckdb.loadModel(src).loadQueryByName('by_name')
|
|
428
407
|
).run();
|
|
429
408
|
const document = new JSDOM().window.document;
|
|
430
409
|
const html = await new HTMLView(document).render(result, {
|
|
@@ -437,17 +416,14 @@ describe('rendering results', () => {
|
|
|
437
416
|
|
|
438
417
|
describe('date renderer', () => {
|
|
439
418
|
test('date with timezone rendered correctly', async () => {
|
|
440
|
-
const
|
|
441
|
-
|
|
442
|
-
expect(runtime).toBeDefined();
|
|
443
|
-
const src = `sql: one is { connection: "${connectionName}" select: """SELECT 1"""}
|
|
444
|
-
query: mex_query is from_sql(one) -> {
|
|
419
|
+
const src = `
|
|
420
|
+
query: mex_query is duckdb.sql('SELECT 1') -> {
|
|
445
421
|
timezone: 'America/Mexico_City'
|
|
446
422
|
project: mex_time is @2021-02-24 03:05:06
|
|
447
423
|
}
|
|
448
424
|
`;
|
|
449
425
|
const result = await (
|
|
450
|
-
await
|
|
426
|
+
await duckdb.loadModel(src).loadQueryByName('mex_query')
|
|
451
427
|
).run();
|
|
452
428
|
const document = new JSDOM().window.document;
|
|
453
429
|
const html = await new HTMLView(document).render(result, {
|
|
@@ -458,23 +434,20 @@ describe('rendering results', () => {
|
|
|
458
434
|
});
|
|
459
435
|
|
|
460
436
|
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
437
|
const src = `
|
|
465
|
-
|
|
438
|
+
source: timeDataTrunc is duckdb.sql("""
|
|
466
439
|
SELECT CAST('2021-12-11 10:20:00' AS datetime) as times
|
|
467
440
|
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)"""
|
|
441
|
+
UNION ALL SELECT CAST('2021-04-01 00:59:00' AS datetime)""")
|
|
469
442
|
|
|
470
443
|
|
|
471
444
|
query:
|
|
472
|
-
data_trunc is
|
|
445
|
+
data_trunc is timeDataTrunc -> {
|
|
473
446
|
project: yr is times.year, qt is times.quarter, mt is times.month, dy is times.day
|
|
474
447
|
}
|
|
475
448
|
`;
|
|
476
449
|
const result = await (
|
|
477
|
-
await
|
|
450
|
+
await duckdb.loadModel(src).loadQueryByName('data_trunc')
|
|
478
451
|
).run();
|
|
479
452
|
const document = new JSDOM().window.document;
|
|
480
453
|
const html = await new HTMLView(document).render(result, {
|
|
@@ -487,19 +460,15 @@ describe('rendering results', () => {
|
|
|
487
460
|
|
|
488
461
|
describe('bar chart renderer', () => {
|
|
489
462
|
test('date with timezone rendered correctly', async () => {
|
|
490
|
-
const
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
is from_sql(one) -> {
|
|
497
|
-
timezone: 'America/Mexico_City'
|
|
498
|
-
project: mex_time is @2021-02-24 03:05:06
|
|
499
|
-
}
|
|
463
|
+
const src = `
|
|
464
|
+
query: mex_query # bar_chart
|
|
465
|
+
is duckdb.sql('SELECT 1') -> {
|
|
466
|
+
timezone: 'America/Mexico_City'
|
|
467
|
+
project: mex_time is @2021-02-24 03:05:06
|
|
468
|
+
}
|
|
500
469
|
`;
|
|
501
470
|
const result = await (
|
|
502
|
-
await
|
|
471
|
+
await duckdb.loadModel(src).loadQueryByName('mex_query')
|
|
503
472
|
).run();
|
|
504
473
|
const document = new JSDOM().window.document;
|
|
505
474
|
const html = await new HTMLView(document).render(result, {
|
|
@@ -512,21 +481,18 @@ describe('rendering results', () => {
|
|
|
512
481
|
|
|
513
482
|
describe('point map renderer', () => {
|
|
514
483
|
test('date with timezone rendered correctly', async () => {
|
|
515
|
-
const
|
|
516
|
-
const runtime = runtimes.runtimeMap.get(connectionName);
|
|
517
|
-
expect(runtime).toBeDefined();
|
|
518
|
-
const src = `sql: timeData is { connection: "${connectionName}" select: """
|
|
484
|
+
const src = `source: timeData is duckdb.sql("""
|
|
519
485
|
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"""
|
|
486
|
+
UNION ALL SELECT 32.8647113, -117.1998042, CAST('2021-11-12' AS datetime), 400 as size""")
|
|
521
487
|
|
|
522
|
-
query: mexico_point_map is
|
|
488
|
+
query: mexico_point_map is timeData -> {
|
|
523
489
|
timezone: 'America/Mexico_City'
|
|
524
490
|
group_by: latitude, longitude, times
|
|
525
491
|
aggregate:
|
|
526
492
|
sizeSum is sum(size)
|
|
527
493
|
}`;
|
|
528
494
|
const result = await (
|
|
529
|
-
await
|
|
495
|
+
await duckdb.loadModel(src).loadQueryByName('mexico_point_map')
|
|
530
496
|
).run();
|
|
531
497
|
const document = new JSDOM().window.document;
|
|
532
498
|
const html = await new HTMLView(document).render(result, {
|
|
@@ -539,23 +505,18 @@ describe('rendering results', () => {
|
|
|
539
505
|
|
|
540
506
|
describe('number renderer', () => {
|
|
541
507
|
test('value format tags works correctly', async () => {
|
|
542
|
-
const connectionName = 'duckdb';
|
|
543
|
-
const runtime = runtimes.runtimeMap.get(connectionName);
|
|
544
|
-
expect(runtime).toBeDefined();
|
|
545
508
|
const src = `
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
query: number_query is from_sql(number_sql) -> {
|
|
509
|
+
query: number_query is duckdb.sql('SELECT 12.345 as anumber') -> {
|
|
549
510
|
project:
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
511
|
+
anumber
|
|
512
|
+
# number= "#,##0.0000"
|
|
513
|
+
larger is anumber
|
|
514
|
+
# number= "#,##0.00"
|
|
515
|
+
shorter is anumber
|
|
555
516
|
}
|
|
556
517
|
`;
|
|
557
518
|
const result = await (
|
|
558
|
-
await
|
|
519
|
+
await duckdb.loadModel(src).loadQueryByName('number_query')
|
|
559
520
|
).run();
|
|
560
521
|
const document = new JSDOM().window.document;
|
|
561
522
|
const html = await new HTMLView(document).render(result, {
|
|
@@ -568,13 +529,8 @@ describe('rendering results', () => {
|
|
|
568
529
|
|
|
569
530
|
describe('data volume renderer', () => {
|
|
570
531
|
test('data volume tags works correctly', async () => {
|
|
571
|
-
const connectionName = 'duckdb';
|
|
572
|
-
const runtime = runtimes.runtimeMap.get(connectionName);
|
|
573
|
-
expect(runtime).toBeDefined();
|
|
574
532
|
const src = `
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
query: bytes_query is from_sql(number_sql) -> {
|
|
533
|
+
query: bytes_query is duckdb.sql('SELECT 1') -> {
|
|
578
534
|
project:
|
|
579
535
|
# data_volume = bytes
|
|
580
536
|
usage_b is 3758
|
|
@@ -589,7 +545,7 @@ describe('rendering results', () => {
|
|
|
589
545
|
}
|
|
590
546
|
`;
|
|
591
547
|
const result = await (
|
|
592
|
-
await
|
|
548
|
+
await duckdb.loadModel(src).loadQueryByName('bytes_query')
|
|
593
549
|
).run();
|
|
594
550
|
const document = new JSDOM().window.document;
|
|
595
551
|
const html = await new HTMLView(document).render(result, {
|
|
@@ -602,13 +558,8 @@ describe('rendering results', () => {
|
|
|
602
558
|
|
|
603
559
|
describe('duration renderer', () => {
|
|
604
560
|
test('duration tags works correctly', async () => {
|
|
605
|
-
const connectionName = 'duckdb';
|
|
606
|
-
const runtime = runtimes.runtimeMap.get(connectionName);
|
|
607
|
-
expect(runtime).toBeDefined();
|
|
608
561
|
const src = `
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
query: duration_query is from_sql(number_sql) -> {
|
|
562
|
+
query: duration_query is duckdb.sql('SELECT 1') -> {
|
|
612
563
|
project:
|
|
613
564
|
# duration = nanoseconds
|
|
614
565
|
ns1 is 1
|
|
@@ -657,7 +608,7 @@ describe('rendering results', () => {
|
|
|
657
608
|
}
|
|
658
609
|
`;
|
|
659
610
|
const result = await (
|
|
660
|
-
await
|
|
611
|
+
await duckdb.loadModel(src).loadQueryByName('duration_query')
|
|
661
612
|
).run();
|
|
662
613
|
const document = new JSDOM().window.document;
|
|
663
614
|
const html = await new HTMLView(document).render(result, {
|