@malloydata/malloy-tests 0.0.224-dev241217193641 → 0.0.224-dev241217205411
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/package.json
CHANGED
|
@@ -21,13 +21,13 @@
|
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"@jest/globals": "^29.4.3",
|
|
24
|
-
"@malloydata/db-bigquery": "^0.0.224-
|
|
25
|
-
"@malloydata/db-duckdb": "^0.0.224-
|
|
26
|
-
"@malloydata/db-postgres": "^0.0.224-
|
|
27
|
-
"@malloydata/db-snowflake": "^0.0.224-
|
|
28
|
-
"@malloydata/db-trino": "^0.0.224-
|
|
29
|
-
"@malloydata/malloy": "^0.0.224-
|
|
30
|
-
"@malloydata/render": "^0.0.224-
|
|
24
|
+
"@malloydata/db-bigquery": "^0.0.224-dev241217205411",
|
|
25
|
+
"@malloydata/db-duckdb": "^0.0.224-dev241217205411",
|
|
26
|
+
"@malloydata/db-postgres": "^0.0.224-dev241217205411",
|
|
27
|
+
"@malloydata/db-snowflake": "^0.0.224-dev241217205411",
|
|
28
|
+
"@malloydata/db-trino": "^0.0.224-dev241217205411",
|
|
29
|
+
"@malloydata/malloy": "^0.0.224-dev241217205411",
|
|
30
|
+
"@malloydata/render": "^0.0.224-dev241217205411",
|
|
31
31
|
"events": "^3.3.0",
|
|
32
32
|
"jsdom": "^22.1.0",
|
|
33
33
|
"luxon": "^2.4.0",
|
|
@@ -37,5 +37,5 @@
|
|
|
37
37
|
"@types/jsdom": "^21.1.1",
|
|
38
38
|
"@types/luxon": "^2.4.0"
|
|
39
39
|
},
|
|
40
|
-
"version": "0.0.224-
|
|
40
|
+
"version": "0.0.224-dev241217205411"
|
|
41
41
|
}
|
|
@@ -1069,14 +1069,14 @@ expressionModels.forEach((x, databaseName) => {
|
|
|
1069
1069
|
});
|
|
1070
1070
|
});
|
|
1071
1071
|
|
|
1072
|
-
describe('
|
|
1072
|
+
describe('string_repeat', () => {
|
|
1073
1073
|
it(`works - ${databaseName}`, async () => {
|
|
1074
1074
|
await funcTestMultiple(
|
|
1075
|
-
["
|
|
1076
|
-
["
|
|
1077
|
-
["
|
|
1078
|
-
['
|
|
1079
|
-
["
|
|
1075
|
+
["string_repeat('foo', 0)", ''],
|
|
1076
|
+
["string_repeat('foo', 1)", 'foo'],
|
|
1077
|
+
["string_repeat('foo', 2)", 'foofoo'],
|
|
1078
|
+
['string_repeat(null, 2)', null],
|
|
1079
|
+
["string_repeat('foo', null)", null]
|
|
1080
1080
|
);
|
|
1081
1081
|
});
|
|
1082
1082
|
// TODO how does a user do this: the second argument needs to be an integer, but floor doesn't cast to "integer" type.
|
|
@@ -21,24 +21,28 @@ describe.each(runtimes.runtimeList)(
|
|
|
21
21
|
if (runtime === undefined) {
|
|
22
22
|
throw new Error("Couldn't build runtime");
|
|
23
23
|
}
|
|
24
|
+
const presto = databaseName === 'presto';
|
|
24
25
|
|
|
25
|
-
test.when(databaseName === 'presto')('presto explain parser', async () => {
|
|
26
|
-
const abrec = 'CAST(ROW(0,1) AS ROW(a DOUBLE,b DOUBLE))';
|
|
27
|
-
await expect(`
|
|
28
|
-
run: ${databaseName}.sql("""
|
|
29
|
-
SELECT
|
|
30
|
-
${abrec} as "abrec",
|
|
31
|
-
ARRAY['c', 'd'] as str_array,
|
|
32
|
-
array[1,2,3] as int_array,
|
|
33
|
-
ARRAY[${abrec}] as array_of_abrec
|
|
34
|
-
""")
|
|
35
|
-
`).malloyResultMatches(runtime, {});
|
|
36
|
-
});
|
|
37
26
|
it(`runs an sql query - ${databaseName}`, async () => {
|
|
38
27
|
await expect(
|
|
39
28
|
`run: ${databaseName}.sql("SELECT 1 as n") -> { select: n }`
|
|
40
29
|
).malloyResultMatches(runtime, {n: 1});
|
|
41
30
|
});
|
|
31
|
+
test.when(databaseName === 'presto')(
|
|
32
|
+
'schema parser does not throw on compound types',
|
|
33
|
+
async () => {
|
|
34
|
+
const abrec = 'CAST(ROW(0,1) AS ROW(a DOUBLE,b DOUBLE))';
|
|
35
|
+
await expect(`
|
|
36
|
+
run: ${databaseName}.sql("""
|
|
37
|
+
SELECT
|
|
38
|
+
${abrec} as "abrec",
|
|
39
|
+
ARRAY['c', 'd'] as str_array,
|
|
40
|
+
array[1,2,3] as int_array,
|
|
41
|
+
ARRAY[${abrec}] as array_of_abrec
|
|
42
|
+
""")
|
|
43
|
+
`).malloyResultMatches(runtime, {});
|
|
44
|
+
}
|
|
45
|
+
);
|
|
42
46
|
|
|
43
47
|
it(`runs the to_unixtime function - ${databaseName}`, async () => {
|
|
44
48
|
await expect(`run: ${databaseName}.sql("SELECT 1 as n") -> {
|
|
@@ -313,12 +317,229 @@ describe.each(runtimes.runtimeList)(
|
|
|
313
317
|
query: 'first_param=val_one&second_param=2',
|
|
314
318
|
});
|
|
315
319
|
});
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
320
|
+
describe('various array functions', () => {
|
|
321
|
+
const nums = `${databaseName}.sql('SELECT ARRAY[4,1,1] as "nums"')`;
|
|
322
|
+
it('runs split function', async () => {
|
|
323
|
+
await expect(`
|
|
324
|
+
run: ${databaseName}.sql("SELECT 1 AS N") -> {
|
|
325
|
+
select: some_words is split('hello world', ' ')
|
|
326
|
+
}
|
|
327
|
+
`).malloyResultMatches(runtime, {some_words: ['hello', 'world']});
|
|
328
|
+
});
|
|
329
|
+
it.when(presto)('runs array_average', async () => {
|
|
330
|
+
await expect(
|
|
331
|
+
`run: ${nums}->{select: tavg is array_average(nums)}`
|
|
332
|
+
).malloyResultMatches(runtime, {tavg: 2});
|
|
333
|
+
});
|
|
334
|
+
it('runs array_distinct', async () => {
|
|
335
|
+
await expect(
|
|
336
|
+
`run: ${nums}->{select: t is array_distinct(nums)}`
|
|
337
|
+
).malloyResultMatches(runtime, {t: [4, 1]});
|
|
338
|
+
});
|
|
339
|
+
it.when(presto)('runs array_has_duplicates', async () => {
|
|
340
|
+
await expect(
|
|
341
|
+
`run: ${nums}->{select: t is array_has_duplicates(nums)}`
|
|
342
|
+
).malloyResultMatches(runtime, {t: true});
|
|
343
|
+
});
|
|
344
|
+
it('runs array_max', async () => {
|
|
345
|
+
await expect(
|
|
346
|
+
`run: ${nums}->{select: t is array_max(nums)}`
|
|
347
|
+
).malloyResultMatches(runtime, {t: 4});
|
|
348
|
+
});
|
|
349
|
+
it('runs array_min', async () => {
|
|
350
|
+
await expect(
|
|
351
|
+
`run: ${nums}->{select: t is array_min(nums)}`
|
|
352
|
+
).malloyResultMatches(runtime, {t: 1});
|
|
353
|
+
});
|
|
354
|
+
it.when(presto)('runs array_cum_sum', async () => {
|
|
355
|
+
await expect(
|
|
356
|
+
`run: ${nums}->{select: t is array_cum_sum(nums)}`
|
|
357
|
+
).malloyResultMatches(runtime, {t: [4, 5, 6]});
|
|
358
|
+
});
|
|
359
|
+
it.when(presto)('runs array_duplicates', async () => {
|
|
360
|
+
await expect(
|
|
361
|
+
`run: ${nums}->{select: t is array_duplicates(nums)}`
|
|
362
|
+
).malloyResultMatches(runtime, {t: [1]});
|
|
363
|
+
});
|
|
364
|
+
it('runs array_sort', async () => {
|
|
365
|
+
await expect(
|
|
366
|
+
`run: ${nums}->{select: t is array_sort(nums)}`
|
|
367
|
+
).malloyResultMatches(runtime, {t: [1, 1, 4]});
|
|
368
|
+
});
|
|
369
|
+
it('runs repeat', async () => {
|
|
370
|
+
await expect(
|
|
371
|
+
`run: ${nums}->{select: t is repeat('x', 2)}`
|
|
372
|
+
).malloyResultMatches(runtime, {t: ['x', 'x']});
|
|
373
|
+
});
|
|
374
|
+
it('runs slice', async () => {
|
|
375
|
+
await expect(
|
|
376
|
+
`run: ${nums}->{select: t is slice(nums, 2, 2)}`
|
|
377
|
+
).malloyResultMatches(runtime, {t: [1, 1]});
|
|
378
|
+
});
|
|
379
|
+
it('runs cardinality', async () => {
|
|
380
|
+
await expect(
|
|
381
|
+
`run: ${nums}->{select: t is cardinality(nums)}`
|
|
382
|
+
).malloyResultMatches(runtime, {t: 3});
|
|
383
|
+
});
|
|
384
|
+
it.when(presto)('runs array_sum', async () => {
|
|
385
|
+
await expect(
|
|
386
|
+
`run: ${nums}->{select: t is array_sum(nums)}`
|
|
387
|
+
).malloyResultMatches(runtime, {t: 6});
|
|
388
|
+
});
|
|
389
|
+
it('runs contains', async () => {
|
|
390
|
+
await expect(
|
|
391
|
+
`run: ${nums}->{select: t is contains(nums, 42)}`
|
|
392
|
+
).malloyResultMatches(runtime, {t: false});
|
|
393
|
+
});
|
|
394
|
+
it('runs array_except', async () => {
|
|
395
|
+
await expect(
|
|
396
|
+
`run: ${nums}->{select: t is array_except(nums, [4])}`
|
|
397
|
+
).malloyResultMatches(runtime, {t: [1]});
|
|
398
|
+
});
|
|
399
|
+
// mtoy todo figure out how to test this, maybe reconfigure test instance
|
|
400
|
+
it.skip('runs array_normalize', async () => {
|
|
401
|
+
await expect(`
|
|
402
|
+
# test.verbose
|
|
403
|
+
run: ${nums}->{select: t is array_normalize(nums, 40)}
|
|
404
|
+
`).malloyResultMatches(runtime, {t: [1, 0.25, 0.25]});
|
|
405
|
+
});
|
|
406
|
+
it.when(presto)('runs array_position', async () => {
|
|
407
|
+
await expect(
|
|
408
|
+
`run: ${nums}->{select: t is array_position(nums, 1, 2)}`
|
|
409
|
+
).malloyResultMatches(runtime, {t: 3});
|
|
410
|
+
});
|
|
411
|
+
it('runs array_remove', async () => {
|
|
412
|
+
await expect(
|
|
413
|
+
`run: ${nums}->{select: t is array_remove(nums, 1)}`
|
|
414
|
+
).malloyResultMatches(runtime, {t: [4]});
|
|
415
|
+
});
|
|
416
|
+
it.when(presto)('runs array_sort_desc', async () => {
|
|
417
|
+
await expect(
|
|
418
|
+
`run: ${nums}->{select: t is array_sort_desc([1,2,3])}`
|
|
419
|
+
).malloyResultMatches(runtime, {t: [3, 2, 1]});
|
|
420
|
+
});
|
|
421
|
+
// mtoy todo find why test instance doesn't have this fucntion
|
|
422
|
+
it.skip('runs array_split_into_chunks', async () => {
|
|
423
|
+
await expect(
|
|
424
|
+
`run: ${nums}->{select: t is array_split_into_chunks(nums, 1)}`
|
|
425
|
+
).malloyResultMatches(runtime, {t: [[4], [1], [1]]});
|
|
426
|
+
});
|
|
427
|
+
it('runs arrays_overlap', async () => {
|
|
428
|
+
await expect(
|
|
429
|
+
`run: ${nums}->{select: t is arrays_overlap(nums, [2,3,4])}`
|
|
430
|
+
).malloyResultMatches(runtime, {t: true});
|
|
431
|
+
});
|
|
432
|
+
it('runs arrays_union', async () => {
|
|
433
|
+
await expect(
|
|
434
|
+
`run: ${nums}->{select: t is array_union(nums, [2])}`
|
|
435
|
+
).malloyResultMatches(runtime, {t: [4, 1, 2]});
|
|
436
|
+
});
|
|
437
|
+
it.when(presto)('runs remove_nulls', async () => {
|
|
438
|
+
await expect(
|
|
439
|
+
`run: ${nums}->{select: t is remove_nulls([null, 2])}`
|
|
440
|
+
).malloyResultMatches(runtime, {t: [2]});
|
|
441
|
+
});
|
|
442
|
+
/// mtoy todo figure out overload
|
|
443
|
+
it.skip('runs reverse', async () => {
|
|
444
|
+
await expect(
|
|
445
|
+
`run: ${nums}->{select: t is reverse(nums)}`
|
|
446
|
+
).malloyResultMatches(runtime, {t: [1, 1, 4]});
|
|
447
|
+
});
|
|
448
|
+
it('runs shuffle', async () => {
|
|
449
|
+
await expect(
|
|
450
|
+
`run: ${nums}->{select: t is shuffle([1])}`
|
|
451
|
+
).malloyResultMatches(runtime, {t: [1]});
|
|
452
|
+
});
|
|
453
|
+
it.when(presto)('runs array_top_n', async () => {
|
|
454
|
+
await expect(
|
|
455
|
+
`run: ${nums}->{select: t is array_top_n(nums, 2)}`
|
|
456
|
+
).malloyResultMatches(runtime, {t: [4, 1]});
|
|
457
|
+
});
|
|
458
|
+
it('runs combinations', async () => {
|
|
459
|
+
await expect(
|
|
460
|
+
`run: ${nums}->{select: t is combinations([1,2,3], 2)}`
|
|
461
|
+
).malloyResultMatches(runtime, {
|
|
462
|
+
t: [
|
|
463
|
+
[1, 2],
|
|
464
|
+
[1, 3],
|
|
465
|
+
[2, 3],
|
|
466
|
+
],
|
|
467
|
+
});
|
|
468
|
+
});
|
|
469
|
+
it('runs element_at', async () => {
|
|
470
|
+
await expect(
|
|
471
|
+
`run: ${nums}->{select: t is element_at(nums, 1)}`
|
|
472
|
+
).malloyResultMatches(runtime, {t: 4});
|
|
473
|
+
});
|
|
474
|
+
it('runs flatten', async () => {
|
|
475
|
+
await expect(
|
|
476
|
+
`run: ${nums}->{select: t is flatten([[1], [2]])}`
|
|
477
|
+
).malloyResultMatches(runtime, {t: [1, 2]});
|
|
478
|
+
});
|
|
479
|
+
it('runs ngrams', async () => {
|
|
480
|
+
await expect(
|
|
481
|
+
`run: ${nums}->{select: t is ngrams([1,2,3], 2)}`
|
|
482
|
+
).malloyResultMatches(runtime, {
|
|
483
|
+
t: [
|
|
484
|
+
[1, 2],
|
|
485
|
+
[2, 3],
|
|
486
|
+
],
|
|
487
|
+
});
|
|
488
|
+
});
|
|
489
|
+
it('runs trim_array', async () => {
|
|
490
|
+
await expect(
|
|
491
|
+
`run: ${nums}->{select: t is trim_array(nums, 2)}`
|
|
492
|
+
).malloyResultMatches(runtime, {t: [4]});
|
|
493
|
+
});
|
|
494
|
+
it('runs sequence(n1,n2)', async () => {
|
|
495
|
+
await expect(
|
|
496
|
+
`run: ${nums}->{select: t is sequence(1,2)}`
|
|
497
|
+
).malloyResultMatches(runtime, {t: [1, 2]});
|
|
498
|
+
});
|
|
499
|
+
it('runs sequence(n1,n2,n3)', async () => {
|
|
500
|
+
await expect(
|
|
501
|
+
`run: ${nums}->{select: t is sequence(10, 20, 10)}`
|
|
502
|
+
).malloyResultMatches(runtime, {t: [10, 20]});
|
|
503
|
+
});
|
|
504
|
+
// mtoy todo figure out how to write test
|
|
505
|
+
it.skip('runs sequence(d1,d2)', async () => {
|
|
506
|
+
await expect(
|
|
507
|
+
`run: ${nums}->{select: t is sequence(@2001-01-01, @2001-01-02)}`
|
|
508
|
+
).malloyResultMatches(runtime, {
|
|
509
|
+
t: [new Date('2001-01-01'), new Date('2001-01-02')],
|
|
510
|
+
});
|
|
511
|
+
});
|
|
512
|
+
it('runs array_intersect(a1,a2)', async () => {
|
|
513
|
+
await expect(
|
|
514
|
+
`run: ${nums}->{select: t is array_intersect(nums, [4])}`
|
|
515
|
+
).malloyResultMatches(runtime, {t: [4]});
|
|
516
|
+
});
|
|
517
|
+
it.when(presto)('runs array_intersect(a)', async () => {
|
|
518
|
+
await expect(
|
|
519
|
+
`run: ${nums}->{select: t is array_intersect([[1,2], [2,3]])}`
|
|
520
|
+
).malloyResultMatches(runtime, {t: [2]});
|
|
521
|
+
});
|
|
522
|
+
it('runs array_join(a,s)', async () => {
|
|
523
|
+
await expect(
|
|
524
|
+
`run: ${nums}->{select: t is array_join(nums, ',')}`
|
|
525
|
+
).malloyResultMatches(runtime, {t: '4,1,1'});
|
|
526
|
+
});
|
|
527
|
+
it('runs array_join(a,s, n)', async () => {
|
|
528
|
+
await expect(
|
|
529
|
+
`run: ${nums}->{select: t is array_join(['a', null], ',', 'x')}`
|
|
530
|
+
).malloyResultMatches(runtime, {t: 'a,x'});
|
|
531
|
+
});
|
|
532
|
+
it.when(presto)('runs array_least_frequent(a)', async () => {
|
|
533
|
+
await expect(
|
|
534
|
+
`run: ${nums}->{select: t is array_least_frequent(nums)}`
|
|
535
|
+
).malloyResultMatches(runtime, {t: [4]});
|
|
536
|
+
});
|
|
537
|
+
it.when(presto)('runs array_least_frequent(a, n)', async () => {
|
|
538
|
+
await expect(
|
|
539
|
+
`run: ${nums}->{select: t is array_least_frequent(nums, 2)}`
|
|
540
|
+
).malloyResultMatches(runtime, {t: [4, 1]});
|
|
541
|
+
});
|
|
542
|
+
// mtoy todo document missing lambda sort
|
|
322
543
|
});
|
|
323
544
|
}
|
|
324
545
|
);
|