Different pipes. One standard.

Type to search this site.

Search runs in your browser against a static index built with this site (Pagefind). Nothing you type is sent to a server.

Can a SQL query be a step?

Available — v0.0.1 (experimental)sqlduckdb

Aggregate with DuckDB SQL

A SQL aggregation as a pipe: order records in, one total per customer out. A .sql file plus a manifest is a pipe.

Available in v0.0.1: the files, README and tests are in examples/duckdb-sql of the openflange-go repository. Commands run from the repository root.

Needs: the duckdb CLI on PATH (the repository verified it with v2.0.1).

A pipe is a data-processing step with declared inputs and outputs.

What goes in, what comes out

Input — examples/duckdb-sql/orders.ndjson
{"customer":"ada","day":"2026-12-01","amount":10}
{"customer":"bob","day":"2026-12-01","amount":5.5}
{"customer":"ada","day":"2026-12-02","amount":32}
{"customer":"bob","day":"2026-12-03","amount":20}
Command
openflange run ./examples/duckdb-sql/total-by-customer --grant subprocess < examples/duckdb-sql/orders.ndjson
Output (stdout)
{"customer":"ada","orders":2,"total":42.00}
{"customer":"bob","orders":2,"total":25.50}

Files and further commands

examples/duckdb-sql/total-by-customer/query.sql
-- SPDX-License-Identifier: Apache-2.0
-- Aggregation: one output row per customer.
-- NDJSON in on stdin, NDJSON out on stdout. DuckDB reads ALL of the input
-- before the first row comes out (dataset scope).
COPY (
  SELECT
    customer,
    count(*)    AS orders,
    sum(amount) AS total
  FROM read_json_auto('/dev/stdin', format = 'newline_delimited',
                      columns = {customer: 'VARCHAR', day: 'DATE', amount: 'DECIMAL(18,2)'})
  GROUP BY customer
  ORDER BY customer
) TO '/dev/stdout' (FORMAT json);
Window functions work the same way
openflange run ./examples/duckdb-sql/running-total --grant subprocess < examples/duckdb-sql/orders.ndjson
# {"customer":"ada","day":"2026-12-01","amount":10.00,"running_total":10.00,"amount_rank":3}
# {"customer":"ada","day":"2026-12-02","amount":32.00,"running_total":42.00,"amount_rank":1}
# {"customer":"bob","day":"2026-12-01","amount":5.50,"running_total":5.50,"amount_rank":4}
# {"customer":"bob","day":"2026-12-03","amount":20.00,"running_total":25.50,"amount_rank":2}

What to notice

  • This materialises the dataset. The pipe declares scope: dataset: DuckDB reads all of stdin before the first row comes out. That is what a GROUP BY needs, but it is not streaming.
  • SQL window functions (OVER (…)) are not stream windows. A windows stream (std:window, see the moving-window example) groups records as they flow, in bounded memory.
  • Amounts are DECIMAL(18,2), which is why the totals print as 42.00.
  • Permissions: subprocess only — an in-memory database, no files, no network. It was not re-run for this page (no DuckDB on the machine that built it).