holdenmatt / duckdb-wasm-kit

Hooks and utilities to make it easier to use duckdb-wasm in React apps.
https://www.npmjs.com/package/duckdb-wasm-kit
MIT License
101 stars 4 forks source link

JSON file import support #6

Closed rohitgarud closed 7 months ago

rohitgarud commented 10 months ago

This is a feature request rather than an issue!!

Thank you for this amazing package. I was wondering whether it is possible to add support to directly import JSON files as DuckDB itself supports this.

holdenmatt commented 10 months ago

Thanks for the request! I would also love this, but it needs dynamic extension loading.

As soon as the DuckDB team pushes 0.9.0 support to npm (stilll wip), I’ll update and look into adding json.

rohitgarud commented 10 months ago

Thanks for the request! I would also love this, but it needs dynamic extension loading.

As soon as the DuckDB team pushes 0.9.0 support to npm (stilll wip), I’ll update and look into adding json.

Thank you for the quick response.. looking forward to the update..

rohitgarud commented 10 months ago

How can we save the result of the query (Arrow) to a JSON file? JSON.stringify after arrowToJSON is throwing BigInt not JSON serializable error.. Please let me know if there is any solution

holdenmatt commented 10 months ago

If your datasets are large, it's better to avoid converting to JSON, and access the values via the row proxy objects, like this:

const row = arrow.get(rowIndex);

If you do want to convert a whole Arrow table to JSON, you can do:

const jsonRows = arrow.toArray().map((row) => row.toJSON());

DuckDB outputs BigInts by default. To convert them to JS numbers, you'll want to use the castBigIntToDouble config value as documented here.

rohitgarud commented 10 months ago

Thank you very much for the detailed response.. very helpful..

holdenmatt commented 7 months ago

I've upgraded to the latest duckdb-wasm version, which now supports dynamic extension loading.

I haven't played with the "json" extension myself, but it should now be usable when you execute load "json" as described here: https://duckdb.org/docs/extensions/json.html

Let me know if you have any issues with it :)