@observablehq/notebook-kit 2.1.8 → 2.1.9
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/package.json +1 -1
- package/dist/src/runtime/stdlib/duckdb.js +30 -12
- package/package.json +1 -1
package/dist/package.json
CHANGED
|
@@ -203,6 +203,8 @@ async function insertSource(database, name, source) {
|
|
|
203
203
|
source = await source;
|
|
204
204
|
if (isFileAttachment(source))
|
|
205
205
|
return insertFile(database, name, source);
|
|
206
|
+
if (isFlechetteTable(source))
|
|
207
|
+
return insertFlechetteTable(database, name, source);
|
|
206
208
|
if (isArrowTable(source))
|
|
207
209
|
return insertArrowTable(database, name, source);
|
|
208
210
|
if (Array.isArray(source))
|
|
@@ -215,6 +217,8 @@ async function insertSource(database, name, source) {
|
|
|
215
217
|
if ("data" in source) {
|
|
216
218
|
// data + options
|
|
217
219
|
const { data, ...options } = source;
|
|
220
|
+
if (isFlechetteTable(data))
|
|
221
|
+
return insertFlechetteTable(database, name, data, options);
|
|
218
222
|
if (isArrowTable(data))
|
|
219
223
|
return insertArrowTable(database, name, data, options);
|
|
220
224
|
return insertArray(database, name, data, options);
|
|
@@ -301,22 +305,28 @@ async function insertUntypedCSV(connection, file, name) {
|
|
|
301
305
|
async function insertArrowTable(database, name, table, options) {
|
|
302
306
|
const connection = await database.connect();
|
|
303
307
|
try {
|
|
304
|
-
await connection.insertArrowTable(table, {
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
308
|
+
await connection.insertArrowTable(table, { name, schema: "main", ...options });
|
|
309
|
+
}
|
|
310
|
+
finally {
|
|
311
|
+
await connection.close();
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
async function insertArrowIpc(database, name, buffer, options) {
|
|
315
|
+
const connection = await database.connect();
|
|
316
|
+
try {
|
|
317
|
+
await connection.insertArrowFromIPCStream(buffer, { name, schema: "main", ...options });
|
|
309
318
|
}
|
|
310
319
|
finally {
|
|
311
320
|
await connection.close();
|
|
312
321
|
}
|
|
313
322
|
}
|
|
323
|
+
async function insertFlechetteTable(database, name, table, options) {
|
|
324
|
+
const { tableToIPC } = await import("https://cdn.jsdelivr.net/npm/@uwdata/flechette@2.5.0/+esm");
|
|
325
|
+
return await insertArrowIpc(database, name, tableToIPC(table, { format: "stream" }), options);
|
|
326
|
+
}
|
|
314
327
|
async function insertArqueroTable(database, name, source) {
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
const arrow = await import("https://cdn.jsdelivr.net/npm/apache-arrow@17.0.0/+esm");
|
|
318
|
-
const table = arrow.tableFromIPC(source.toArrowBuffer());
|
|
319
|
-
return await insertArrowTable(database, name, table);
|
|
328
|
+
const buffer = typeof source.toArrowIPC === "function" ? source.toArrowIPC() : source.toArrowBuffer(); // prettier-ignore
|
|
329
|
+
return await insertArrowIpc(database, name, buffer);
|
|
320
330
|
}
|
|
321
331
|
async function insertArray(database, name, array, options) {
|
|
322
332
|
const arrow = await import("https://cdn.jsdelivr.net/npm/apache-arrow@17.0.0/+esm");
|
|
@@ -372,9 +382,17 @@ function isFileAttachment(value) {
|
|
|
372
382
|
typeof value.url === "function" &&
|
|
373
383
|
typeof value.arrayBuffer === "function");
|
|
374
384
|
}
|
|
375
|
-
// Arquero tables have a `toArrowBuffer` function
|
|
385
|
+
// Arquero tables have a `toArrowBuffer` (v5-) or `toArrowIPC` (v6+) function
|
|
376
386
|
function isArqueroTable(value) {
|
|
377
|
-
return value && typeof value.toArrowBuffer === "function";
|
|
387
|
+
return (value && (typeof value.toArrowBuffer === "function" || typeof value.toArrowIPC === "function"));
|
|
388
|
+
}
|
|
389
|
+
// Flechette tables have a `toColumns` method
|
|
390
|
+
function isFlechetteTable(value) {
|
|
391
|
+
return (value &&
|
|
392
|
+
typeof value.getChild === "function" &&
|
|
393
|
+
typeof value.toColumns === "function" &&
|
|
394
|
+
value.schema &&
|
|
395
|
+
Array.isArray(value.schema.fields));
|
|
378
396
|
}
|
|
379
397
|
// Returns true if the value is an Apache Arrow table. This uses a “duck” test
|
|
380
398
|
// (instead of strict instanceof) because we want it to work with a range of
|