From b2304812c1427794d84ef82434e35a7093ebbaf6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philippe=20Rivi=C3=A8re?= Date: Sat, 18 Nov 2023 08:39:13 +0100 Subject: [PATCH 1/4] Use an absolute URL to ingest FileAttachments in DuckDB. --- src/duckdb.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/duckdb.js b/src/duckdb.js index 6e42cbf..f102772 100644 --- a/src/duckdb.js +++ b/src/duckdb.js @@ -171,7 +171,7 @@ async function insertFile(database, name, file, options) { const buffer = await file.arrayBuffer(); await database.registerFileBuffer(file.name, new Uint8Array(buffer)); } else { - await database.registerFileURL(file.name, url, 4); // duckdb.DuckDBDataProtocol.HTTP + await database.registerFileURL(file.name, new URL(url, document.location).href, 4); // duckdb.DuckDBDataProtocol.HTTP } const connection = await database.connect(); try { From 9d884215b74c7743a7d2fb8f5eebfe9679db737d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philippe=20Rivi=C3=A8re?= Date: Sat, 18 Nov 2023 08:39:20 +0100 Subject: [PATCH 2/4] simpler syntax --- src/duckdb.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/duckdb.js b/src/duckdb.js index f102772..ae995e3 100644 --- a/src/duckdb.js +++ b/src/duckdb.js @@ -208,7 +208,7 @@ async function insertFile(database, name, file, options) { } if (/\.parquet$/i.test(file.name)) { return await connection.query( - `CREATE VIEW '${name}' AS SELECT * FROM parquet_scan('${file.name}')` + `CREATE VIEW '${name}' AS FROM parquet_scan('${file.name}')` ); } throw new Error(`unknown file type: ${file.mimeType}`); @@ -220,7 +220,7 @@ async function insertFile(database, name, file, options) { async function insertUntypedCSV(connection, file, name) { const statement = await connection.prepare( - `CREATE TABLE '${name}' AS SELECT * FROM read_csv_auto(?, ALL_VARCHAR=TRUE)` + `CREATE TABLE '${name}' AS FROM read_csv_auto(?, ALL_VARCHAR=TRUE)` ); return await statement.send(file.name); } From b4898a4a11349e2ab9d153f2d5aa03e5bbc01a5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philippe=20Rivi=C3=A8re?= Date: Sun, 26 Nov 2023 23:32:09 +0100 Subject: [PATCH 3/4] Update src/duckdb.js Co-authored-by: Mike Bostock --- src/duckdb.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/duckdb.js b/src/duckdb.js index ae995e3..1676a70 100644 --- a/src/duckdb.js +++ b/src/duckdb.js @@ -171,7 +171,7 @@ async function insertFile(database, name, file, options) { const buffer = await file.arrayBuffer(); await database.registerFileBuffer(file.name, new Uint8Array(buffer)); } else { - await database.registerFileURL(file.name, new URL(url, document.location).href, 4); // duckdb.DuckDBDataProtocol.HTTP + await database.registerFileURL(file.name, new URL(url, location).href, 4); // duckdb.DuckDBDataProtocol.HTTP } const connection = await database.connect(); try { From f9f9b48b135d61575375141d7c9c13ed7d36c7bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philippe=20Rivi=C3=A8re?= Date: Sun, 26 Nov 2023 23:38:29 +0100 Subject: [PATCH 4/4] Revert "simpler syntax" This reverts commit 9d884215b74c7743a7d2fb8f5eebfe9679db737d. --- src/duckdb.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/duckdb.js b/src/duckdb.js index 1676a70..0e00d13 100644 --- a/src/duckdb.js +++ b/src/duckdb.js @@ -208,7 +208,7 @@ async function insertFile(database, name, file, options) { } if (/\.parquet$/i.test(file.name)) { return await connection.query( - `CREATE VIEW '${name}' AS FROM parquet_scan('${file.name}')` + `CREATE VIEW '${name}' AS SELECT * FROM parquet_scan('${file.name}')` ); } throw new Error(`unknown file type: ${file.mimeType}`); @@ -220,7 +220,7 @@ async function insertFile(database, name, file, options) { async function insertUntypedCSV(connection, file, name) { const statement = await connection.prepare( - `CREATE TABLE '${name}' AS FROM read_csv_auto(?, ALL_VARCHAR=TRUE)` + `CREATE TABLE '${name}' AS SELECT * FROM read_csv_auto(?, ALL_VARCHAR=TRUE)` ); return await statement.send(file.name); }