trdsql treats JSON(jq processed JSON) as a table and executes SQL.
trdsql -driver sqlite3 -ojsonl
"SELECT json(author_name)->>0 AS author_name, count(*) AS count
FROM openlibrary.json::.docs
WHERE author_name IS NOT NULL AND publish_year IS NOT NULL
GROUP BY json(author_name)->>0 ORDER BY count DESC LIMIT 3"
The “.docs” after the “::” in “openlibrary.json::.docs” is the jq syntax.
Only this part is jq syntax, and the others are SQL.
trdsql just includes the gojq library, which eliminates the need for the jq command.
This is the same as passing jq as a filter.
jq .docs openlibrary.json| trdsql -driver sqlite3 -ijson -ojsonl
"SELECT json(author_name)->>0 AS author_name, count(*) AS count
FROM - WHERE author_name IS NOT NULL AND publish_year IS NOT NULL
GROUP BY json(author_name)->>0 ORDER BY count DESC LIMIT 3"
sqlite3 does not yet have a standard unicode normalization function.
However, PostgreSQL has a normalize function.
trdsql -driver postgres -dsn "dbname=trdsql" -ojsonl
"SELECT json(normalize(author_name))->>0 AS author_name, count(*) AS count
FROM openlibrary.json::.docs WHERE author_name IS NOT NULL AND publish_year IS NOT NULL
GROUP BY json(normalize(author_name))->>0 ORDER BY count DESC LIMIT 3"