|
| 1 | +import assert from 'node:assert'; |
| 2 | +import { DuckDB } from '@uwdata/mosaic-duckdb'; |
| 3 | +import { tableFromArrays, tableFromIPC, tableToIPC } from '../src/index.js'; |
| 4 | +import * as dataMethods from './util/data.js'; |
| 5 | + |
| 6 | +// Arrow types not supported by DuckDB |
| 7 | +const skip = new Set([ |
| 8 | + 'binaryView', 'empty', 'largeListView', 'listView', |
| 9 | + 'runEndEncoded32', 'runEndEncoded64', 'utf8View' |
| 10 | +]); |
| 11 | + |
| 12 | +describe('DuckDB compatibility', () => { |
| 13 | + for (const [name, method] of Object.entries(dataMethods)) { |
| 14 | + if (skip.has(name)) continue; |
| 15 | + it(`includes ${name} data`, async () => { |
| 16 | + const data = await method(); |
| 17 | + const load = await Promise.all( |
| 18 | + data.map(({ bytes }) => loadIPC(tableFromIPC(bytes))) |
| 19 | + ); |
| 20 | + assert.deepStrictEqual(load, Array(data.length).fill(true)); |
| 21 | + }); |
| 22 | + } |
| 23 | + |
| 24 | + it('includes default dictionary types', async () => { |
| 25 | + const t = tableFromArrays({ foo: ['x', 'y', 'z'] }); |
| 26 | + assert.strictEqual(await loadIPC(t), true); |
| 27 | + }); |
| 28 | +}); |
| 29 | + |
| 30 | +function loadIPC(table) { |
| 31 | + const bytes = tableToIPC(table, { format: 'stream' }); |
| 32 | + return new Promise((resolve) => { |
| 33 | + const db = new DuckDB(); |
| 34 | + db.db.register_buffer('arrow_ipc', [bytes], true, (err) => { |
| 35 | + if (err) { |
| 36 | + console.error(err); |
| 37 | + resolve(false); |
| 38 | + } else { |
| 39 | + resolve(true); |
| 40 | + } |
| 41 | + }); |
| 42 | + }); |
| 43 | +} |
0 commit comments