@malloydata/db-duckdb 0.0.222-dev241212001744 → 0.0.222-dev241212021944

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.
@@ -28,18 +28,6 @@ export declare abstract class DuckDBCommon extends BaseConnection implements Tes
28
28
  abstract runSQLStream(sql: string, options: RunSQLOptions): AsyncIterableIterator<QueryDataRow>;
29
29
  fetchSelectSchema(sqlRef: SQLSourceDef): Promise<SQLSourceDef | string>;
30
30
  estimateQueryCost(_: string): Promise<QueryRunStats>;
31
- /**
32
- * Split's a structs columns declaration into individual columns
33
- * to be fed back into fillStructDefFromTypeMap(). Handles commas
34
- * within nested STRUCT() declarations.
35
- *
36
- * (https://github.com/malloydata/malloy/issues/635)
37
- *
38
- * @param s struct's column declaration
39
- * @return Array of column type declarations
40
- */
41
- private splitColumns;
42
- private stringToTypeMap;
43
31
  fillStructDefFromTypeMap(structDef: StructDef, typeMap: {
44
32
  [name: string]: string;
45
33
  }): void;
@@ -91,104 +91,13 @@ class DuckDBCommon extends connection_1.BaseConnection {
91
91
  async estimateQueryCost(_) {
92
92
  return {};
93
93
  }
94
- /**
95
- * Split's a structs columns declaration into individual columns
96
- * to be fed back into fillStructDefFromTypeMap(). Handles commas
97
- * within nested STRUCT() declarations.
98
- *
99
- * (https://github.com/malloydata/malloy/issues/635)
100
- *
101
- * @param s struct's column declaration
102
- * @return Array of column type declarations
103
- */
104
- splitColumns(s) {
105
- const columns = [];
106
- let parens = 0;
107
- let column = '';
108
- let eatSpaces = true;
109
- for (let idx = 0; idx < s.length; idx++) {
110
- const c = s.charAt(idx);
111
- if (eatSpaces && c === ' ') {
112
- // Eat space
113
- }
114
- else {
115
- eatSpaces = false;
116
- if (!parens && c === ',') {
117
- columns.push(column);
118
- column = '';
119
- eatSpaces = true;
120
- }
121
- else {
122
- column += c;
123
- }
124
- if (c === '(') {
125
- parens += 1;
126
- }
127
- else if (c === ')') {
128
- parens -= 1;
129
- }
130
- }
131
- }
132
- columns.push(column);
133
- return columns;
134
- }
135
- stringToTypeMap(s) {
136
- const ret = {};
137
- const columns = this.splitColumns(s);
138
- for (const c of columns) {
139
- //const [name, type] = c.split(" ", 1);
140
- const columnMatch = c.match(/^(?<name>[^\s]+) (?<type>.*)$/);
141
- if (columnMatch && columnMatch.groups) {
142
- ret[columnMatch.groups['name']] = columnMatch.groups['type'];
143
- }
144
- else {
145
- throw new Error(`Badly form Structure definition ${s}`);
146
- }
147
- }
148
- return ret;
149
- }
150
94
  fillStructDefFromTypeMap(structDef, typeMap) {
151
95
  for (const fieldName in typeMap) {
152
- let duckDBType = typeMap[fieldName];
153
96
  // Remove quotes from field name
154
97
  const name = unquoteName(fieldName);
155
- let malloyType = this.dialect.sqlTypeToMalloyType(duckDBType);
156
- const arrayMatch = duckDBType.match(/(?<duckDBType>.*)\[\]$/);
157
- if (arrayMatch && arrayMatch.groups) {
158
- duckDBType = arrayMatch.groups['duckDBType'];
159
- }
160
- const structMatch = duckDBType.match(/^STRUCT\((?<fields>.*)\)$/);
161
- if (structMatch && structMatch.groups) {
162
- const newTypeMap = this.stringToTypeMap(structMatch.groups['fields']);
163
- let innerStructDef;
164
- const structhead = { name, dialect: this.dialectName, fields: [] };
165
- if (arrayMatch) {
166
- innerStructDef = {
167
- type: 'array',
168
- elementTypeDef: { type: 'record_element' },
169
- join: 'many',
170
- ...structhead,
171
- };
172
- }
173
- else {
174
- innerStructDef = {
175
- type: 'record',
176
- join: 'one',
177
- ...structhead,
178
- };
179
- }
180
- this.fillStructDefFromTypeMap(innerStructDef, newTypeMap);
181
- structDef.fields.push(innerStructDef);
182
- }
183
- else {
184
- if (arrayMatch) {
185
- malloyType = this.dialect.sqlTypeToMalloyType(duckDBType);
186
- structDef.fields.push((0, malloy_1.mkArrayDef)(malloyType, name, this.dialectName));
187
- }
188
- else {
189
- structDef.fields.push({ ...malloyType, name });
190
- }
191
- }
98
+ const dbType = typeMap[fieldName];
99
+ const malloyType = this.dialect.parseDuckDBType(dbType);
100
+ structDef.fields.push((0, malloy_1.mkFieldDef)(malloyType, name, 'duckdb'));
192
101
  }
193
102
  }
194
103
  async schemaFromQuery(infoQuery, structDef) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@malloydata/db-duckdb",
3
- "version": "0.0.222-dev241212001744",
3
+ "version": "0.0.222-dev241212021944",
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.222-dev241212001744",
44
+ "@malloydata/malloy": "^0.0.222-dev241212021944",
45
45
  "@motherduck/wasm-client": "^0.6.6",
46
46
  "apache-arrow": "^17.0.0",
47
47
  "duckdb": "1.1.1",