DuckDB analytical expression helpers for Ecto queries.
These macros wrap DuckDB-specific SQL functions in Ecto.Query.API.fragment/1
so analytical queries can stay in Ecto's query DSL instead of scattering raw
fragment strings across application code.
import Ecto.Query
import QuackDB.Ecto.Analytics
from(event in "events",
group_by: event.category,
select: %{
category: event.category,
median_score: median(event.score),
p95_score: quantile_cont(event.score, 0.95),
scores: list(event.score)
}
)Helpers only build expressions. DuckDB clauses that are not representable in
Ecto's AST, such as PIVOT, UNPIVOT, QUALIFY, and GROUPING SETS,
should still be sent as raw SQL.
Summary
Functions
Builds json_insert(json, path, value), which only adds a missing value.
Builds json_remove(json, path).
Builds json_replace(json, path, value), which only changes an existing value.
Builds DuckDB 2.0's json_set(json, path, value), which creates or
replaces the value at path. The value is converted with to_json, so
Elixir strings set JSON strings. Paths are JSON path strings or lists such
as [:address, :city].
Runs DuckDB SUMMARIZE for an Ecto queryable using the :all query operation.
Runs DuckDB SUMMARIZE for an Ecto queryable using the given Ecto SQL operation.
Runs DuckDB SUMMARIZE for an Ecto queryable and raises on error.
Runs DuckDB SUMMARIZE for an Ecto queryable using the given Ecto SQL operation and raises on error.
Reads a DuckDB variable set with SET VARIABLE, using DuckDB 2.0's
$name shorthand. Pass a pinned value to read a variable named at runtime
through getvariable/1.
Functions
Builds json_insert(json, path, value), which only adds a missing value.
Builds json_remove(json, path).
Builds json_replace(json, path, value), which only changes an existing value.
Builds DuckDB 2.0's json_set(json, path, value), which creates or
replaces the value at path. The value is converted with to_json, so
Elixir strings set JSON strings. Paths are JSON path strings or lists such
as [:address, :city].
Runs DuckDB SUMMARIZE for an Ecto queryable using the :all query operation.
Runs DuckDB SUMMARIZE for an Ecto queryable using the given Ecto SQL operation.
Runs DuckDB SUMMARIZE for an Ecto queryable and raises on error.
Runs DuckDB SUMMARIZE for an Ecto queryable using the given Ecto SQL operation and raises on error.
Reads a DuckDB variable set with SET VARIABLE, using DuckDB 2.0's
$name shorthand. Pass a pinned value to read a variable named at runtime
through getvariable/1.