@malloydata/malloy-tests 0.0.194-dev241001154534 → 0.0.194-dev241001231135
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.194-
|
|
25
|
-
"@malloydata/db-duckdb": "^0.0.194-
|
|
26
|
-
"@malloydata/db-postgres": "^0.0.194-
|
|
27
|
-
"@malloydata/db-snowflake": "^0.0.194-
|
|
28
|
-
"@malloydata/db-trino": "^0.0.194-
|
|
29
|
-
"@malloydata/malloy": "^0.0.194-
|
|
30
|
-
"@malloydata/render": "^0.0.194-
|
|
24
|
+
"@malloydata/db-bigquery": "^0.0.194-dev241001231135",
|
|
25
|
+
"@malloydata/db-duckdb": "^0.0.194-dev241001231135",
|
|
26
|
+
"@malloydata/db-postgres": "^0.0.194-dev241001231135",
|
|
27
|
+
"@malloydata/db-snowflake": "^0.0.194-dev241001231135",
|
|
28
|
+
"@malloydata/db-trino": "^0.0.194-dev241001231135",
|
|
29
|
+
"@malloydata/malloy": "^0.0.194-dev241001231135",
|
|
30
|
+
"@malloydata/render": "^0.0.194-dev241001231135",
|
|
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.194-
|
|
39
|
+
"version": "0.0.194-dev241001231135"
|
|
40
40
|
}
|
|
@@ -32,19 +32,23 @@ describe.each(allDucks.runtimeList)('duckdb:%s', (dbName, runtime) => {
|
|
|
32
32
|
run: foo -> fooview;
|
|
33
33
|
`;
|
|
34
34
|
|
|
35
|
-
const qm = runtime.loadQuery(query, {
|
|
35
|
+
const qm = runtime.loadQuery(query, {
|
|
36
|
+
replaceMaterializedReferences: true,
|
|
37
|
+
materializedTablePrefix: 'myPipelinePrefix',
|
|
38
|
+
});
|
|
36
39
|
const preparedResult = await qm.getPreparedResult();
|
|
37
40
|
|
|
38
41
|
expect(preparedResult.sql).toBe(
|
|
39
|
-
'SELECT \n base."two"+1 as "three"\nFROM
|
|
42
|
+
'SELECT \n base."two"+1 as "three"\nFROM myPipelinePrefix_myMaterializedQuery_6037d4be_8b92_5ea7_95a0_27bd26c240ca as base\n'
|
|
40
43
|
);
|
|
41
44
|
expect(preparedResult.dependenciesToMaterialize).toStrictEqual({
|
|
42
|
-
'
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
45
|
+
'myPipelinePrefix_myMaterializedQuery_6037d4be_8b92_5ea7_95a0_27bd26c240ca':
|
|
46
|
+
{
|
|
47
|
+
'id': 'myPipelinePrefix_myMaterializedQuery_6037d4be_8b92_5ea7_95a0_27bd26c240ca',
|
|
48
|
+
'path': 'internal://internal.malloy',
|
|
49
|
+
'queryName': 'myMaterializedQuery',
|
|
50
|
+
'source': undefined,
|
|
51
|
+
},
|
|
48
52
|
});
|
|
49
53
|
});
|
|
50
54
|
|
|
@@ -76,11 +80,11 @@ describe.each(allDucks.runtimeList)('duckdb:%s', (dbName, runtime) => {
|
|
|
76
80
|
const preparedResult = await qm.getPreparedResult();
|
|
77
81
|
|
|
78
82
|
expect(preparedResult.sql).toBe(
|
|
79
|
-
'SELECT \n base."three"+1 as "four"\nFROM
|
|
83
|
+
'SELECT \n base."three"+1 as "four"\nFROM secondLevelMaterializedQuery_bd80d526_f867_587e_933e_89353d26d022 as base\n'
|
|
80
84
|
);
|
|
81
85
|
expect(preparedResult.dependenciesToMaterialize).toStrictEqual({
|
|
82
|
-
'
|
|
83
|
-
id: '
|
|
86
|
+
'secondLevelMaterializedQuery_bd80d526_f867_587e_933e_89353d26d022': {
|
|
87
|
+
id: 'secondLevelMaterializedQuery_bd80d526_f867_587e_933e_89353d26d022',
|
|
84
88
|
path: 'internal://internal.malloy',
|
|
85
89
|
queryName: 'secondLevelMaterializedQuery',
|
|
86
90
|
source: undefined,
|
|
@@ -0,0 +1,149 @@
|
|
|
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
|
+
import {Explore, Field} from '@malloydata/malloy';
|
|
12
|
+
|
|
13
|
+
const [describe, databases] = describeIfDatabaseAvailable(['duckdb']);
|
|
14
|
+
const dbs = new RuntimeList(databases);
|
|
15
|
+
|
|
16
|
+
function referenceId(field: Field | Explore) {
|
|
17
|
+
if (field.isExplore() || field.isQueryField()) {
|
|
18
|
+
return undefined;
|
|
19
|
+
}
|
|
20
|
+
return field.referenceId;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
describe.each(dbs.runtimeList)('%s', (dbName, runtime) => {
|
|
24
|
+
describe('reference id', () => {
|
|
25
|
+
it('is correct for field references in table', async () => {
|
|
26
|
+
const query = `
|
|
27
|
+
run: duckdb.sql("SELECT 1 as one") -> {
|
|
28
|
+
group_by: one
|
|
29
|
+
nest: a is {
|
|
30
|
+
group_by: one
|
|
31
|
+
}
|
|
32
|
+
nest: b is {
|
|
33
|
+
group_by: one is "fake"
|
|
34
|
+
}
|
|
35
|
+
nest: c is {
|
|
36
|
+
# this reference has an annotation
|
|
37
|
+
group_by: one
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
`;
|
|
41
|
+
|
|
42
|
+
const result = await runtime.loadQuery(query).run();
|
|
43
|
+
const actual = referenceId(result.data.path(0, 'one').field);
|
|
44
|
+
expect(actual).not.toBeUndefined();
|
|
45
|
+
expect(referenceId(result.data.path(0, 'a', 0, 'one').field)).toBe(
|
|
46
|
+
actual
|
|
47
|
+
);
|
|
48
|
+
const bOne = referenceId(result.data.path(0, 'b', 0, 'one').field);
|
|
49
|
+
expect(bOne).not.toBe(undefined);
|
|
50
|
+
expect(bOne).not.toBe(actual);
|
|
51
|
+
expect(referenceId(result.data.path(0, 'c', 0, 'one').field)).toBe(
|
|
52
|
+
actual
|
|
53
|
+
);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('is correct for measures', async () => {
|
|
57
|
+
const query = `
|
|
58
|
+
run: duckdb.sql("SELECT 1 as one") extend {
|
|
59
|
+
measure: c is count()
|
|
60
|
+
} -> {
|
|
61
|
+
aggregate: c
|
|
62
|
+
nest: a is {
|
|
63
|
+
aggregate: c
|
|
64
|
+
}
|
|
65
|
+
nest: b is {
|
|
66
|
+
aggregate: c is count() * 2
|
|
67
|
+
}
|
|
68
|
+
nest: d is {
|
|
69
|
+
# this reference has an annotation
|
|
70
|
+
aggregate: c
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
`;
|
|
74
|
+
|
|
75
|
+
const result = await runtime.loadQuery(query).run();
|
|
76
|
+
const actual = referenceId(result.data.path(0, 'c').field);
|
|
77
|
+
expect(actual).not.toBeUndefined();
|
|
78
|
+
expect(referenceId(result.data.path(0, 'a', 'c').field)).toBe(actual);
|
|
79
|
+
const bC = referenceId(result.data.path(0, 'b', 'c').field);
|
|
80
|
+
expect(bC).not.toBe(undefined);
|
|
81
|
+
expect(bC).not.toBe(actual);
|
|
82
|
+
expect(referenceId(result.data.path(0, 'd', 'c').field)).toBe(actual);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it('is correct for field references from extend block', async () => {
|
|
86
|
+
const query = `
|
|
87
|
+
run: duckdb.sql("SELECT 1 as one") -> {
|
|
88
|
+
extend: {
|
|
89
|
+
dimension: two is 2
|
|
90
|
+
}
|
|
91
|
+
group_by: two
|
|
92
|
+
nest: a is {
|
|
93
|
+
group_by: two
|
|
94
|
+
}
|
|
95
|
+
nest: b is {
|
|
96
|
+
group_by: two is "fake"
|
|
97
|
+
}
|
|
98
|
+
nest: c is {
|
|
99
|
+
# this reference has an annotation
|
|
100
|
+
group_by: two
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
`;
|
|
104
|
+
|
|
105
|
+
const result = await runtime.loadQuery(query).run();
|
|
106
|
+
const actual = referenceId(result.data.path(0, 'two').field);
|
|
107
|
+
expect(actual).not.toBeUndefined();
|
|
108
|
+
expect(referenceId(result.data.path(0, 'a', 0, 'two').field)).toBe(
|
|
109
|
+
actual
|
|
110
|
+
);
|
|
111
|
+
const bTwo = referenceId(result.data.path(0, 'b', 0, 'two').field);
|
|
112
|
+
expect(bTwo).not.toBe(undefined);
|
|
113
|
+
expect(bTwo).not.toBe(actual);
|
|
114
|
+
expect(referenceId(result.data.path(0, 'c', 0, 'two').field)).toBe(
|
|
115
|
+
actual
|
|
116
|
+
);
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it.skip('is unequal for different nest/extend blocks', async () => {
|
|
120
|
+
const query = `
|
|
121
|
+
run: duckdb.sql("SELECT 1 as one") -> {
|
|
122
|
+
nest: a is {
|
|
123
|
+
extend: {
|
|
124
|
+
dimension: three is 3
|
|
125
|
+
}
|
|
126
|
+
group_by: three
|
|
127
|
+
}
|
|
128
|
+
nest: b is {
|
|
129
|
+
extend: {
|
|
130
|
+
dimension: three is 4
|
|
131
|
+
}
|
|
132
|
+
group_by: three
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
`;
|
|
136
|
+
|
|
137
|
+
const result = await runtime.loadQuery(query).run();
|
|
138
|
+
const actual = referenceId(result.data.path(0, 'a', 0, 'three').field);
|
|
139
|
+
expect(actual).not.toBeUndefined();
|
|
140
|
+
expect(referenceId(result.data.path(0, 'b', 0, 'three').field)).toBe(
|
|
141
|
+
actual
|
|
142
|
+
);
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
afterAll(async () => {
|
|
148
|
+
await dbs.closeAll();
|
|
149
|
+
});
|