@malloydata/db-duckdb 0.0.138-dev240404233606 → 0.0.138-dev240405003346
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/dist/duckdb.spec.js +119 -0
- package/dist/duckdb_common.d.ts +3 -1
- package/dist/duckdb_common.js +9 -5
- package/package.json +2 -2
package/dist/duckdb.spec.js
CHANGED
|
@@ -101,7 +101,116 @@ describe('DuckDBConnection', () => {
|
|
|
101
101
|
await connection2.close();
|
|
102
102
|
});
|
|
103
103
|
});
|
|
104
|
+
describe('schema parser', () => {
|
|
105
|
+
it('parses arrays', () => {
|
|
106
|
+
const structDef = makeStructDef();
|
|
107
|
+
connection.fillStructDefFromTypeMap(structDef, { test: ARRAY_SCHEMA });
|
|
108
|
+
expect(structDef.fields[0]).toEqual({
|
|
109
|
+
'name': 'test',
|
|
110
|
+
'type': 'struct',
|
|
111
|
+
'dialect': 'duckdb',
|
|
112
|
+
'structRelationship': {
|
|
113
|
+
'fieldName': 'test',
|
|
114
|
+
'isArray': true,
|
|
115
|
+
'type': 'nested',
|
|
116
|
+
},
|
|
117
|
+
'structSource': {
|
|
118
|
+
'type': 'nested',
|
|
119
|
+
},
|
|
120
|
+
'fields': [
|
|
121
|
+
{
|
|
122
|
+
'name': 'value',
|
|
123
|
+
'type': 'number',
|
|
124
|
+
'numberType': 'integer',
|
|
125
|
+
},
|
|
126
|
+
],
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
it('parses inline', () => {
|
|
130
|
+
const structDef = makeStructDef();
|
|
131
|
+
connection.fillStructDefFromTypeMap(structDef, { test: INLINE_SCHEMA });
|
|
132
|
+
expect(structDef.fields[0]).toEqual({
|
|
133
|
+
'name': 'test',
|
|
134
|
+
'type': 'struct',
|
|
135
|
+
'dialect': 'duckdb',
|
|
136
|
+
'structRelationship': {
|
|
137
|
+
'type': 'inline',
|
|
138
|
+
},
|
|
139
|
+
'structSource': {
|
|
140
|
+
'type': 'inline',
|
|
141
|
+
},
|
|
142
|
+
'fields': [
|
|
143
|
+
{
|
|
144
|
+
'name': 'a',
|
|
145
|
+
'type': 'number',
|
|
146
|
+
'numberType': 'float',
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
'name': 'b',
|
|
150
|
+
'type': 'number',
|
|
151
|
+
'numberType': 'integer',
|
|
152
|
+
},
|
|
153
|
+
{
|
|
154
|
+
'name': 'c',
|
|
155
|
+
'type': 'string',
|
|
156
|
+
},
|
|
157
|
+
],
|
|
158
|
+
});
|
|
159
|
+
});
|
|
160
|
+
it('parses nested', () => {
|
|
161
|
+
const structDef = makeStructDef();
|
|
162
|
+
connection.fillStructDefFromTypeMap(structDef, { test: NESTED_SCHEMA });
|
|
163
|
+
expect(structDef.fields[0]).toEqual({
|
|
164
|
+
'name': 'test',
|
|
165
|
+
'type': 'struct',
|
|
166
|
+
'dialect': 'duckdb',
|
|
167
|
+
'structRelationship': {
|
|
168
|
+
'fieldName': 'test',
|
|
169
|
+
'isArray': false,
|
|
170
|
+
'type': 'nested',
|
|
171
|
+
},
|
|
172
|
+
'structSource': { 'type': 'nested' },
|
|
173
|
+
'fields': [
|
|
174
|
+
{ 'name': 'a', 'numberType': 'float', 'type': 'number' },
|
|
175
|
+
{ 'name': 'b', 'numberType': 'integer', 'type': 'number' },
|
|
176
|
+
{ 'name': 'c', 'type': 'string' },
|
|
177
|
+
],
|
|
178
|
+
});
|
|
179
|
+
});
|
|
180
|
+
it('parses a simple type', () => {
|
|
181
|
+
const structDef = makeStructDef();
|
|
182
|
+
connection.fillStructDefFromTypeMap(structDef, { test: 'varchar(60)' });
|
|
183
|
+
expect(structDef.fields[0]).toEqual({
|
|
184
|
+
'name': 'test',
|
|
185
|
+
'type': 'string',
|
|
186
|
+
});
|
|
187
|
+
});
|
|
188
|
+
});
|
|
104
189
|
});
|
|
190
|
+
/**
|
|
191
|
+
* Create a basic StructDef for the purpose of passing to
|
|
192
|
+
* DuckDBConnection.fillStructDefFromTypeMap()
|
|
193
|
+
*
|
|
194
|
+
* @returns valid StructDef for testing
|
|
195
|
+
*/
|
|
196
|
+
const makeStructDef = () => {
|
|
197
|
+
return {
|
|
198
|
+
type: 'struct',
|
|
199
|
+
name: 'test',
|
|
200
|
+
dialect: 'duckdb',
|
|
201
|
+
structSource: { type: 'table', tablePath: 'test' },
|
|
202
|
+
structRelationship: {
|
|
203
|
+
type: 'basetable',
|
|
204
|
+
connectionName: 'duckdb',
|
|
205
|
+
},
|
|
206
|
+
fields: [],
|
|
207
|
+
};
|
|
208
|
+
};
|
|
209
|
+
//
|
|
210
|
+
// SQL blocks for testing table name detection in
|
|
211
|
+
// DuckDBConnection.fetchSchemaForSQLBlock()
|
|
212
|
+
//
|
|
213
|
+
// Uses string value for table
|
|
105
214
|
const SQL_BLOCK_1 = {
|
|
106
215
|
type: 'sqlBlock',
|
|
107
216
|
name: 'block1',
|
|
@@ -119,6 +228,7 @@ created_at AS inventory_items_created_at
|
|
|
119
228
|
FROM "inventory_items.parquet"
|
|
120
229
|
`,
|
|
121
230
|
};
|
|
231
|
+
// Uses read_parquet() for table
|
|
122
232
|
const SQL_BLOCK_2 = {
|
|
123
233
|
type: 'sqlBlock',
|
|
124
234
|
name: 'block2',
|
|
@@ -136,4 +246,13 @@ created_at AS inventory_items_created_at
|
|
|
136
246
|
FROM read_parquet("inventory_items2.parquet")
|
|
137
247
|
`,
|
|
138
248
|
};
|
|
249
|
+
//
|
|
250
|
+
// Type strings for testing DuckDBConnection.fillStructDefFromTypeMap()
|
|
251
|
+
//
|
|
252
|
+
// 'integer[]' is array
|
|
253
|
+
const ARRAY_SCHEMA = 'integer[]';
|
|
254
|
+
// STRUCT(...) is inline
|
|
255
|
+
const INLINE_SCHEMA = 'STRUCT(a double, b integer, c varchar(60))';
|
|
256
|
+
// STRUCT(....)[] is nested
|
|
257
|
+
const NESTED_SCHEMA = 'STRUCT(a double, b integer, c varchar(60))[]';
|
|
139
258
|
//# sourceMappingURL=duckdb.spec.js.map
|
package/dist/duckdb_common.d.ts
CHANGED
|
@@ -41,7 +41,9 @@ export declare abstract class DuckDBCommon implements TestableConnection, Persis
|
|
|
41
41
|
*/
|
|
42
42
|
private splitColumns;
|
|
43
43
|
private stringToTypeMap;
|
|
44
|
-
|
|
44
|
+
fillStructDefFromTypeMap(structDef: StructDef, typeMap: {
|
|
45
|
+
[name: string]: string;
|
|
46
|
+
}): void;
|
|
45
47
|
private schemaFromQuery;
|
|
46
48
|
fetchSchemaForSQLBlock(sqlRef: SQLBlock, { refreshTimestamp }: FetchSchemaOptions): Promise<{
|
|
47
49
|
structDef: StructDef;
|
package/dist/duckdb_common.js
CHANGED
|
@@ -181,11 +181,15 @@ class DuckDBCommon {
|
|
|
181
181
|
name,
|
|
182
182
|
dialect: this.dialectName,
|
|
183
183
|
structSource: { type: arrayMatch ? 'nested' : 'inline' },
|
|
184
|
-
structRelationship:
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
184
|
+
structRelationship: arrayMatch
|
|
185
|
+
? {
|
|
186
|
+
type: 'nested',
|
|
187
|
+
fieldName: name,
|
|
188
|
+
isArray: false,
|
|
189
|
+
}
|
|
190
|
+
: {
|
|
191
|
+
type: 'inline',
|
|
192
|
+
},
|
|
189
193
|
fields: [],
|
|
190
194
|
};
|
|
191
195
|
this.fillStructDefFromTypeMap(innerStructDef, newTypeMap);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@malloydata/db-duckdb",
|
|
3
|
-
"version": "0.0.138-
|
|
3
|
+
"version": "0.0.138-dev240405003346",
|
|
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.28.1-dev106.0",
|
|
44
|
-
"@malloydata/malloy": "^0.0.138-
|
|
44
|
+
"@malloydata/malloy": "^0.0.138-dev240405003346",
|
|
45
45
|
"@motherduck/wasm-client": "^0.4.0",
|
|
46
46
|
"apache-arrow": "^14.0.0",
|
|
47
47
|
"duckdb": "0.9.2",
|