Expand description
DuckDB-free core of the improv DuckDB extension (crates/duckdb_improv).
The extension reads rows through DuckDB and hands them here as plain Rust
values, the same split as improv_pg_model / pg_improv:
calc:improv_calc/improv_calc_text, a scalar formula over named JSON inputs (compiled once, cached);function_rows:improv_functions, the built-in function registry;parse_spec,bind, the*_sqlbuilders andrun:improv(source, model), a small model spec over a table or query, the SQL that reads it, and the engine’s cells as result rows.
The model spec has one item per line (blank lines and # / --
comments are skipped):
category <Name> = <column>
input <Name> = <column> [sum|avg|min|max|count]
<Name> = <formula>Every input ranges over every category. A category’s items are its
column’s distinct non-NULL values in the column’s own order (numbers
numerically, dates chronologically), so PREV and NEXT follow it.
Modules§
- calc
improv_calc(formula [, inputs]): one scalar Improv formula over named inputs, the engine’s own per-cell operators ([improv_engine::scalar]), asLANGUAGE improvevaluates a function body.
Structs§
- Bound
- The spec bound to the source’s columns.
- Category
Spec - A
category <Name> = <column>line. - Column
- A source column as
DESCRIBEreports it. - Derived
Spec - A
<Name> = <formula>line. - Function
Row - One row of
improv_functions(). - Input
Spec - An
input <Name> = <column> [agg]line. - Row
- One result row of
improv(source, model). - Spec
- A parsed model spec.
Enums§
- Cell
Value - Re-exported so the extension shell needs no direct engine dependency. The dataflow encoding of a cell value.
- Error
- Everything that can go wrong building or running a model.
- Value
Type - Re-exported so the extension shell needs no direct engine dependency. The declared type of a measure.
Functions§
- bind
- Resolve the spec’s columns against the source (DuckDB names are
case-insensitive) and type its inputs: numbers, booleans and text;
sumandavgneed a number,countis a number. - describe_
sql - The SQL listing the source’s columns and types.
- function_
rows - The built-in functions in registry order; with
query, those [functions::search] finds, best match first. - input_
sql - The SQL reading input
i’s rows: every category column as text, then the value as aDOUBLE,BOOLEANorVARCHAR, aggregated per coordinate when the input has an aggregation. - items_
sql - The SQL listing a category’s items: its column’s distinct non-NULL values as text, in the column’s own order.
- parse_
spec - Parse a model spec. Errors name the offending line.
- run
- Build the model from the spec, its categories’ items (from
items_sql, per category) and its inputs’ rows (frominput_sql, per input), evaluate every derived measure, and return one row per derived cell: measures in declaration order, each one’s cells in item order. - source_
sql - The source in a
FROM: a query (SELECT,WITH,FROM,VALUES, or anything parenthesized) as a subquery, else a table or view name as written. A trailing;is dropped.