@malloydata/db-duckdb 0.0.41-dev230615174435 → 0.0.41-dev230615181401
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.
|
@@ -54,7 +54,8 @@ const web_worker_1 = __importDefault(require("web-worker"));
|
|
|
54
54
|
const malloy_1 = require("@malloydata/malloy");
|
|
55
55
|
const apache_arrow_1 = require("apache-arrow");
|
|
56
56
|
const duckdb_common_1 = require("./duckdb_common");
|
|
57
|
-
const TABLE_MATCH = /FROM\s*'(
|
|
57
|
+
const TABLE_MATCH = /FROM\s*('([^']*)'|"([^"]*)")/gi;
|
|
58
|
+
const TABLE_FUNCTION_MATCH = /FROM\s+[a-z0-9_]+\(('([^']*)'|"([^"]*)")/gi;
|
|
58
59
|
/**
|
|
59
60
|
* Arrow's toJSON() doesn't really do what I'd expect, since
|
|
60
61
|
* it still includes Arrow objects like DecimalBigNums and Vectors,
|
|
@@ -258,7 +259,10 @@ class DuckDBWASMConnection extends duckdb_common_1.DuckDBCommon {
|
|
|
258
259
|
async fetchSchemaForSQLBlock(sqlRef) {
|
|
259
260
|
const tables = [];
|
|
260
261
|
for (const match of sqlRef.selectStr.matchAll(TABLE_MATCH)) {
|
|
261
|
-
tables.push(match[
|
|
262
|
+
tables.push(match[2] || match[3]);
|
|
263
|
+
}
|
|
264
|
+
for (const match of sqlRef.selectStr.matchAll(TABLE_FUNCTION_MATCH)) {
|
|
265
|
+
tables.push(match[2] || match[3]);
|
|
262
266
|
}
|
|
263
267
|
await this.findTables(tables);
|
|
264
268
|
return super.fetchSchemaForSQLBlock(sqlRef);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright 2023 Google LLC
|
|
4
|
+
*
|
|
5
|
+
* Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
* a copy of this software and associated documentation files
|
|
7
|
+
* (the "Software"), to deal in the Software without restriction,
|
|
8
|
+
* including without limitation the rights to use, copy, modify, merge,
|
|
9
|
+
* publish, distribute, sublicense, and/or sell copies of the Software,
|
|
10
|
+
* and to permit persons to whom the Software is furnished to do so,
|
|
11
|
+
* subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be
|
|
14
|
+
* included in all copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
19
|
+
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
20
|
+
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
21
|
+
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
22
|
+
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
+
const duckdb_common_1 = require("./duckdb_common");
|
|
26
|
+
const duckdb_wasm_connection_node_1 = require("./duckdb_wasm_connection_node");
|
|
27
|
+
describe('DuckDBWasmConnection', () => {
|
|
28
|
+
let connection;
|
|
29
|
+
let findTables;
|
|
30
|
+
beforeAll(async () => {
|
|
31
|
+
connection = new duckdb_wasm_connection_node_1.DuckDBWASMConnection('duckdb');
|
|
32
|
+
await connection.runSQL('SELECT 1');
|
|
33
|
+
});
|
|
34
|
+
afterAll(async () => {
|
|
35
|
+
await connection.close();
|
|
36
|
+
await new Promise(resolve => setTimeout(resolve, 10000));
|
|
37
|
+
});
|
|
38
|
+
beforeEach(() => {
|
|
39
|
+
jest
|
|
40
|
+
.spyOn(duckdb_common_1.DuckDBCommon.prototype, 'fetchSchemaForSQLBlock')
|
|
41
|
+
.mockResolvedValue({
|
|
42
|
+
error: 'mocked',
|
|
43
|
+
});
|
|
44
|
+
findTables = jest.spyOn(connection, 'findTables');
|
|
45
|
+
});
|
|
46
|
+
afterEach(() => {
|
|
47
|
+
jest.resetAllMocks();
|
|
48
|
+
});
|
|
49
|
+
it('finds simple tables in SQL', async () => {
|
|
50
|
+
await connection.fetchSchemaForSQLBlock({
|
|
51
|
+
selectStr: `
|
|
52
|
+
SELECT
|
|
53
|
+
created_at,
|
|
54
|
+
sale_price,
|
|
55
|
+
inventory_item_id
|
|
56
|
+
FROM 'order_items.parquet'
|
|
57
|
+
SELECT
|
|
58
|
+
id,
|
|
59
|
+
product_department,
|
|
60
|
+
product_category,
|
|
61
|
+
created_at AS inventory_items_created_at
|
|
62
|
+
FROM "inventory_items.parquet"
|
|
63
|
+
`,
|
|
64
|
+
});
|
|
65
|
+
expect(findTables).toHaveBeenCalledWith([
|
|
66
|
+
'order_items.parquet',
|
|
67
|
+
'inventory_items.parquet',
|
|
68
|
+
]);
|
|
69
|
+
});
|
|
70
|
+
it('finds table functions in SQL', async () => {
|
|
71
|
+
await connection.fetchSchemaForSQLBlock({
|
|
72
|
+
selectStr: `
|
|
73
|
+
SELECT
|
|
74
|
+
created_at,
|
|
75
|
+
sale_price,
|
|
76
|
+
inventory_item_id
|
|
77
|
+
FROM read_parquet('order_items2.parquet', arg='value')
|
|
78
|
+
SELECT
|
|
79
|
+
id,
|
|
80
|
+
product_department,
|
|
81
|
+
product_category,
|
|
82
|
+
created_at AS inventory_items_created_at
|
|
83
|
+
FROM read_parquet("inventory_items2.parquet")
|
|
84
|
+
`,
|
|
85
|
+
});
|
|
86
|
+
expect(findTables).toHaveBeenCalledWith([
|
|
87
|
+
'order_items2.parquet',
|
|
88
|
+
'inventory_items2.parquet',
|
|
89
|
+
]);
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
//# sourceMappingURL=duckdb_wasm_connection.spec.js.map
|