@malloydata/malloy-tests 0.0.296 → 0.0.298
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,14 +21,14 @@
|
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"@jest/globals": "^29.4.3",
|
|
24
|
-
"@malloydata/db-bigquery": "0.0.
|
|
25
|
-
"@malloydata/db-duckdb": "0.0.
|
|
26
|
-
"@malloydata/db-postgres": "0.0.
|
|
27
|
-
"@malloydata/db-snowflake": "0.0.
|
|
28
|
-
"@malloydata/db-trino": "0.0.
|
|
29
|
-
"@malloydata/malloy": "0.0.
|
|
30
|
-
"@malloydata/malloy-tag": "0.0.
|
|
31
|
-
"@malloydata/render": "0.0.
|
|
24
|
+
"@malloydata/db-bigquery": "0.0.298",
|
|
25
|
+
"@malloydata/db-duckdb": "0.0.298",
|
|
26
|
+
"@malloydata/db-postgres": "0.0.298",
|
|
27
|
+
"@malloydata/db-snowflake": "0.0.298",
|
|
28
|
+
"@malloydata/db-trino": "0.0.298",
|
|
29
|
+
"@malloydata/malloy": "0.0.298",
|
|
30
|
+
"@malloydata/malloy-tag": "0.0.298",
|
|
31
|
+
"@malloydata/render": "0.0.298",
|
|
32
32
|
"events": "^3.3.0",
|
|
33
33
|
"jsdom": "^22.1.0",
|
|
34
34
|
"luxon": "^2.4.0",
|
|
@@ -38,5 +38,5 @@
|
|
|
38
38
|
"@types/jsdom": "^21.1.1",
|
|
39
39
|
"@types/luxon": "^2.4.0"
|
|
40
40
|
},
|
|
41
|
-
"version": "0.0.
|
|
41
|
+
"version": "0.0.298"
|
|
42
42
|
}
|
|
@@ -29,43 +29,35 @@ describe.each(runtimes.runtimeList)(
|
|
|
29
29
|
});
|
|
30
30
|
|
|
31
31
|
describe('HLL Window Functions', () => {
|
|
32
|
-
it(
|
|
33
|
-
|
|
32
|
+
it.when(presto)(
|
|
33
|
+
`hll_accumulate_moving function - ${databaseName}`,
|
|
34
|
+
async () => {
|
|
35
|
+
await expect(`run: ${databaseName}.sql("""
|
|
34
36
|
SELECT 'A' as category, 'value1' as val, 1 as seq
|
|
35
37
|
UNION ALL SELECT 'A' as category, 'value2' as val, 2 as seq
|
|
36
38
|
UNION ALL SELECT 'B' as category, 'value1' as val, 1 as seq
|
|
37
39
|
UNION ALL SELECT 'B' as category, 'value3' as val, 2 as seq
|
|
38
40
|
""") -> {
|
|
39
|
-
|
|
41
|
+
select: *
|
|
40
42
|
order_by: category, seq
|
|
41
|
-
calculate:
|
|
42
|
-
}`).malloyResultMatches(runtime, [
|
|
43
|
-
{category: 'A', hll_moving: 1},
|
|
44
|
-
{category: 'A', hll_moving: 2},
|
|
45
|
-
{category: 'B', hll_moving: 1},
|
|
46
|
-
{category: 'B', hll_moving: 1},
|
|
47
|
-
]);
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it(`hll_combine_moving function - ${databaseName}`, async () => {
|
|
51
|
-
await expect(`run: ${databaseName}.sql("""
|
|
52
|
-
SELECT 'A' as category, 'value1' as val, 1 as seq
|
|
53
|
-
UNION ALL SELECT 'A' as category, 'value2' as val, 2 as seq
|
|
54
|
-
UNION ALL SELECT 'B' as category, 'value1' as val, 1 as seq
|
|
55
|
-
""") -> {
|
|
56
|
-
group_by: category
|
|
57
|
-
aggregate: hll_set is hll_accumulate(val)
|
|
43
|
+
calculate: hll_acc is hll_accumulate_moving(val, 1)
|
|
58
44
|
} -> {
|
|
59
|
-
|
|
60
|
-
|
|
45
|
+
select:
|
|
46
|
+
*
|
|
47
|
+
hll_moving is hll_estimate(hll_acc)
|
|
61
48
|
}`).malloyResultMatches(runtime, [
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
49
|
+
{category: 'A', val: 'value1', seq: 1, hll_moving: 1},
|
|
50
|
+
{category: 'A', val: 'value2', seq: 2, hll_moving: 2},
|
|
51
|
+
{category: 'B', val: 'value1', seq: 1, hll_moving: 2},
|
|
52
|
+
{category: 'B', val: 'value3', seq: 2, hll_moving: 2},
|
|
53
|
+
]);
|
|
54
|
+
}
|
|
55
|
+
);
|
|
66
56
|
|
|
67
|
-
it(
|
|
68
|
-
|
|
57
|
+
it.when(presto)(
|
|
58
|
+
`hll_combine_moving function - ${databaseName}`,
|
|
59
|
+
async () => {
|
|
60
|
+
await expect(`run: ${databaseName}.sql("""
|
|
69
61
|
SELECT 'A' as category, 'value1' as val, 1 as seq
|
|
70
62
|
UNION ALL SELECT 'A' as category, 'value2' as val, 2 as seq
|
|
71
63
|
UNION ALL SELECT 'B' as category, 'value1' as val, 1 as seq
|
|
@@ -73,13 +65,19 @@ describe.each(runtimes.runtimeList)(
|
|
|
73
65
|
group_by: category
|
|
74
66
|
aggregate: hll_set is hll_accumulate(val)
|
|
75
67
|
} -> {
|
|
68
|
+
select: *
|
|
76
69
|
order_by: category
|
|
77
|
-
calculate:
|
|
70
|
+
calculate: combined_hll is hll_combine_moving(hll_set, 1)
|
|
71
|
+
} -> {
|
|
72
|
+
select:
|
|
73
|
+
*
|
|
74
|
+
final_count is hll_estimate(combined_hll)
|
|
78
75
|
}`).malloyResultMatches(runtime, [
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
76
|
+
{category: 'A', final_count: 2},
|
|
77
|
+
{category: 'B', final_count: 2},
|
|
78
|
+
]);
|
|
79
|
+
}
|
|
80
|
+
);
|
|
83
81
|
});
|
|
84
82
|
test.when(databaseName === 'presto')(
|
|
85
83
|
'schema parser does not throw on compound types',
|
|
@@ -652,6 +650,236 @@ describe.each(runtimes.runtimeList)(
|
|
|
652
650
|
""") -> { aggregate: n is count() }
|
|
653
651
|
`).matchesRows(runtime, {n: 1});
|
|
654
652
|
});
|
|
653
|
+
|
|
654
|
+
describe('T-Digest functions', () => {
|
|
655
|
+
const testData = `${databaseName}.sql("""
|
|
656
|
+
SELECT CAST(1.0 AS DOUBLE) as n, CAST(1 AS BIGINT) as w
|
|
657
|
+
UNION ALL SELECT CAST(2.0 AS DOUBLE) as n, CAST(2 AS BIGINT) as w
|
|
658
|
+
UNION ALL SELECT CAST(3.0 AS DOUBLE) as n, CAST(1 AS BIGINT) as w
|
|
659
|
+
UNION ALL SELECT CAST(4.0 AS DOUBLE) as n, CAST(3 AS BIGINT) as w
|
|
660
|
+
UNION ALL SELECT CAST(5.0 AS DOUBLE) as n, CAST(1 AS BIGINT) as w
|
|
661
|
+
UNION ALL SELECT CAST(6.0 AS DOUBLE) as n, CAST(2 AS BIGINT) as w
|
|
662
|
+
UNION ALL SELECT CAST(7.0 AS DOUBLE) as n, CAST(1 AS BIGINT) as w
|
|
663
|
+
UNION ALL SELECT CAST(8.0 AS DOUBLE) as n, CAST(2 AS BIGINT) as w
|
|
664
|
+
UNION ALL SELECT CAST(9.0 AS DOUBLE) as n, CAST(1 AS BIGINT) as w
|
|
665
|
+
UNION ALL SELECT CAST(10.0 AS DOUBLE) as n, CAST(3 AS BIGINT) as w
|
|
666
|
+
""")`;
|
|
667
|
+
|
|
668
|
+
it.when(presto)(
|
|
669
|
+
`runs the basic tdigest_agg function - ${databaseName}`,
|
|
670
|
+
async () => {
|
|
671
|
+
await expect(`run: ${testData} -> {
|
|
672
|
+
aggregate:
|
|
673
|
+
median is value_at_quantile(tdigest_agg(n), 0.5)
|
|
674
|
+
}`).malloyResultMatches(runtime, {
|
|
675
|
+
median: 6,
|
|
676
|
+
});
|
|
677
|
+
}
|
|
678
|
+
);
|
|
679
|
+
|
|
680
|
+
it.when(presto)(
|
|
681
|
+
`runs the tdigest_agg with weight function - ${databaseName}`,
|
|
682
|
+
async () => {
|
|
683
|
+
await expect(`run: ${testData} -> {
|
|
684
|
+
aggregate:
|
|
685
|
+
weighted_median is value_at_quantile(tdigest_agg(n, w), 0.5)
|
|
686
|
+
}`).malloyResultMatches(runtime, {
|
|
687
|
+
weighted_median: 5.5,
|
|
688
|
+
});
|
|
689
|
+
}
|
|
690
|
+
);
|
|
691
|
+
|
|
692
|
+
it.when(presto)(
|
|
693
|
+
`runs the tdigest_agg with weight and compression function - ${databaseName}`,
|
|
694
|
+
async () => {
|
|
695
|
+
await expect(`run: ${testData} -> {
|
|
696
|
+
aggregate:
|
|
697
|
+
compressed_median is value_at_quantile(tdigest_agg(n, w, 100), 0.5)
|
|
698
|
+
}`).malloyResultMatches(runtime, {
|
|
699
|
+
compressed_median: 5.5,
|
|
700
|
+
});
|
|
701
|
+
}
|
|
702
|
+
);
|
|
703
|
+
|
|
704
|
+
it.when(presto)(
|
|
705
|
+
`runs the value_at_quantile function - ${databaseName}`,
|
|
706
|
+
async () => {
|
|
707
|
+
await expect(`run: ${testData} -> {
|
|
708
|
+
aggregate:
|
|
709
|
+
q25 is value_at_quantile(tdigest_agg(n), 0.25)
|
|
710
|
+
q50 is value_at_quantile(tdigest_agg(n), 0.5)
|
|
711
|
+
q75 is value_at_quantile(tdigest_agg(n), 0.75)
|
|
712
|
+
q90 is value_at_quantile(tdigest_agg(n), 0.9)
|
|
713
|
+
}`).malloyResultMatches(runtime, {
|
|
714
|
+
q25: 3,
|
|
715
|
+
q50: 6,
|
|
716
|
+
q75: 8,
|
|
717
|
+
q90: 10,
|
|
718
|
+
});
|
|
719
|
+
}
|
|
720
|
+
);
|
|
721
|
+
|
|
722
|
+
it.when(presto)(
|
|
723
|
+
`runs the quantile_at_value function - ${databaseName}`,
|
|
724
|
+
async () => {
|
|
725
|
+
await expect(`run: ${testData} -> {
|
|
726
|
+
aggregate:
|
|
727
|
+
q_at_5 is quantile_at_value(tdigest_agg(n), 5.0)
|
|
728
|
+
q_at_2 is quantile_at_value(tdigest_agg(n), 2.0)
|
|
729
|
+
q_at_8 is quantile_at_value(tdigest_agg(n), 8.0)
|
|
730
|
+
}`).malloyResultMatches(runtime, {
|
|
731
|
+
q_at_5: 0.45,
|
|
732
|
+
q_at_2: 0.15,
|
|
733
|
+
q_at_8: 0.75,
|
|
734
|
+
});
|
|
735
|
+
}
|
|
736
|
+
);
|
|
737
|
+
|
|
738
|
+
it.when(presto)(
|
|
739
|
+
`runs the values_at_quantiles function - ${databaseName}`,
|
|
740
|
+
async () => {
|
|
741
|
+
await expect(`run: ${testData} -> {
|
|
742
|
+
aggregate:
|
|
743
|
+
quantiles is values_at_quantiles(tdigest_agg(n), [0.25, 0.5, 0.75])
|
|
744
|
+
}`).malloyResultMatches(runtime, {
|
|
745
|
+
quantiles: [3, 6, 8],
|
|
746
|
+
});
|
|
747
|
+
}
|
|
748
|
+
);
|
|
749
|
+
|
|
750
|
+
it.when(presto)(
|
|
751
|
+
`runs the scale_tdigest function - ${databaseName}`,
|
|
752
|
+
async () => {
|
|
753
|
+
await expect(`run: ${testData} -> {
|
|
754
|
+
aggregate:
|
|
755
|
+
original_median is value_at_quantile(tdigest_agg(n), 0.5)
|
|
756
|
+
scaled_median is value_at_quantile(scale_tdigest(tdigest_agg(n), 2.0), 0.5)
|
|
757
|
+
}`).malloyResultMatches(runtime, {
|
|
758
|
+
original_median: 6,
|
|
759
|
+
scaled_median: 5.5,
|
|
760
|
+
});
|
|
761
|
+
}
|
|
762
|
+
);
|
|
763
|
+
|
|
764
|
+
it.when(presto)(
|
|
765
|
+
`runs the trimmed_mean function - ${databaseName}`,
|
|
766
|
+
async () => {
|
|
767
|
+
await expect(`run: ${testData} -> {
|
|
768
|
+
aggregate:
|
|
769
|
+
trimmed_mean_10_90 is trimmed_mean(tdigest_agg(n), 0.1, 0.9)
|
|
770
|
+
trimmed_mean_25_75 is trimmed_mean(tdigest_agg(n), 0.25, 0.75)
|
|
771
|
+
}`).malloyResultMatches(runtime, {
|
|
772
|
+
trimmed_mean_10_90: 6,
|
|
773
|
+
trimmed_mean_25_75: 5.5,
|
|
774
|
+
});
|
|
775
|
+
}
|
|
776
|
+
);
|
|
777
|
+
|
|
778
|
+
it.when(presto)(
|
|
779
|
+
`runs the merge tdigest function - ${databaseName}`,
|
|
780
|
+
async () => {
|
|
781
|
+
await expect(`run: ${testData} -> {
|
|
782
|
+
group_by: group_col is case when n <= 5 then 'A' else 'B' end
|
|
783
|
+
aggregate: td is tdigest_agg(n)
|
|
784
|
+
} -> {
|
|
785
|
+
aggregate:
|
|
786
|
+
overall_median is value_at_quantile(merge_tdigest(td), 0.5)
|
|
787
|
+
}`).malloyResultMatches(runtime, {
|
|
788
|
+
overall_median: 6,
|
|
789
|
+
});
|
|
790
|
+
}
|
|
791
|
+
);
|
|
792
|
+
|
|
793
|
+
it.when(presto)(
|
|
794
|
+
`runs the merge_tdigest array function - ${databaseName}`,
|
|
795
|
+
async () => {
|
|
796
|
+
await expect(`run: ${testData} -> {
|
|
797
|
+
group_by: group_col is case when n <= 5 then 'A' else 'B' end
|
|
798
|
+
aggregate: td is tdigest_agg(n)
|
|
799
|
+
} -> {
|
|
800
|
+
aggregate:
|
|
801
|
+
overall_median is value_at_quantile(merge_tdigest_array(array_agg(td)), 0.5)
|
|
802
|
+
}`).malloyResultMatches(runtime, {
|
|
803
|
+
overall_median: 6,
|
|
804
|
+
});
|
|
805
|
+
}
|
|
806
|
+
);
|
|
807
|
+
|
|
808
|
+
it.skip(`runs the destructure_tdigest function - ${databaseName}`, async () => {
|
|
809
|
+
// TODO: Fix this test - destructure_tdigest returns a record type
|
|
810
|
+
// which needs special handling in the test
|
|
811
|
+
await expect(`run: ${testData} -> {
|
|
812
|
+
aggregate:
|
|
813
|
+
destructured is destructure_tdigest(tdigest_agg(n))
|
|
814
|
+
}`).malloyResultMatches(runtime, {
|
|
815
|
+
destructured: {
|
|
816
|
+
centroid_means: [],
|
|
817
|
+
centroid_weights: [],
|
|
818
|
+
min_value: 1.0,
|
|
819
|
+
max_value: 10.0,
|
|
820
|
+
sum_value: 55.0,
|
|
821
|
+
count_value: 10,
|
|
822
|
+
},
|
|
823
|
+
});
|
|
824
|
+
});
|
|
825
|
+
|
|
826
|
+
it.skip(`runs the construct_tdigest function - ${databaseName}`, async () => {
|
|
827
|
+
// This test is complex because construct_tdigest needs the output of destructure_tdigest
|
|
828
|
+
// For now, we'll test that the function exists and can be called with sample data
|
|
829
|
+
await expect(`run: ${databaseName}.sql("SELECT 1 as dummy") -> {
|
|
830
|
+
select:
|
|
831
|
+
test_construct is value_at_quantile(
|
|
832
|
+
construct_tdigest(
|
|
833
|
+
[1.0, 2.0, 3.0],
|
|
834
|
+
[1.0, 1.0, 1.0],
|
|
835
|
+
1.0,
|
|
836
|
+
3.0,
|
|
837
|
+
6.0,
|
|
838
|
+
3.0,
|
|
839
|
+
100
|
|
840
|
+
),
|
|
841
|
+
0.5
|
|
842
|
+
)
|
|
843
|
+
}`).malloyResultMatches(runtime, {
|
|
844
|
+
test_construct: 2,
|
|
845
|
+
});
|
|
846
|
+
});
|
|
847
|
+
|
|
848
|
+
it.when(presto)(
|
|
849
|
+
`runs tdigest functions with edge cases - ${databaseName}`,
|
|
850
|
+
async () => {
|
|
851
|
+
const singleValueData = `${databaseName}.sql("SELECT CAST(5.0 AS DOUBLE) as n")`;
|
|
852
|
+
await expect(`run: ${singleValueData} -> {
|
|
853
|
+
aggregate:
|
|
854
|
+
median is value_at_quantile(tdigest_agg(n), 0.5)
|
|
855
|
+
q25 is value_at_quantile(tdigest_agg(n), 0.25)
|
|
856
|
+
q75 is value_at_quantile(tdigest_agg(n), 0.75)
|
|
857
|
+
}`).malloyResultMatches(runtime, {
|
|
858
|
+
median: 5.0,
|
|
859
|
+
q25: 5.0,
|
|
860
|
+
q75: 5.0,
|
|
861
|
+
});
|
|
862
|
+
}
|
|
863
|
+
);
|
|
864
|
+
|
|
865
|
+
it.when(presto)(
|
|
866
|
+
`runs tdigest functions with extreme quantiles - ${databaseName}`,
|
|
867
|
+
async () => {
|
|
868
|
+
await expect(`run: ${testData} -> {
|
|
869
|
+
aggregate:
|
|
870
|
+
min_quantile is value_at_quantile(tdigest_agg(n), 0.0)
|
|
871
|
+
max_quantile is value_at_quantile(tdigest_agg(n), 1.0)
|
|
872
|
+
q_at_min is quantile_at_value(tdigest_agg(n), 1.0)
|
|
873
|
+
q_at_max is quantile_at_value(tdigest_agg(n), 10.0)
|
|
874
|
+
}`).malloyResultMatches(runtime, {
|
|
875
|
+
min_quantile: 1,
|
|
876
|
+
max_quantile: 10,
|
|
877
|
+
q_at_min: 0.05,
|
|
878
|
+
q_at_max: 0.95,
|
|
879
|
+
});
|
|
880
|
+
}
|
|
881
|
+
);
|
|
882
|
+
});
|
|
655
883
|
}
|
|
656
884
|
);
|
|
657
885
|
|