@malloydata/malloy-tests 0.0.191-dev240925232958 → 0.0.191-dev240927225523
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.191-
|
|
25
|
-
"@malloydata/db-duckdb": "^0.0.191-
|
|
26
|
-
"@malloydata/db-postgres": "^0.0.191-
|
|
27
|
-
"@malloydata/db-snowflake": "^0.0.191-
|
|
28
|
-
"@malloydata/db-trino": "^0.0.191-
|
|
29
|
-
"@malloydata/malloy": "^0.0.191-
|
|
30
|
-
"@malloydata/render": "^0.0.191-
|
|
24
|
+
"@malloydata/db-bigquery": "^0.0.191-dev240927225523",
|
|
25
|
+
"@malloydata/db-duckdb": "^0.0.191-dev240927225523",
|
|
26
|
+
"@malloydata/db-postgres": "^0.0.191-dev240927225523",
|
|
27
|
+
"@malloydata/db-snowflake": "^0.0.191-dev240927225523",
|
|
28
|
+
"@malloydata/db-trino": "^0.0.191-dev240927225523",
|
|
29
|
+
"@malloydata/malloy": "^0.0.191-dev240927225523",
|
|
30
|
+
"@malloydata/render": "^0.0.191-dev240927225523",
|
|
31
31
|
"jsdom": "^22.1.0",
|
|
32
32
|
"luxon": "^2.4.0",
|
|
33
33
|
"madge": "^6.0.0"
|
|
@@ -36,5 +36,5 @@
|
|
|
36
36
|
"@types/jsdom": "^21.1.1",
|
|
37
37
|
"@types/luxon": "^2.4.0"
|
|
38
38
|
},
|
|
39
|
-
"version": "0.0.191-
|
|
39
|
+
"version": "0.0.191-dev240927225523"
|
|
40
40
|
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import {RuntimeList} from '../../runtimes';
|
|
9
|
+
import '../../util/db-jest-matchers';
|
|
10
|
+
import {describeIfDatabaseAvailable} from '../../util';
|
|
11
|
+
|
|
12
|
+
const runtimes = ['duckdb', 'duckdb_wasm'];
|
|
13
|
+
const [describe, databases] = describeIfDatabaseAvailable(runtimes);
|
|
14
|
+
const allDucks = new RuntimeList(databases);
|
|
15
|
+
|
|
16
|
+
describe.each(allDucks.runtimeList)('duckdb:%s', (dbName, runtime) => {
|
|
17
|
+
it('materialized top level query is replaced and added to queries to materialize', async () => {
|
|
18
|
+
const query = `
|
|
19
|
+
# materialize
|
|
20
|
+
query: myMaterializedQuery is duckdb.sql("select 1 as one, 'word' as word") -> {
|
|
21
|
+
select:
|
|
22
|
+
two is one + 1
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
source: foo is myMaterializedQuery extend {
|
|
26
|
+
view: fooview is {
|
|
27
|
+
select:
|
|
28
|
+
three is two + 1
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
run: foo -> fooview;
|
|
33
|
+
`;
|
|
34
|
+
|
|
35
|
+
const qm = runtime.loadQuery(query, {replaceMaterializedReferences: true});
|
|
36
|
+
const preparedResult = await qm.getPreparedResult();
|
|
37
|
+
|
|
38
|
+
expect(preparedResult.sql).toBe(
|
|
39
|
+
'SELECT \n base."two"+1 as "three"\nFROM myMaterializedQuery-6037d4be-8b92-5ea7-95a0-27bd26c240ca as base\n'
|
|
40
|
+
);
|
|
41
|
+
expect(preparedResult.dependenciesToMaterialize).toStrictEqual({
|
|
42
|
+
'myMaterializedQuery-6037d4be-8b92-5ea7-95a0-27bd26c240ca': {
|
|
43
|
+
'id': '6037d4be-8b92-5ea7-95a0-27bd26c240ca',
|
|
44
|
+
'path': 'internal://internal.malloy',
|
|
45
|
+
'queryName': 'myMaterializedQuery',
|
|
46
|
+
'source': undefined,
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('materialized multiple levels', async () => {
|
|
52
|
+
const query = `
|
|
53
|
+
# materialize
|
|
54
|
+
query: myMaterializedQuery is duckdb.sql("select 1 as one, 'word' as word") -> {
|
|
55
|
+
select:
|
|
56
|
+
two is one + 1
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
# materialize
|
|
60
|
+
query: secondLevelMaterializedQuery is myMaterializedQuery -> {
|
|
61
|
+
select:
|
|
62
|
+
three is two + 1
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
source: foo is secondLevelMaterializedQuery extend {
|
|
66
|
+
view: fooview is {
|
|
67
|
+
select:
|
|
68
|
+
four is three + 1
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
run: foo -> fooview;
|
|
73
|
+
`;
|
|
74
|
+
|
|
75
|
+
const qm = runtime.loadQuery(query, {replaceMaterializedReferences: true});
|
|
76
|
+
const preparedResult = await qm.getPreparedResult();
|
|
77
|
+
|
|
78
|
+
expect(preparedResult.sql).toBe(
|
|
79
|
+
'SELECT \n base."three"+1 as "four"\nFROM secondLevelMaterializedQuery-bd80d526-f867-587e-933e-89353d26d022 as base\n'
|
|
80
|
+
);
|
|
81
|
+
expect(preparedResult.dependenciesToMaterialize).toStrictEqual({
|
|
82
|
+
'secondLevelMaterializedQuery-bd80d526-f867-587e-933e-89353d26d022': {
|
|
83
|
+
id: 'bd80d526-f867-587e-933e-89353d26d022',
|
|
84
|
+
path: 'internal://internal.malloy',
|
|
85
|
+
queryName: 'secondLevelMaterializedQuery',
|
|
86
|
+
source: undefined,
|
|
87
|
+
},
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it('replaceMaterializedReferences = false compiles the whole sql', async () => {
|
|
92
|
+
const query = `
|
|
93
|
+
# materialize
|
|
94
|
+
query: myMaterializedQuery is duckdb.sql("select 1 as one, 'word' as word") -> {
|
|
95
|
+
select:
|
|
96
|
+
two is one + 1
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
source: foo is myMaterializedQuery extend {
|
|
100
|
+
view: fooview is {
|
|
101
|
+
select:
|
|
102
|
+
three is two + 1
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
run: foo -> fooview;`;
|
|
107
|
+
|
|
108
|
+
const qm = runtime.loadQuery(query, {replaceMaterializedReferences: false});
|
|
109
|
+
const preparedResult = await qm.getPreparedResult();
|
|
110
|
+
|
|
111
|
+
expect(preparedResult.sql).toBe(
|
|
112
|
+
'WITH __stage0 AS (\n SELECT \n base."one"+1 as "two"\n FROM (select 1 as one, \'word\' as word) as base\n)\nSELECT \n base."two"+1 as "three"\nFROM __stage0 as base\n'
|
|
113
|
+
);
|
|
114
|
+
expect(preparedResult.dependenciesToMaterialize).toStrictEqual({});
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
afterAll(async () => {
|
|
119
|
+
await allDucks.closeAll();
|
|
120
|
+
});
|