@@ -37,6 +37,57 @@ use datafusion_expr::{
3737 lit, Expr , WindowFunctionDefinition ,
3838} ;
3939
40+ #[ pyfunction]
41+ pub fn approx_distinct ( expression : PyExpr ) -> PyExpr {
42+ functions_aggregate:: expr_fn:: approx_distinct:: approx_distinct ( expression. expr ) . into ( )
43+ }
44+
45+ #[ pyfunction]
46+ pub fn approx_median ( expression : PyExpr , distinct : bool ) -> PyResult < PyExpr > {
47+ // TODO: better builder pattern
48+ let expr = functions_aggregate:: expr_fn:: approx_median ( expression. expr ) ;
49+ if distinct {
50+ Ok ( expr. distinct ( ) . build ( ) ?. into ( ) )
51+ } else {
52+ Ok ( expr. into ( ) )
53+ }
54+ }
55+
56+ #[ pyfunction]
57+ pub fn approx_percentile_cont (
58+ expression : PyExpr ,
59+ percentile : PyExpr ,
60+ distinct : bool ,
61+ ) -> PyResult < PyExpr > {
62+ // TODO: better builder pattern
63+ let expr =
64+ functions_aggregate:: expr_fn:: approx_percentile_cont ( expression. expr , percentile. expr ) ;
65+ if distinct {
66+ Ok ( expr. distinct ( ) . build ( ) ?. into ( ) )
67+ } else {
68+ Ok ( expr. into ( ) )
69+ }
70+ }
71+
72+ #[ pyfunction]
73+ pub fn approx_percentile_cont_with_weight (
74+ expression : PyExpr ,
75+ weight : PyExpr ,
76+ percentile : PyExpr ,
77+ distinct : bool ,
78+ ) -> PyResult < PyExpr > {
79+ let expr = functions_aggregate:: expr_fn:: approx_percentile_cont_with_weight (
80+ expression. expr ,
81+ weight. expr ,
82+ percentile. expr ,
83+ ) ;
84+ if distinct {
85+ Ok ( expr. distinct ( ) . build ( ) ?. into ( ) )
86+ } else {
87+ Ok ( expr. into ( ) )
88+ }
89+ }
90+
4091#[ pyfunction]
4192pub fn sum ( args : PyExpr ) -> PyExpr {
4293 functions_aggregate:: expr_fn:: sum ( args. expr ) . into ( )
@@ -727,13 +778,6 @@ array_fn!(list_resize, array_resize, array size value);
727778array_fn ! ( flatten, array) ;
728779array_fn ! ( range, start stop step) ;
729780
730- aggregate_function ! ( approx_distinct, ApproxDistinct ) ;
731- aggregate_function ! ( approx_median, ApproxMedian ) ;
732- aggregate_function ! ( approx_percentile_cont, ApproxPercentileCont ) ;
733- aggregate_function ! (
734- approx_percentile_cont_with_weight,
735- ApproxPercentileContWithWeight
736- ) ;
737781aggregate_function ! ( array_agg, ArrayAgg ) ;
738782aggregate_function ! ( avg, Avg ) ;
739783aggregate_function ! ( corr, Correlation ) ;
0 commit comments