timsaucer commented on code in PR #859:
URL: https://github.com/apache/datafusion-python/pull/859#discussion_r1750666740
##########
src/functions.rs:
##########
@@ -35,305 +35,30 @@ use datafusion::functions_aggregate;
use datafusion::logical_expr::expr::Alias;
use datafusion::logical_expr::sqlparser::ast::NullTreatment as DFNullTreatment;
use datafusion::logical_expr::{
- expr::{find_df_window_func, AggregateFunction, Sort, WindowFunction},
+ expr::{find_df_window_func, Sort, WindowFunction},
lit, Expr, WindowFunctionDefinition,
};
-#[pyfunction]
-pub fn approx_distinct(expression: PyExpr) -> PyExpr {
- functions_aggregate::expr_fn::approx_distinct(expression.expr).into()
-}
-
-#[pyfunction]
-pub fn approx_median(expression: PyExpr, distinct: bool) -> PyResult<PyExpr> {
- let expr = functions_aggregate::expr_fn::approx_median(expression.expr);
- if distinct {
- Ok(expr.distinct().build()?.into())
- } else {
- Ok(expr.into())
- }
-}
-
-#[pyfunction]
-pub fn approx_percentile_cont(
- expression: PyExpr,
- percentile: PyExpr,
- distinct: bool,
- num_centroids: Option<PyExpr>, // enforces optional arguments at the end,
currently
-) -> PyResult<PyExpr> {
- let args = if let Some(num_centroids) = num_centroids {
- vec![expression.expr, percentile.expr, num_centroids.expr]
- } else {
- vec![expression.expr, percentile.expr]
- };
- let udaf =
functions_aggregate::approx_percentile_cont::approx_percentile_cont_udaf();
- let expr = udaf.call(args);
- if distinct {
- Ok(expr.distinct().build()?.into())
- } else {
- Ok(expr.into())
- }
-}
-
-#[pyfunction]
-pub fn approx_percentile_cont_with_weight(
- expression: PyExpr,
- weight: PyExpr,
- percentile: PyExpr,
- distinct: bool,
-) -> PyResult<PyExpr> {
- let expr =
functions_aggregate::expr_fn::approx_percentile_cont_with_weight(
- expression.expr,
- weight.expr,
- percentile.expr,
- );
- if distinct {
- Ok(expr.distinct().build()?.into())
- } else {
- Ok(expr.into())
- }
-}
-
-#[pyfunction]
-pub fn avg(expression: PyExpr, distinct: bool) -> PyResult<PyExpr> {
- let expr = functions_aggregate::expr_fn::avg(expression.expr);
- if distinct {
- Ok(expr.distinct().build()?.into())
- } else {
- Ok(expr.into())
- }
-}
-
-#[pyfunction]
-pub fn bit_and(expr_x: PyExpr, distinct: bool) -> PyResult<PyExpr> {
- let expr = functions_aggregate::expr_fn::bit_and(expr_x.expr);
- if distinct {
- Ok(expr.distinct().build()?.into())
- } else {
- Ok(expr.into())
- }
-}
-
-#[pyfunction]
-pub fn bit_or(expression: PyExpr, distinct: bool) -> PyResult<PyExpr> {
- let expr = functions_aggregate::expr_fn::bit_or(expression.expr);
- if distinct {
- Ok(expr.distinct().build()?.into())
- } else {
- Ok(expr.into())
- }
-}
-
-#[pyfunction]
-pub fn bit_xor(expression: PyExpr, distinct: bool) -> PyResult<PyExpr> {
- let expr = functions_aggregate::expr_fn::bit_xor(expression.expr);
- if distinct {
- Ok(expr.distinct().build()?.into())
- } else {
- Ok(expr.into())
- }
-}
-
-#[pyfunction]
-pub fn bool_and(expression: PyExpr, distinct: bool) -> PyResult<PyExpr> {
- let expr = functions_aggregate::expr_fn::bool_and(expression.expr);
- if distinct {
- Ok(expr.distinct().build()?.into())
- } else {
- Ok(expr.into())
- }
-}
-
-#[pyfunction]
-pub fn bool_or(expression: PyExpr, distinct: bool) -> PyResult<PyExpr> {
- let expr = functions_aggregate::expr_fn::bool_or(expression.expr);
- if distinct {
- Ok(expr.distinct().build()?.into())
- } else {
- Ok(expr.into())
- }
-}
-
-#[pyfunction]
-pub fn corr(y: PyExpr, x: PyExpr, distinct: bool) -> PyResult<PyExpr> {
- let expr = functions_aggregate::expr_fn::corr(y.expr, x.expr);
- if distinct {
- Ok(expr.distinct().build()?.into())
- } else {
- Ok(expr.into())
- }
-}
-
-#[pyfunction]
-pub fn grouping(expression: PyExpr, distinct: bool) -> PyResult<PyExpr> {
- let expr = functions_aggregate::expr_fn::grouping(expression.expr);
- if distinct {
- Ok(expr.distinct().build()?.into())
- } else {
- Ok(expr.into())
- }
-}
-
-#[pyfunction]
-pub fn sum(args: PyExpr) -> PyExpr {
- functions_aggregate::expr_fn::sum(args.expr).into()
-}
-
-#[pyfunction]
-pub fn covar_samp(y: PyExpr, x: PyExpr) -> PyExpr {
- functions_aggregate::expr_fn::covar_samp(y.expr, x.expr).into()
-}
-
-#[pyfunction]
-pub fn covar_pop(y: PyExpr, x: PyExpr) -> PyExpr {
- functions_aggregate::expr_fn::covar_pop(y.expr, x.expr).into()
-}
-
-#[pyfunction]
-pub fn median(arg: PyExpr) -> PyExpr {
- functions_aggregate::expr_fn::median(arg.expr).into()
-}
-
-#[pyfunction]
-pub fn stddev(expression: PyExpr, distinct: bool) -> PyResult<PyExpr> {
- 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<PyExpr> {
- 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()
-}
-
-#[pyfunction]
-pub fn var_pop(expression: PyExpr, distinct: bool) -> PyResult<PyExpr> {
- let expr = functions_aggregate::expr_fn::var_pop(expression.expr);
- if distinct {
- Ok(expr.distinct().build()?.into())
- } else {
- Ok(expr.into())
- }
-}
-
-#[pyfunction]
-pub fn regr_avgx(expr_y: PyExpr, expr_x: PyExpr, distinct: bool) ->
PyResult<PyExpr> {
- let expr = functions_aggregate::expr_fn::regr_avgx(expr_y.expr,
expr_x.expr);
- if distinct {
- Ok(expr.distinct().build()?.into())
- } else {
- Ok(expr.into())
- }
-}
-
-#[pyfunction]
-pub fn regr_avgy(expr_y: PyExpr, expr_x: PyExpr, distinct: bool) ->
PyResult<PyExpr> {
- let expr = functions_aggregate::expr_fn::regr_avgy(expr_y.expr,
expr_x.expr);
- if distinct {
- Ok(expr.distinct().build()?.into())
- } else {
- Ok(expr.into())
- }
-}
-
-#[pyfunction]
-pub fn regr_count(expr_y: PyExpr, expr_x: PyExpr, distinct: bool) ->
PyResult<PyExpr> {
- let expr = functions_aggregate::expr_fn::regr_count(expr_y.expr,
expr_x.expr);
- if distinct {
- Ok(expr.distinct().build()?.into())
- } else {
- Ok(expr.into())
- }
-}
-
-#[pyfunction]
-pub fn regr_intercept(expr_y: PyExpr, expr_x: PyExpr, distinct: bool) ->
PyResult<PyExpr> {
- let expr = functions_aggregate::expr_fn::regr_intercept(expr_y.expr,
expr_x.expr);
- if distinct {
- Ok(expr.distinct().build()?.into())
- } else {
- Ok(expr.into())
- }
-}
-
-#[pyfunction]
-pub fn regr_r2(expr_y: PyExpr, expr_x: PyExpr, distinct: bool) ->
PyResult<PyExpr> {
- let expr = functions_aggregate::expr_fn::regr_r2(expr_y.expr, expr_x.expr);
- if distinct {
- Ok(expr.distinct().build()?.into())
- } else {
- Ok(expr.into())
- }
-}
-
-#[pyfunction]
-pub fn regr_slope(expr_y: PyExpr, expr_x: PyExpr, distinct: bool) ->
PyResult<PyExpr> {
- let expr = functions_aggregate::expr_fn::regr_slope(expr_y.expr,
expr_x.expr);
- if distinct {
- Ok(expr.distinct().build()?.into())
- } else {
- Ok(expr.into())
- }
-}
-
-#[pyfunction]
-pub fn regr_sxx(expr_y: PyExpr, expr_x: PyExpr, distinct: bool) ->
PyResult<PyExpr> {
- let expr = functions_aggregate::expr_fn::regr_sxx(expr_y.expr,
expr_x.expr);
- if distinct {
- Ok(expr.distinct().build()?.into())
- } else {
- Ok(expr.into())
- }
-}
-
-#[pyfunction]
-pub fn regr_sxy(expr_y: PyExpr, expr_x: PyExpr, distinct: bool) ->
PyResult<PyExpr> {
- let expr = functions_aggregate::expr_fn::regr_sxy(expr_y.expr,
expr_x.expr);
- if distinct {
- Ok(expr.distinct().build()?.into())
- } else {
- Ok(expr.into())
- }
-}
-
-#[pyfunction]
-pub fn regr_syy(expr_y: PyExpr, expr_x: PyExpr, distinct: bool) ->
PyResult<PyExpr> {
- let expr = functions_aggregate::expr_fn::regr_syy(expr_y.expr,
expr_x.expr);
- if distinct {
- Ok(expr.distinct().build()?.into())
- } else {
- Ok(expr.into())
- }
-}
-
fn add_builder_fns_to_aggregate(
agg_fn: Expr,
- distinct: bool,
+ distinct: Option<bool>,
filter: Option<PyExpr>,
order_by: Option<Vec<PyExpr>>,
null_treatment: Option<NullTreatment>,
) -> PyResult<PyExpr> {
// Since ExprFuncBuilder::new() is private, we can guarantee initializing
// a builder with an `order_by` default of empty vec
- let order_by = order_by
- .map(|x| x.into_iter().map(|x| x.expr).collect::<Vec<_>>())
- .unwrap_or_default();
- let mut builder = agg_fn.order_by(order_by);
+ // let order_by = order_by
Review Comment:
Good catch! Removed
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]