Skip to main content

Crate improv_duckdb_model

Crate improv_duckdb_model 

Source
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 *_sql builders and run: 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]), as LANGUAGE improv evaluates a function body.

Structs§

Bound
The spec bound to the source’s columns.
CategorySpec
A category <Name> = <column> line.
Column
A source column as DESCRIBE reports it.
DerivedSpec
A <Name> = <formula> line.
FunctionRow
One row of improv_functions().
InputSpec
An input <Name> = <column> [agg] line.
Row
One result row of improv(source, model).
Spec
A parsed model spec.

Enums§

CellValue
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.
ValueType
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; sum and avg need a number, count is 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 a DOUBLE, BOOLEAN or VARCHAR, 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 (from input_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.

Type Aliases§

FactRow
One fact row: the category values (in declaration order) and the value.
Result
Result alias for this crate.