@@ -37,6 +37,57 @@ use datafusion_expr::{
37
37
lit, Expr , WindowFunctionDefinition ,
38
38
} ;
39
39
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
+
40
91
#[ pyfunction]
41
92
pub fn sum ( args : PyExpr ) -> PyExpr {
42
93
functions_aggregate:: expr_fn:: sum ( args. expr ) . into ( )
@@ -727,13 +778,6 @@ array_fn!(list_resize, array_resize, array size value);
727
778
array_fn ! ( flatten, array) ;
728
779
array_fn ! ( range, start stop step) ;
729
780
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
- ) ;
737
781
aggregate_function ! ( array_agg, ArrayAgg ) ;
738
782
aggregate_function ! ( avg, Avg ) ;
739
783
aggregate_function ! ( corr, Correlation ) ;
0 commit comments