diff --git a/datafusion/expr/src/expr.rs b/datafusion/expr/src/expr.rs index 4eb1bc1f6ca76..34d710d3cead7 100644 --- a/datafusion/expr/src/expr.rs +++ b/datafusion/expr/src/expr.rs @@ -502,12 +502,6 @@ impl AggregateFunctionDefinition { AggregateFunctionDefinition::Name(func_name) => func_name.as_ref(), } } - - pub fn new_builtin( - fun: aggregate_function::AggregateFunction, - ) -> AggregateFunctionDefinition { - Self::BuiltIn(fun) - } } /// Aggregate function @@ -534,7 +528,7 @@ impl AggregateFunction { order_by: Option>, ) -> Self { Self { - func_def: AggregateFunctionDefinition::new_builtin(fun), + func_def: AggregateFunctionDefinition::BuiltIn(fun), args, distinct, filter, @@ -1611,7 +1605,7 @@ fn create_name(e: &Expr) -> Result { filter, order_by, }) => { - let mut name = match func_def { + let name = match func_def { AggregateFunctionDefinition::BuiltIn(..) | AggregateFunctionDefinition::Name(..) => { create_function_name(func_def.name(), *distinct, args)? @@ -1624,13 +1618,21 @@ fn create_name(e: &Expr) -> Result { names.join(",") } }; + let mut info = String::new(); if let Some(fe) = filter { - name = format!("{name} FILTER (WHERE {fe})"); + info += &format!(" FILTER (WHERE {fe})"); }; if let Some(order_by) = order_by { - name = format!("{name} ORDER BY [{}]", expr_vec_fmt!(order_by)); + info += &format!("{name} ORDER BY [{}]", expr_vec_fmt!(order_by)); }; - Ok(name) + + match func_def { + AggregateFunctionDefinition::BuiltIn(..) + | AggregateFunctionDefinition::Name(..) => Ok(name), + AggregateFunctionDefinition::UDF(..) => { + Ok(format!("{}({}){}", func_def.name(), name, info)) + } + } } Expr::GroupingSet(grouping_set) => match grouping_set { GroupingSet::Rollup(exprs) => {