Querying with Trino

Querying BookNest's Lakehouse Tables with Trino

Trino 403,499 speaks ANSI SQL with Analytical SQL and Data Warehouses's toolkit, so analysts query the lakehouse like a warehouse, here through the CLI inside the container (--catalog iceberg --schema booknest --timezone UTC):

genre_q2.sql: gross revenue per genre in the second quarter of 2026SQL
SELECT b.genre, count(DISTINCT o.order_id) AS orders, sum(i.qty * i.unit_price) AS gross
FROM orders o
JOIN order_items i ON i.order_id = o.order_id
JOIN books b ON b.book_id = i.book_id
WHERE o.order_ts >= TIMESTAMP '2026-04-01 00:00:00'
  AND o.order_ts < TIMESTAMP '2026-07-01 00:00:00' AND o.status <> 'cancelled'
GROUP BY b.genre ORDER BY gross DESC
Output
      genre      | orders |   gross
-----------------+--------+-----------
 Technology      |   3075 | 142239.50
 Cooking         |   3879 | 109824.00
 ...
(6 rows)

Partition pruning did its work first: EXPLAIN ANALYZE on the date filter alone reports 32 splits (June's 30 daily files plus two monthly files, Partition Evolution) and 16,553 of the 100,000 rows. The web UI (http://localhost:31080/ui/) records every query, here 1.05 seconds with 166 ms of planning, mostly catalog and manifest reads:

Trino 483's web UI: the overview of the genre query
Trino 483's web UI: the overview of the genre query

Its other tabs show the stages, tasks and splits of Trino's Architecture, the first place to look when a query is slow.