Skip to content

Commit 80d6fcd

Browse files
committed
test: Add DuckDB arrow scan compatibility tests.
1 parent da2fb3f commit 80d6fcd

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

test/duckdb-compat-test.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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

Comments
 (0)