Live data from Hacker News

DuckDB: Querying JSON files as if they were tables

duckdb.org

71–80 of 81 posts

Re: DuckDB: Querying JSON files as if they were tables

#71
post #67
post #66

If you ever need to join two large dataframes, but are OOMing on the join, write them to disk as parquet files then use DuckDB to do the join. It's amazing what you can do on one machine thanks to DuckDB.

This isn't unique to duckdb. Almost all databases allow for sorting and joins of large tables that don't fit into memory.

Yes but if you're in a Jupyter notebook, you may not be directly connected to a DB. If you're using pandas, this unlocks some scalability before needing dask and a cluster.

Re: DuckDB: Querying JSON files as if they were tables

#72
post #70
post #59

Ah I was looking for exactly this the other day. I'm try to build a git based interface to our BI tool so that we can get config for our reports in source control instead of configuration in a db. Was looking for something to read json files which will house the config via SQL, i.e. a human readable db as an alternative to what the BI tool is using for it's config persistence. Will give DuckDB a go, thanks for postin…

Are you talking about metabase by any chance?

Haha indeed! I've started with a very basic Ruby api client that can read and create dashboards.

My plan is to poc a tool that allows you to edit metabase config as files and secondly something that can replicate cloud instances to other environments like local docker image or staging instance

Re: DuckDB: Querying JSON files as if they were tables

#73

What's funny, is I've wanted something similar as a feature for "Azure Data Studio" that can open/use a CSV file and query it as a sqlite table. Basically an auto-import to a temp or in-memory db/table that you can then query against. Would just be a nice gui feature to have.

That is exactly https://superintendent.app (disclaimer: I'm the creator)

Re: DuckDB: Querying JSON files as if they were tables

#74
This is cool, but would like to give some higher level context about querying JSON files.

JSON is a row based file format. It doesn't allow query engines to skip rows or skip columns when running queries, so all data needs to get read into memory. That's really inefficient.

Column based file formats allow for query engines to skip entire columns of data (e.g. Parquet). Parquet also stores metadata on row groups and allows query engines to skip rows when reading data. These performance enhancements can speed up queries from 0x - 100x or more (depends on how much data is skipped).

Data Lakehouse storage systems abstract the file metadata to a separate layer, which is even better than storing it in the file footer like Parquet does.

This DuckDB functionality is cool, but I think it's best to use it to convert JSON files to Parquet / a Lakehouse storage system, and then query them. JSON is a really inefficient file format for running queries.

Re: DuckDB: Querying JSON files as if they were tables

#75

This is really cool! With their Postgres scanner[0] you can now easily query multiple datasources using SQL and join between them (i.e. Postgres table with JSON file). Something I previously strived to build with OctoSQL[1]. There's even predicate push-down to the underlying databases (for Postgres)! It's amazing to see how quickly DuckDB is adding new features. Not a huge fan of C++, which is right now used for auth…

After having tried their PostgreSQL plugin I feel like it's a bit too early to use in production.

Very little amount and unclear pushdown filters are one of the issues, not handling certain data types and thus not being able to scan the table (even if the column in question isn't used) is another.

I think that DuckDB is also missing a PostgreSQL logical replication driver to continuously replicate a subset of tables you want to run stats on.

Syncing the full table every time is too slow.

Re: DuckDB: Querying JSON files as if they were tables

#76

Mind you this isn’t appropriate for most cases. But I love the idea of “you start with text file. You end with text file. All the database stuff, indexes, etc. are just a detail.” Often I find that the database wants to be the authority and that makes working with different formats a bit uncomfortable.

We’re currently building real-time apis backed by terabytes of compressed parquet… hundreds of billions of ‘rows’… in exactly this fashion using polars. It amazes us at every turn. Join us and help!

What project?

Do you mean polars reading Parquet into DuckDB to process that amount of data?

Re: DuckDB: Querying JSON files as if they were tables

#77

Welcome to the gang! :) https://github.com/multiprocessio/dsq#comparisons Realistically though aside from the variety of input formats that DuckDB doesn't (yet) support, I think most people should probably use DuckDB or ClickHouse-local. Tools like dsq can provide broader support or a slightly simpler UX in some cases (and even that is obviously debatable). But I think the future is more the DuckDB or ClickHouse-loca…

I made a docker image with a number of extensions already installed and enabled so you can start using DuckDB with the lowest friction.

`alias dckr='docker run --rm -it -v $(pwd):/data -w /data duckerlabs/ducker'`

then `dckr` gives you a DuckDB shell with PRQL, httpfs, json, parquet, postgres, sqlite, and substrait enabled.

For example, to get the first 5 lines of a csv file named "albums.csv", you could run it with PRQL

```dckr -c 'from `albums.csv` | take 5;'```

https://github.com/duckerlabs/ducker

Re: DuckDB: Querying JSON files as if they were tables

#78
post #23

Very nice! Does anyone know if we can query duckdb with a pandas dialect?

Not Pandas but very similar and (in my very biased opinion) better is PRQL (www.prql-lang.org) which as of yesterday you can now use in DuckDB!

See my comment above: https://news.ycombinator.com/item?id=35027712

Re: DuckDB: Querying JSON files as if they were tables

#79

Running into a couple issues right out of the gate: 1) Needed to increase maximum_object_size 2) Unexpected yyjson tag in ValTypeToString Couldn't find a reference anywhere to that error. Loads into Snowflake without a hitch - which is where I normally query large JSON files.

Thanks for trying it out! Could you perhaps open an issue [1] or share the file with us so we could investigate the problem? [1] https://github.com/duckdb/duckdb/issues

I tried to do "select * from ... limit 1" from a 1.7GB JSON file (array of objects), and I had to increase maximum_object_size to 1GB to make it not throw an error. But DuckDB then consumed 8GB of RAM and sat there consuming 100% CPU (1 core) for ever — I killed it after about 10 minutes.

Meanwhile, doing the same with Jq ("jq '.[0]'") completed in 11 seconds and consumed about 2.8GB RAM.

I love DuckDB, but it does seem like something isn't right here.

Re: DuckDB: Querying JSON files as if they were tables

#80

Earlier quoted context omitted.

We’re currently building real-time apis backed by terabytes of compressed parquet… hundreds of billions of ‘rows’… in exactly this fashion using polars. It amazes us at every turn. Join us and help!

What project? Do you mean polars reading Parquet into DuckDB to process that amount of data?

Internal. We're using Polars as the query engine to effectively query that data statically at rest (more accurately, mmap'd on disk in arrow ipc format)
Post reply on HN