@malloydata/malloy-tests 0.0.294 → 0.0.296
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/README.md +15 -13
- package/package.json +9 -9
- package/src/databases/presto-trino/presto-trino.spec.ts +54 -0
package/README.md
CHANGED
|
@@ -13,7 +13,7 @@ Assumes that postgres has been installed via nix (installs but doesn't configure
|
|
|
13
13
|
ADD to environment: `export PGHOST=localhost`
|
|
14
14
|
|
|
15
15
|
**postgres_init.sh** - builds a database as the current user in .tmp/data/malloytestdb. Starts server running on localhost:5432
|
|
16
|
-
copies the test data in `malloytest-postgres.sql.gz` into the database.
|
|
16
|
+
copies the test data in `malloytest-postgres.sql.gz` into the database. - You may also need to add state_facts.sql for some tests
|
|
17
17
|
|
|
18
18
|
**postgres_start.sh** - starts the postgres server, once it has been installed (use after a reboot, for example)
|
|
19
19
|
|
|
@@ -30,7 +30,7 @@ Setting up DuckDB:
|
|
|
30
30
|
|
|
31
31
|
# Using the custom matcher for running queries
|
|
32
32
|
|
|
33
|
-
There is now a custom matcher, `malloyResultMatches` for running queries.
|
|
33
|
+
There is now a custom matcher, `malloyResultMatches` for running queries. The customer matcher makes it easy to write readable tests which need to look at query results, and produces useful output when the test fails to make it easier to develop tests or respond to the output of failing tests.
|
|
34
34
|
|
|
35
35
|
## Check for results in the first row of output
|
|
36
36
|
|
|
@@ -54,9 +54,9 @@ import './util/db-jest-matchers';
|
|
|
54
54
|
|
|
55
55
|
This will check the following things.
|
|
56
56
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
57
|
+
- There is at least one row of data in the output. So `.malloyQueryMatches(rt, {})` will fail if the query returns no rows
|
|
58
|
+
- There are entries in that row for each key. `{}` matches any row
|
|
59
|
+
- The entries are equal, but it will error if the expected data as a number and the returned data is a string.
|
|
60
60
|
|
|
61
61
|
## Accessing nested results
|
|
62
62
|
|
|
@@ -79,11 +79,11 @@ example also shows passing a model instead of a runtime to the matcher.
|
|
|
79
79
|
});
|
|
80
80
|
```
|
|
81
81
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
82
|
+
> [!WARNING]
|
|
83
|
+
> There is currently a ... feature ... where if the source code of a test
|
|
84
|
+
> contains the characters `nest:` and the runtime connection does not support nesting,
|
|
85
|
+
> the test passes without actually doing anything. There will better handling of
|
|
86
|
+
> this problem in the future, but if your test is mysteriously passing, this is why.
|
|
87
87
|
|
|
88
88
|
## Queries returning more than one row of data
|
|
89
89
|
|
|
@@ -102,8 +102,8 @@ An array of match rows may can also be used, if the test needs to verify more th
|
|
|
102
102
|
|
|
103
103
|
This will pass if ..
|
|
104
104
|
|
|
105
|
-
|
|
106
|
-
|
|
105
|
+
- There are exactly two rows of output. If there are not exactly two the matcher will fail. If the query makes more than two rows, you will need to add a `limit: 2` to allow the matcher to pass.
|
|
106
|
+
- Each row is matches the matching criteria, again `{}` means "pass if there is a row"
|
|
107
107
|
|
|
108
108
|
## Reading failure output
|
|
109
109
|
|
|
@@ -235,7 +235,9 @@ The old template for a test looked something like
|
|
|
235
235
|
```
|
|
236
236
|
|
|
237
237
|
The actual matcher for a result is limited to an equality test, in the old pattern you would have written something using an existing matcher for a data value
|
|
238
|
+
|
|
238
239
|
```TypeScript
|
|
239
240
|
expect(result.data.patch(0, 'numThings').value).toBeGreaterThan(7);
|
|
240
241
|
```
|
|
241
|
-
|
|
242
|
+
|
|
243
|
+
and if this is desirable, more work on the custom matcher would be needed to allow expressions like this to be written.
|
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.296",
|
|
25
|
+
"@malloydata/db-duckdb": "0.0.296",
|
|
26
|
+
"@malloydata/db-postgres": "0.0.296",
|
|
27
|
+
"@malloydata/db-snowflake": "0.0.296",
|
|
28
|
+
"@malloydata/db-trino": "0.0.296",
|
|
29
|
+
"@malloydata/malloy": "0.0.296",
|
|
30
|
+
"@malloydata/malloy-tag": "0.0.296",
|
|
31
|
+
"@malloydata/render": "0.0.296",
|
|
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.296"
|
|
42
42
|
}
|
|
@@ -27,6 +27,60 @@ describe.each(runtimes.runtimeList)(
|
|
|
27
27
|
`run: ${databaseName}.sql("SELECT 1 as n") -> { select: n }`
|
|
28
28
|
).malloyResultMatches(runtime, {n: 1});
|
|
29
29
|
});
|
|
30
|
+
|
|
31
|
+
describe('HLL Window Functions', () => {
|
|
32
|
+
it(`hll_accumulate_moving function - ${databaseName}`, async () => {
|
|
33
|
+
await expect(`run: ${databaseName}.sql("""
|
|
34
|
+
SELECT 'A' as category, 'value1' as val, 1 as seq
|
|
35
|
+
UNION ALL SELECT 'A' as category, 'value2' as val, 2 as seq
|
|
36
|
+
UNION ALL SELECT 'B' as category, 'value1' as val, 1 as seq
|
|
37
|
+
UNION ALL SELECT 'B' as category, 'value3' as val, 2 as seq
|
|
38
|
+
""") -> {
|
|
39
|
+
group_by: category
|
|
40
|
+
order_by: category, seq
|
|
41
|
+
calculate: hll_moving is hll_estimate_moving(hll_accumulate_moving(val, 1), 1)
|
|
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)
|
|
58
|
+
} -> {
|
|
59
|
+
order_by: category
|
|
60
|
+
calculate: combined_hll is hll_estimate_moving(hll_combine_moving(hll_set, 1), 1)
|
|
61
|
+
}`).malloyResultMatches(runtime, [
|
|
62
|
+
{category: 'A', combined_hll: 2},
|
|
63
|
+
{category: 'B', combined_hll: 1},
|
|
64
|
+
]);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it(`hll_estimate_moving function - ${databaseName}`, async () => {
|
|
68
|
+
await expect(`run: ${databaseName}.sql("""
|
|
69
|
+
SELECT 'A' as category, 'value1' as val, 1 as seq
|
|
70
|
+
UNION ALL SELECT 'A' as category, 'value2' as val, 2 as seq
|
|
71
|
+
UNION ALL SELECT 'B' as category, 'value1' as val, 1 as seq
|
|
72
|
+
""") -> {
|
|
73
|
+
group_by: category
|
|
74
|
+
aggregate: hll_set is hll_accumulate(val)
|
|
75
|
+
} -> {
|
|
76
|
+
order_by: category
|
|
77
|
+
calculate: estimated_count is hll_estimate_moving(hll_set, 1)
|
|
78
|
+
}`).malloyResultMatches(runtime, [
|
|
79
|
+
{category: 'A', estimated_count: 2},
|
|
80
|
+
{category: 'B', estimated_count: 1},
|
|
81
|
+
]);
|
|
82
|
+
});
|
|
83
|
+
});
|
|
30
84
|
test.when(databaseName === 'presto')(
|
|
31
85
|
'schema parser does not throw on compound types',
|
|
32
86
|
async () => {
|