@malloydata/db-duckdb 0.0.240-dev250311213218 → 0.0.240-dev250311214430

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@malloydata/db-duckdb",
3
- "version": "0.0.240-dev250311213218",
3
+ "version": "0.0.240-dev250311214430",
4
4
  "license": "MIT",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -41,7 +41,7 @@
41
41
  },
42
42
  "dependencies": {
43
43
  "@duckdb/duckdb-wasm": "1.29.0",
44
- "@malloydata/malloy": "^0.0.240-dev250311213218",
44
+ "@malloydata/malloy": "^0.0.240-dev250311214430",
45
45
  "@motherduck/wasm-client": "^0.6.6",
46
46
  "apache-arrow": "^17.0.0",
47
47
  "duckdb": "1.1.1",
@@ -1 +0,0 @@
1
- export {};
@@ -1,242 +0,0 @@
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_connection_1 = require("./duckdb_connection");
27
- const malloy_1 = require("@malloydata/malloy");
28
- const test_1 = require("@malloydata/malloy/test");
29
- const [describe] = (0, test_1.describeIfDatabaseAvailable)(['duckdb']);
30
- /*
31
- * !IMPORTANT
32
- *
33
- * The connection is reused for each test, so if you do not name your tables
34
- * and keys uniquely for each test you will see cross test interactions.
35
- */
36
- describe('DuckDBConnection', () => {
37
- let connection;
38
- beforeAll(async () => {
39
- connection = new duckdb_connection_1.DuckDBConnection('duckdb');
40
- await connection.runSQL('SELECT 1');
41
- expect(Object.keys(duckdb_connection_1.DuckDBConnection.activeDBs).length).toEqual(1);
42
- });
43
- afterAll(async () => {
44
- await connection.close();
45
- expect(Object.keys(duckdb_connection_1.DuckDBConnection.activeDBs).length).toEqual(0);
46
- });
47
- describe('schema', () => {
48
- let runRawSQL;
49
- beforeEach(async () => {
50
- runRawSQL = jest
51
- .spyOn(duckdb_common_1.DuckDBCommon.prototype, 'runRawSQL')
52
- .mockResolvedValue({ rows: [], totalRows: 0 });
53
- });
54
- afterEach(() => {
55
- jest.resetAllMocks();
56
- runRawSQL.mockRestore();
57
- });
58
- it('caches table schema', async () => {
59
- await connection.fetchSchemaForTables({ 'test1': 'table1' }, {});
60
- expect(runRawSQL).toHaveBeenCalledTimes(1);
61
- await new Promise(resolve => setTimeout(resolve));
62
- await connection.fetchSchemaForTables({ 'test1': 'table1' }, {});
63
- expect(runRawSQL).toHaveBeenCalledTimes(1);
64
- });
65
- it('refreshes table schema', async () => {
66
- await connection.fetchSchemaForTables({ 'test2': 'table2' }, {});
67
- expect(runRawSQL).toHaveBeenCalledTimes(1);
68
- await new Promise(resolve => setTimeout(resolve));
69
- await connection.fetchSchemaForTables({ 'test2': 'table2' }, { refreshTimestamp: Date.now() + 10 });
70
- expect(runRawSQL).toHaveBeenCalledTimes(2);
71
- });
72
- it('caches sql schema', async () => {
73
- await connection.fetchSchemaForSQLStruct(SQL_BLOCK_1, {});
74
- expect(runRawSQL).toHaveBeenCalledTimes(1);
75
- await new Promise(resolve => setTimeout(resolve));
76
- await connection.fetchSchemaForSQLStruct(SQL_BLOCK_1, {});
77
- expect(runRawSQL).toHaveBeenCalledTimes(1);
78
- });
79
- it('refreshes sql schema', async () => {
80
- await connection.fetchSchemaForSQLStruct(SQL_BLOCK_2, {});
81
- expect(runRawSQL).toHaveBeenCalledTimes(1);
82
- await new Promise(resolve => setTimeout(resolve));
83
- await connection.fetchSchemaForSQLStruct(SQL_BLOCK_2, {
84
- refreshTimestamp: Date.now() + 10,
85
- });
86
- expect(runRawSQL).toHaveBeenCalledTimes(2);
87
- });
88
- });
89
- describe('multiple connections', () => {
90
- it('can open multiple connections with different settings', async () => {
91
- const connection1 = new duckdb_connection_1.DuckDBConnection('duckdb1');
92
- const connection2 = new duckdb_connection_1.DuckDBConnection('duckdb2');
93
- await connection1.runRawSQL("SET FILE_SEARCH_PATH='/home/user1'");
94
- await connection2.runRawSQL("SET FILE_SEARCH_PATH='/home/user2'");
95
- const val1 = await connection1.runSQL("SELECT current_setting('FILE_SEARCH_PATH') AS val");
96
- const val2 = await connection2.runSQL("SELECT current_setting('FILE_SEARCH_PATH') AS val");
97
- expect(Object.keys(duckdb_connection_1.DuckDBConnection.activeDBs).length).toEqual(1);
98
- expect(duckdb_connection_1.DuckDBConnection.activeDBs[':memory:'].connections.length).toEqual(3);
99
- expect(val1).toEqual({ rows: [{ val: '/home/user1' }], totalRows: 1 });
100
- expect(val2).toEqual({ rows: [{ val: '/home/user2' }], totalRows: 1 });
101
- await connection1.close();
102
- await connection2.close();
103
- });
104
- });
105
- describe('schema parser', () => {
106
- it('parses arrays', () => {
107
- const structDef = makeStructDef();
108
- connection.fillStructDefFromTypeMap(structDef, { test: ARRAY_SCHEMA });
109
- expect(structDef.fields[0]).toEqual((0, malloy_1.mkArrayDef)({ type: 'number', numberType: 'integer' }, 'test'));
110
- });
111
- it('parses inline', () => {
112
- const structDef = makeStructDef();
113
- connection.fillStructDefFromTypeMap(structDef, { test: INLINE_SCHEMA });
114
- expect(structDef.fields[0]).toEqual({
115
- 'name': 'test',
116
- 'type': 'record',
117
- 'join': 'one',
118
- 'fields': [
119
- { 'name': 'a', ...dblType },
120
- { 'name': 'b', ...intTyp },
121
- { 'name': 'c', ...strTyp },
122
- ],
123
- });
124
- });
125
- it('parses nested', () => {
126
- const structDef = makeStructDef();
127
- connection.fillStructDefFromTypeMap(structDef, { test: NESTED_SCHEMA });
128
- expect(structDef.fields[0]).toEqual({
129
- 'name': 'test',
130
- 'type': 'array',
131
- 'elementTypeDef': { type: 'record_element' },
132
- 'join': 'many',
133
- 'fields': [
134
- { 'name': 'a', 'numberType': 'float', 'type': 'number' },
135
- { 'name': 'b', 'numberType': 'integer', 'type': 'number' },
136
- { 'name': 'c', 'type': 'string' },
137
- ],
138
- });
139
- });
140
- it('parses struct with sql native field', () => {
141
- const structDef = makeStructDef();
142
- connection.fillStructDefFromTypeMap(structDef, { test: PROFESSOR_SCHEMA });
143
- expect(structDef.fields[0]).toEqual({
144
- 'name': 'test',
145
- 'type': 'array',
146
- 'elementTypeDef': { type: 'record_element' },
147
- 'join': 'many',
148
- 'fields': [
149
- { 'name': 'professor_id', 'type': 'sql native', 'rawType': 'UUID' },
150
- { 'name': 'name', 'type': 'string' },
151
- { 'name': 'age', 'numberType': 'integer', 'type': 'number' },
152
- { 'name': 'total_sections', 'numberType': 'integer', 'type': 'number' },
153
- ],
154
- });
155
- });
156
- it('parses a simple type', () => {
157
- const structDef = makeStructDef();
158
- connection.fillStructDefFromTypeMap(structDef, { test: 'varchar(60)' });
159
- expect(structDef.fields[0]).toEqual({
160
- 'name': 'test',
161
- 'type': 'string',
162
- });
163
- });
164
- it('parses unknown type', () => {
165
- const structDef = makeStructDef();
166
- connection.fillStructDefFromTypeMap(structDef, { test: 'UUID' });
167
- expect(structDef.fields[0]).toEqual({
168
- 'name': 'test',
169
- 'type': 'sql native',
170
- 'rawType': 'UUID',
171
- });
172
- });
173
- });
174
- });
175
- /**
176
- * Create a basic StructDef for the purpose of passing to
177
- * DuckDBConnection.fillStructDefFromTypeMap()
178
- *
179
- * @returns valid StructDef for testing
180
- */
181
- const makeStructDef = () => {
182
- return {
183
- type: 'table',
184
- name: 'test',
185
- dialect: 'duckdb',
186
- tablePath: 'test',
187
- connection: 'duckdb',
188
- fields: [],
189
- };
190
- };
191
- //
192
- // SQL blocks for testing table name detection in
193
- // DuckDBConnection.fetchSchemaForSQLBlock()
194
- //
195
- // Uses string value for table
196
- const SQL_BLOCK_1 = {
197
- connection: 'duckdb',
198
- selectStr: `
199
- SELECT
200
- created_at,
201
- sale_price,
202
- inventory_item_id
203
- FROM 'order_items.parquet'
204
- SELECT
205
- id,
206
- product_department,
207
- product_category,
208
- created_at AS inventory_items_created_at
209
- FROM "inventory_items.parquet"
210
- `,
211
- };
212
- // Uses read_parquet() for table
213
- const SQL_BLOCK_2 = {
214
- connection: 'duckdb',
215
- selectStr: `
216
- SELECT
217
- created_at,
218
- sale_price,
219
- inventory_item_id
220
- FROM read_parquet('order_items2.parquet', arg='value')
221
- SELECT
222
- id,
223
- product_department,
224
- product_category,
225
- created_at AS inventory_items_created_at
226
- FROM read_parquet("inventory_items2.parquet")
227
- `,
228
- };
229
- //
230
- // Type strings for testing DuckDBConnection.fillStructDefFromTypeMap()
231
- //
232
- // 'integer[]' is array
233
- const ARRAY_SCHEMA = 'integer[]';
234
- // STRUCT(...) is inline
235
- const INLINE_SCHEMA = 'STRUCT(a double, b integer, c varchar(60))';
236
- // STRUCT(....)[] is nested
237
- const NESTED_SCHEMA = 'STRUCT(a double, b integer, c varchar(60))[]';
238
- const intTyp = { type: 'number', numberType: 'integer' };
239
- const strTyp = { type: 'string' };
240
- const dblType = { type: 'number', numberType: 'float' };
241
- const PROFESSOR_SCHEMA = 'STRUCT(professor_id UUID, "name" VARCHAR, age BIGINT, total_sections BIGINT)[]';
242
- //# sourceMappingURL=duckdb.spec.js.map
@@ -1 +0,0 @@
1
- export {};
@@ -1,94 +0,0 @@
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 test_1 = require("@malloydata/malloy/test");
26
- const duckdb_common_1 = require("./duckdb_common");
27
- const duckdb_wasm_connection_node_1 = require("./duckdb_wasm_connection_node");
28
- const [describe] = (0, test_1.describeIfDatabaseAvailable)(['duckdb_wasm']);
29
- describe('DuckDBWasmConnection', () => {
30
- let connection;
31
- let findTables;
32
- beforeAll(async () => {
33
- connection = new duckdb_wasm_connection_node_1.DuckDBWASMConnection('duckdb');
34
- await connection.runSQL('SELECT 1');
35
- });
36
- afterAll(async () => {
37
- await connection.close();
38
- await new Promise(resolve => setTimeout(resolve, 10000));
39
- });
40
- beforeEach(() => {
41
- jest
42
- .spyOn(duckdb_common_1.DuckDBCommon.prototype, 'fetchSelectSchema')
43
- .mockResolvedValue('mocked');
44
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
45
- findTables = jest.spyOn(connection, 'findTables');
46
- });
47
- afterEach(() => {
48
- jest.resetAllMocks();
49
- });
50
- it('finds simple tables in SQL', async () => {
51
- await connection.fetchSchemaForSQLStruct({
52
- selectStr: `
53
- SELECT
54
- created_at,
55
- sale_price,
56
- inventory_item_id
57
- FROM 'order_items.parquet'
58
- SELECT
59
- id,
60
- product_department,
61
- product_category,
62
- created_at AS inventory_items_created_at
63
- FROM "inventory_items.parquet"
64
- `,
65
- }, {});
66
- expect(findTables).toHaveBeenCalledWith(['order_items.parquet', 'inventory_items.parquet'], {});
67
- });
68
- it('finds table functions in SQL', async () => {
69
- await connection.fetchSchemaForSQLStruct({
70
- selectStr: `
71
- SELECT
72
- created_at,
73
- sale_price,
74
- inventory_item_id
75
- FROM read_parquet('order_items2.parquet', arg='value')
76
- SELECT
77
- id,
78
- product_department,
79
- product_category,
80
- created_at AS inventory_items_created_at
81
- FROM read_parquet("inventory_items2.parquet")
82
- `,
83
- }, {});
84
- expect(findTables).toHaveBeenCalledWith(['order_items2.parquet', 'inventory_items2.parquet'], {});
85
- });
86
- // Test to check that DecimalBigNums are broken.
87
- // Remove/update when fixed, and remove the work-around in
88
- // sqlLiteralNumber()
89
- it('DecimalBigNum is broken', async () => {
90
- const result = await connection.runSQL('SELECT 1.234 AS n1');
91
- expect(result).toEqual({ 'rows': [{ 'n1': 1234 }], 'totalRows': 1 });
92
- });
93
- });
94
- //# sourceMappingURL=duckdb_wasm_connection.spec.js.map