Skip to content

Commit 2cd6853

Browse files
migrate avg to UDAF
Ref: apache/datafusion#10964
1 parent 7d215ad commit 2cd6853

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/functions.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,16 @@ pub fn approx_percentile_cont_with_weight(
8888
}
8989
}
9090

91+
#[pyfunction]
92+
pub fn avg(expression: PyExpr, distinct: bool) -> PyResult<PyExpr> {
93+
let expr = functions_aggregate::expr_fn::avg(expression.expr);
94+
if distinct {
95+
Ok(expr.distinct().build()?.into())
96+
} else {
97+
Ok(expr.into())
98+
}
99+
}
100+
91101
#[pyfunction]
92102
pub fn sum(args: PyExpr) -> PyExpr {
93103
functions_aggregate::expr_fn::sum(args.expr).into()
@@ -779,7 +789,6 @@ array_fn!(flatten, array);
779789
array_fn!(range, start stop step);
780790

781791
aggregate_function!(array_agg, ArrayAgg);
782-
aggregate_function!(avg, Avg);
783792
aggregate_function!(corr, Correlation);
784793
aggregate_function!(grouping, Grouping);
785794
aggregate_function!(max, Max);

0 commit comments

Comments
 (0)