@malloydata/db-duckdb 0.0.29-dev230330180545 → 0.0.29-dev230330224139

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.
@@ -1,5 +1,5 @@
1
1
  import * as duckdb from '@malloydata/duckdb-wasm';
2
- import { QueryDataRow, RunSQLOptions, StructDef } from '@malloydata/malloy';
2
+ import { QueryDataRow, RunSQLOptions, StructDef, SQLBlock } from '@malloydata/malloy';
3
3
  import { DuckDBCommon, QueryOptionsReader } from './duckdb_common';
4
4
  declare type RemoteFileCallback = (tableName: string) => Promise<Uint8Array | undefined>;
5
5
  export declare abstract class DuckDBWASMConnection extends DuckDBCommon {
@@ -24,7 +24,15 @@ export declare abstract class DuckDBWASMConnection extends DuckDBCommon {
24
24
  totalRows: number;
25
25
  }>;
26
26
  runSQLStream(sql: string, _options?: RunSQLOptions): AsyncIterableIterator<QueryDataRow>;
27
- fetchSchemaForTables(tables: string[]): Promise<{
27
+ private findTables;
28
+ fetchSchemaForSQLBlock(sqlRef: SQLBlock): Promise<{
29
+ structDef: StructDef;
30
+ error?: undefined;
31
+ } | {
32
+ error: string;
33
+ structDef?: undefined;
34
+ }>;
35
+ fetchSchemaForTables(tableUris: string[]): Promise<{
28
36
  schemas: Record<string, StructDef>;
29
37
  errors: Record<string, string>;
30
38
  }>;
@@ -54,6 +54,7 @@ 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*'(.*)'/gi;
57
58
  /**
58
59
  * Arrow's toJSON() doesn't really do what I'd expect, since
59
60
  * it still includes Arrow objects like DecimalBigNums and Vectors,
@@ -201,7 +202,7 @@ class DuckDBWASMConnection extends duckdb_common_1.DuckDBCommon {
201
202
  }
202
203
  }
203
204
  }
204
- async fetchSchemaForTables(tables) {
205
+ async findTables(tables) {
205
206
  const fetchRemoteFile = async (tablePath) => {
206
207
  var _a;
207
208
  for (const callback of this.remoteFileCallbacks) {
@@ -214,8 +215,7 @@ class DuckDBWASMConnection extends duckdb_common_1.DuckDBCommon {
214
215
  return true;
215
216
  };
216
217
  await this.setup();
217
- for (const tableUri of tables) {
218
- const { tablePath } = (0, malloy_1.parseTableURI)(tableUri);
218
+ for (const tablePath of tables) {
219
219
  // http and s3 urls are handled by duckdb-wasm
220
220
  if (tablePath.match(/^https?:\/\//)) {
221
221
  continue;
@@ -230,7 +230,22 @@ class DuckDBWASMConnection extends duckdb_common_1.DuckDBCommon {
230
230
  // Wait for response
231
231
  await this.remoteFileStatus[tablePath];
232
232
  }
233
- return super.fetchSchemaForTables(tables);
233
+ }
234
+ async fetchSchemaForSQLBlock(sqlRef) {
235
+ const tables = [];
236
+ for (const match of sqlRef.selectStr.matchAll(TABLE_MATCH)) {
237
+ tables.push(match[1]);
238
+ }
239
+ await this.findTables(tables);
240
+ return super.fetchSchemaForSQLBlock(sqlRef);
241
+ }
242
+ async fetchSchemaForTables(tableUris) {
243
+ const tables = tableUris.map(tableUri => {
244
+ const { tablePath } = (0, malloy_1.parseTableURI)(tableUri);
245
+ return tablePath;
246
+ });
247
+ await this.findTables(tables);
248
+ return super.fetchSchemaForTables(tableUris);
234
249
  }
235
250
  async close() {
236
251
  if (this._connection) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@malloydata/db-duckdb",
3
- "version": "0.0.29-dev230330180545",
3
+ "version": "0.0.29-dev230330224139",
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
  "@malloydata/duckdb-wasm": "0.0.1",
44
- "@malloydata/malloy": "^0.0.29-dev230330180545",
44
+ "@malloydata/malloy": "^0.0.29-dev230330224139",
45
45
  "apache-arrow": "^11.0.0",
46
46
  "duckdb": "0.7.1",
47
47
  "web-worker": "^1.2.0"