Query cached results with SQL (DuckDB) — each asset is a named view

Usage: barca sql [OPTIONS] <QUERY> [FILES]...

Arguments:
  <QUERY>
          The SQL query (DuckDB dialect); quote it as one argument

  [FILES]...
          Python files or directories; default: discover the project

Options:
      --json
          Emit JSON on stdout (the default when stdout is not a terminal)

      --pretty
          Emit human-readable output (the default when stdout is a terminal)

  -l, --limit <LIMIT>
          Maximum number of rows to return

          [default: 100]

      --all
          Return every row (no limit)

      --env <ENV>
          Use a separate cache and history for this environment

      --server [<URL>]
          Use a server (URL or configured); get/run execute its deployed code

      --local
          Run on this machine; ignore a configured server and this project's barca serve

  -h, --help
          Show concise command help

      --examples
          Show all command examples without running anything

Examples:
  barca sql "select * from revenue"                       # one view per asset, using its declared name or function fallback
  barca sql "select region, sum(amount) from orders group by 1"   # any DuckDB SQL over cached results
  barca sql "select * from orders o join revenue r using (region)" # join assets
  barca sql "select * from weekly where partition = 'week=w1'"   # partitioned: one view, a partition column
  barca sql "select status from validate"                  # a task's last result is a view too
  barca sql "select * from orders" pipeline.py              # only nodes in this file become views
  barca sql "select * from orders" --limit 20               # first 20 rows (default: at most 100)
  barca sql "select * from orders" --all                    # every row
  barca sql "select * from orders" --json                   # {columns, rows, total, truncated, hint?}
  barca sql "select * from orders" --env dev                # results cached in another environment
  barca sql "select target, status, elapsed_seconds from barca.runs where status = 'failed' order by started_at desc limit 10"
  barca sql "select node_id, elapsed_seconds, size_bytes from barca.materializations order by created_at desc"
  barca sql "select name, state, reason from barca.nodes where state <> 'cached'"
  barca sql "select sum(gap_seconds) as gap, count(*) filter (where cause is not null and expected_fresh_at is null) as unbounded from barca.nodes"   # the freshness gap as one number
  barca sql "select root_kind, root_node, count(*) as nodes, sum(gap_seconds) as gap from barca.nodes where root_id is not null group by all order by nodes desc"   # what holds the nodes that are not fresh
  barca sql "select id, interval_seconds, typical_queue_wait_seconds from barca.schedules where queue_bound"   # schedules whose ticks wait for a run slot
  barca sql "select scheduled_at, action, run_status, failed, not_reached from barca.ticks order by scheduled_at desc limit 20"   # what the last ticks did
  barca sql "select * from revenue" --local                # this machine's results, not a configured server's
  barca sql "select * from revenue" --server https://barca.example.com   # views resolved by that server
  barca sql "select status, count(*) from barca.runs group by all" --server https://barca.example.com   # barca's tables alone: the server answers

More: barca docs sql
