From c08a35d7b64fa71108dab4696b570ac240fb7f34 Mon Sep 17 00:00:00 2001 From: Michael-J-Ward Date: Wed, 24 Jul 2024 13:14:20 -0500 Subject: [PATCH] migrate stddev to UDAF Ref: https://github.com/apache/datafusion/issues/10827 --- src/functions.rs | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/functions.rs b/src/functions.rs index 6d719da1..6009d266 100644 --- a/src/functions.rs +++ b/src/functions.rs @@ -149,6 +149,26 @@ pub fn covar(y: PyExpr, x: PyExpr) -> PyExpr { covar_samp(y, x) } +#[pyfunction] +pub fn stddev(expression: PyExpr, distinct: bool) -> PyResult { + let expr = functions_aggregate::expr_fn::stddev(expression.expr); + if distinct { + Ok(expr.distinct().build()?.into()) + } else { + Ok(expr.into()) + } +} + +#[pyfunction] +pub fn stddev_pop(expression: PyExpr, distinct: bool) -> PyResult { + let expr = functions_aggregate::expr_fn::stddev_pop(expression.expr); + if distinct { + Ok(expr.distinct().build()?.into()) + } else { + Ok(expr.into()) + } +} + #[pyfunction] pub fn var_samp(expression: PyExpr) -> PyExpr { functions_aggregate::expr_fn::var_sample(expression.expr).into() @@ -787,8 +807,6 @@ array_fn!(range, start stop step); aggregate_function!(array_agg, ArrayAgg); aggregate_function!(max, Max); aggregate_function!(min, Min); -aggregate_function!(stddev, Stddev); -aggregate_function!(stddev_pop, StddevPop); aggregate_function!(stddev_samp, Stddev); aggregate_function!(var_pop, VariancePop); aggregate_function!(regr_avgx, RegrAvgx);