@malloydata/malloy-tests 0.0.232-dev250127220611 → 0.0.232
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.232
|
|
25
|
-
"@malloydata/db-duckdb": "^0.0.232
|
|
26
|
-
"@malloydata/db-postgres": "^0.0.232
|
|
27
|
-
"@malloydata/db-snowflake": "^0.0.232
|
|
28
|
-
"@malloydata/db-trino": "^0.0.232
|
|
29
|
-
"@malloydata/malloy": "^0.0.232
|
|
30
|
-
"@malloydata/render": "^0.0.232
|
|
24
|
+
"@malloydata/db-bigquery": "^0.0.232",
|
|
25
|
+
"@malloydata/db-duckdb": "^0.0.232",
|
|
26
|
+
"@malloydata/db-postgres": "^0.0.232",
|
|
27
|
+
"@malloydata/db-snowflake": "^0.0.232",
|
|
28
|
+
"@malloydata/db-trino": "^0.0.232",
|
|
29
|
+
"@malloydata/malloy": "^0.0.232",
|
|
30
|
+
"@malloydata/render": "^0.0.232",
|
|
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.232
|
|
40
|
+
"version": "0.0.232"
|
|
41
41
|
}
|
|
@@ -56,7 +56,10 @@ describe('Multi-connection', () => {
|
|
|
56
56
|
'duckdb'
|
|
57
57
|
);
|
|
58
58
|
|
|
59
|
-
const runtime = new malloy.Runtime(
|
|
59
|
+
const runtime = new malloy.Runtime({
|
|
60
|
+
urlReader: files,
|
|
61
|
+
connections: connectionMap,
|
|
62
|
+
});
|
|
60
63
|
|
|
61
64
|
afterAll(async () => {
|
|
62
65
|
await postgresConnection.close();
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2023 Google LLC
|
|
3
|
+
*
|
|
4
|
+
* Permission is hereby granted, free of charge, to any person obtaining
|
|
5
|
+
* a copy of this software and associated documentation files
|
|
6
|
+
* (the "Software"), to deal in the Software without restriction,
|
|
7
|
+
* including without limitation the rights to use, copy, modify, merge,
|
|
8
|
+
* publish, distribute, sublicense, and/or sell copies of the Software,
|
|
9
|
+
* and to permit persons to whom the Software is furnished to do so,
|
|
10
|
+
* subject to the following conditions:
|
|
11
|
+
*
|
|
12
|
+
* The above copyright notice and this permission notice shall be
|
|
13
|
+
* included in all copies or substantial portions of the Software.
|
|
14
|
+
*
|
|
15
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
16
|
+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
17
|
+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
18
|
+
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
19
|
+
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
20
|
+
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
21
|
+
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
import {describeIfDatabaseAvailable} from '../../util';
|
|
25
|
+
import {RuntimeList, TestCacheManager, TestURLReader} from '../../runtimes';
|
|
26
|
+
|
|
27
|
+
const [_describe, databases] = describeIfDatabaseAvailable(['duckdb']);
|
|
28
|
+
const runtimes = new RuntimeList(databases);
|
|
29
|
+
|
|
30
|
+
describe.each(runtimes.runtimeList)('%s', (databaseName, runtime) => {
|
|
31
|
+
test('model caching works', async () => {
|
|
32
|
+
const cacheManager = runtime.cacheManager;
|
|
33
|
+
const urlReader = runtime.urlReader;
|
|
34
|
+
expect(urlReader instanceof TestURLReader).toBe(true);
|
|
35
|
+
if (!(urlReader instanceof TestURLReader)) return;
|
|
36
|
+
expect(cacheManager instanceof TestCacheManager).toBe(true);
|
|
37
|
+
if (!(cacheManager instanceof TestCacheManager)) return;
|
|
38
|
+
const modelCache = cacheManager._modelCache;
|
|
39
|
+
if (modelCache === undefined) return;
|
|
40
|
+
const aURL = new URL('file://a.malloy');
|
|
41
|
+
const bURL = new URL('file://b.malloy');
|
|
42
|
+
urlReader.setFile(
|
|
43
|
+
aURL,
|
|
44
|
+
`
|
|
45
|
+
import 'file://b.malloy'
|
|
46
|
+
|
|
47
|
+
source: a is duckdb.sql("SELECT 1 as one")
|
|
48
|
+
`
|
|
49
|
+
);
|
|
50
|
+
urlReader.setFile(
|
|
51
|
+
bURL,
|
|
52
|
+
`
|
|
53
|
+
source: b is duckdb.sql("SELECT 1 as one")
|
|
54
|
+
`
|
|
55
|
+
);
|
|
56
|
+
const model1 = await runtime.getModel(aURL);
|
|
57
|
+
expect(model1.problems).toMatchObject([]);
|
|
58
|
+
const aCached = await modelCache.getModel(aURL);
|
|
59
|
+
expect(aCached).toBeDefined();
|
|
60
|
+
if (aCached === undefined) return;
|
|
61
|
+
expect(aCached.modelDef.contents['a']).toBeDefined();
|
|
62
|
+
expect(aCached.modelDef.dependencies).toMatchObject({
|
|
63
|
+
'file://b.malloy/': {},
|
|
64
|
+
});
|
|
65
|
+
expect(aCached.modelDef.contents['a']).toBeDefined();
|
|
66
|
+
urlReader.setFile(
|
|
67
|
+
bURL,
|
|
68
|
+
`
|
|
69
|
+
source: c is duckdb.sql("SELECT 1 as one")
|
|
70
|
+
`
|
|
71
|
+
);
|
|
72
|
+
const model2 = await runtime.getModel(aURL);
|
|
73
|
+
expect(model2._modelDef.contents['c']).toBeDefined();
|
|
74
|
+
expect(model2._modelDef.contents['a']).toBeDefined();
|
|
75
|
+
expect(model2._modelDef.contents['a2']).not.toBeDefined();
|
|
76
|
+
// We want to check that it's going to use the cached version of b...
|
|
77
|
+
// so we'll sneakily modify the cache in an evil way:
|
|
78
|
+
const existingModel = await modelCache.getModel(bURL);
|
|
79
|
+
expect(existingModel).toBeDefined();
|
|
80
|
+
if (existingModel === undefined) return;
|
|
81
|
+
await modelCache.setModel(bURL, {
|
|
82
|
+
modelDef: {
|
|
83
|
+
...existingModel.modelDef,
|
|
84
|
+
contents: {
|
|
85
|
+
...existingModel.modelDef.contents,
|
|
86
|
+
'sneaky': existingModel.modelDef.contents['c'],
|
|
87
|
+
},
|
|
88
|
+
exports: ['sneaky'],
|
|
89
|
+
},
|
|
90
|
+
invalidationKeys: existingModel.invalidationKeys,
|
|
91
|
+
});
|
|
92
|
+
urlReader.setFile(
|
|
93
|
+
aURL,
|
|
94
|
+
`
|
|
95
|
+
import 'file://b.malloy'
|
|
96
|
+
|
|
97
|
+
source: sneaky_copy is sneaky extend {}
|
|
98
|
+
`
|
|
99
|
+
);
|
|
100
|
+
const model3 = await runtime.getModel(aURL);
|
|
101
|
+
expect(model3._modelDef.contents['sneaky_copy']).toBeDefined();
|
|
102
|
+
expect(model3._modelDef.contents['a']).not.toBeDefined();
|
|
103
|
+
});
|
|
104
|
+
});
|
package/src/runtimes.ts
CHANGED
|
@@ -23,12 +23,15 @@
|
|
|
23
23
|
|
|
24
24
|
import {
|
|
25
25
|
Connection,
|
|
26
|
-
EmptyURLReader,
|
|
27
26
|
MalloyQueryData,
|
|
28
27
|
QueryDataRow,
|
|
29
28
|
Result,
|
|
30
29
|
RunSQLOptions,
|
|
31
30
|
SingleConnectionRuntime,
|
|
31
|
+
InMemoryURLReader,
|
|
32
|
+
InMemoryModelCache,
|
|
33
|
+
CacheManager,
|
|
34
|
+
ModelCache,
|
|
32
35
|
} from '@malloydata/malloy';
|
|
33
36
|
import {BigQueryConnection} from '@malloydata/db-bigquery';
|
|
34
37
|
import {DuckDBConnection} from '@malloydata/db-duckdb';
|
|
@@ -144,7 +147,27 @@ export class DuckDBWASMTestConnection extends DuckDBWASMConnection {
|
|
|
144
147
|
}
|
|
145
148
|
}
|
|
146
149
|
|
|
147
|
-
|
|
150
|
+
export class TestCacheManager extends CacheManager {
|
|
151
|
+
constructor(readonly _modelCache: ModelCache) {
|
|
152
|
+
super(_modelCache);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export class TestURLReader extends InMemoryURLReader {
|
|
157
|
+
constructor() {
|
|
158
|
+
super(new Map());
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
setFile(url: URL, contents: string) {
|
|
162
|
+
this.files.set(url.toString(), contents);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
deleteFile(url: URL) {
|
|
166
|
+
this.files.delete(url.toString());
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
const files = new TestURLReader();
|
|
148
171
|
|
|
149
172
|
export function rows(qr: Result): QueryDataRow[] {
|
|
150
173
|
return qr.data.value;
|
|
@@ -222,7 +245,12 @@ export function runtimeFor(dbName: string): SingleConnectionRuntime {
|
|
|
222
245
|
}
|
|
223
246
|
|
|
224
247
|
export function testRuntimeFor(connection: Connection) {
|
|
225
|
-
return new SingleConnectionRuntime(
|
|
248
|
+
return new SingleConnectionRuntime({
|
|
249
|
+
urlReader: files,
|
|
250
|
+
connection,
|
|
251
|
+
eventStream: new EventEmitter(),
|
|
252
|
+
cacheManager: new TestCacheManager(new InMemoryModelCache()),
|
|
253
|
+
});
|
|
226
254
|
}
|
|
227
255
|
|
|
228
256
|
/**
|