纯 SQL 统计
511 个函数背后是 Rust statrs 库,直接在 DuckDB 查询里调用。统计量用聚合,分布与特殊函数用标量逐行求值。
DuckDB SQL
-- Install once, then LOAD in every session:
INSTALL duckfn_statrs FROM community;
LOAD duckfn_statrs;
-- Aggregates: one column in, one value out per group:
SELECT g, sr_mean(x) AS mean, sr_std_dev(x) AS sd
FROM my_table GROUP BY g;
-- Scalars: distribution functions evaluated row by row:
SELECT sr_normal_pdf(0.0, 0.0, 1.0); -- 0.3989...
SELECT sr_gamma_cdf(2.0, 3.0, 2.0); -- 0.4564...
-- NULL semantics: statrs cannot define it → SQL NULL
SELECT sr_variance(x) FROM (VALUES (1.0)) t(x); -- NULL (single value)