--- spec: openflange.org/pipe/v0.1 id: total-by-customer version: 0.1.0 title: Total by customer (DuckDB SQL) description: Number of orders and total amount per customer, computed by a DuckDB GROUP BY query. license: Apache-2.0 keywords: [duckdb, sql, aggregation, group-by, example] maturity: experimental scope: dataset deterministic: true inputs: orders: description: 'Orders: {"customer": string, "day": "YYYY-MM-DD", "amount": number}.' schema: format: json-schema definition: {type: object} outputs: totals: description: 'One record per customer, ordered by customer: {"customer", "orders", "total"}.' schema: format: json-schema definition: type: object required: [customer, orders, total] properties: customer: {type: [string, "null"]} orders: {type: integer, minimum: 1} total: {type: [number, "null"]} implementation: type: executable command: ["duckdb", "-no-init", "-bail", "-f", "query.sql"] stdin: orders stdout: totals permissions: subprocess: true --- # Total by customer (DuckDB SQL) Implements the [OpenFlange](https://openflange.org/) specification. The `duckdb` command-line shell used as an executable pipe: NDJSON on stdin, the query in [`query.sql`](query.sql), NDJSON on stdout. See [../README.md](../README.md) for input → command → output. - **Dataset scope — the input is materialised.** DuckDB reads all of stdin before the first row comes out. - **Input columns are declared in the query** (`customer` text, `day` date, `amount` decimal(18,2)); other members are ignored. Empty input gives empty output. A value that cannot be converted (`"amount":"abc"`) fails the run with `E_RUNTIME`. A missing or null `amount` is SQL `NULL`, with SQL's usual meaning (`sum` skips it, `count(*)` counts the row). - **Permissions:** `subprocess` (it starts `duckdb`; in-memory database, no files, no network, `-no-init` so no user start-up file is read). A subprocess is not a sandbox. - **Pinned:** verified with DuckDB v2.0.1.