Skip to content

Commit

Permalink
minor: revert parsing precedence between Aggr and UDAF
Browse files Browse the repository at this point in the history
Signed-off-by: Ruihang Xia <[email protected]>
  • Loading branch information
waynexia committed Sep 28, 2023
1 parent 32dfbb0 commit 8a73718
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions datafusion/sql/src/expr/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,15 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
return Ok(expr);
}
} else {
// User defined aggregate functions (UDAF) have precedence in case it has the same name as a scalar built-in function
if let Some(fm) = self.schema_provider.get_aggregate_meta(&name) {
let args =
self.function_args_to_expr(function.args, schema, planner_context)?;
return Ok(Expr::AggregateUDF(expr::AggregateUDF::new(
fm, args, None, None,
)));
}

// next, aggregate built-ins
if let Ok(fun) = AggregateFunction::from_str(&name) {
let distinct = function.distinct;
Expand All @@ -141,15 +150,6 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
)));
};

// User defined aggregate functions (UDAF)
if let Some(fm) = self.schema_provider.get_aggregate_meta(&name) {
let args =
self.function_args_to_expr(function.args, schema, planner_context)?;
return Ok(Expr::AggregateUDF(expr::AggregateUDF::new(
fm, args, None, None,
)));
}

// Special case arrow_cast (as its type is dependent on its argument value)
if name == ARROW_CAST_NAME {
let args =
Expand Down

0 comments on commit 8a73718

Please sign in to comment.