Live data from Hacker News

DuckDB as the New jq

pgrs.net

1–10 of 74 posts

Re: DuckDB as the New jq

#2
Very cool!

I am also a big fan of jq.

And I think using DuckDB and SQL probably makes a lot of sense in a lot of cases.

But I think the examples are very geared towards being better solved in SQL.

The ideal jq examples are combinations of filter (select), map (map) and concat (.[]).

For example, finding the right download link:

  $ curl -s https://api.github.com/repos/go-gitea/gitea/releases/latest \
    | jq -r '.assets[]
             | .browser_download_url
             | select(endswith("linux-amd64"))'
  https://github.com/go-gitea/gitea/releases/download/v1.15.7/gitea-1.15.7-linux-amd64
Or extracting the KUBE_CONFIG of a DigitalOcean Kubernetes cluster from Terraform state:

  $ jq -r '.resources[]
          | select(.type == "digitalocean_kubernetes_cluster")
          | .instances[].attributes.kube_config[].raw_config' \ 
      terraform.tfstate
  apiVersion: v1
  kind: Config
  clusters:
  - cluster:
      certificate-authority-data: ...
      server: https://...k8s.ondigitalocean.com
  ...

Re: DuckDB as the New jq

#5
post #2

Very cool! I am also a big fan of jq. And I think using DuckDB and SQL probably makes a lot of sense in a lot of cases. But I think the examples are very geared towards being better solved in SQL. The ideal jq examples are combinations of filter (select), map (map) and concat (.[]). For example, finding the right download link: $ curl -s https://api.github.com/repos/go-gitea/gitea/releases/latest \ | jq -r '.assets[]…

I think that's a fair point. Unnesting arrays in SQL can be annoying. Here is your first example with duckdb:

  duckdb -c \
    "select * from ( \
      select unnest(assets)->>'browser_download_url' as url \
      from read_json('https://api.github.com/repos/go-gitea/gitea/releases/latest') \
    ) \
    where url like '%linux-amd64'"

Re: DuckDB as the New jq

#9
I tried this and it just seems to add bondage and discipline that I don't need on top of what is, in practice, an extremely chaotic format.

Example: trying to pick one field out of 20000 large JSON files that represent local property records.

% duckdb -json -c "select apn.apnNumber from read_json('*')" Invalid Input Error: JSON transform error in file "052136400500", in record/value 1: Could not convert string 'fb1b1e68-89ee-11ea-bc55-0242ad1302303' to INT128

Well, I didn't want that converted. I just want to ignore it. This has been my experience overall. DuckDB is great if there is a logical schema, not as good as jq when the corpus is just data soup.

Re: DuckDB as the New jq

#10
Related, clickhouse local cli command is a speed demon to parse and query JSON and other formats such as CSV:

- "The world’s fastest tool for querying JSON files" https://clickhouse.com/blog/worlds-fastest-json-querying-too...

- "Show HN: ClickHouse-local – a small tool for serverless data analytics" https://news.ycombinator.com/item?id=34265206

Post reply on HN