diff --git a/datafusion/sql/src/expr/function.rs b/datafusion/sql/src/expr/function.rs index cdf61183eb3d..1fa190c6c9ee 100644 --- a/datafusion/sql/src/expr/function.rs +++ b/datafusion/sql/src/expr/function.rs @@ -349,6 +349,12 @@ impl SqlToRel<'_, S> { } 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.context_provider.get_aggregate_meta(&name) { + // Reject RESPECT NULLS and IGNORE NULLS for aggregate functions + // See https://github.com/apache/datafusion/issues/15006 + if null_treatment.is_some() { + return plan_err!("RESPECT NULLS and IGNORE NULLS are not supported for aggregate functions"); + } + let order_by = self.order_by_to_sort_expr( order_by, schema, @@ -369,7 +375,7 @@ impl SqlToRel<'_, S> { distinct, filter, order_by, - null_treatment, + null_treatment: None, // See https://github.com/apache/datafusion/issues/15006 }; for planner in self.context_provider.get_expr_planners().iter() { match planner.plan_aggregate(aggregate_expr)? { diff --git a/datafusion/sqllogictest/test_files/aggregate.slt b/datafusion/sqllogictest/test_files/aggregate.slt index bc43f6bc8e61..2450c88b1f8d 100644 --- a/datafusion/sqllogictest/test_files/aggregate.slt +++ b/datafusion/sqllogictest/test_files/aggregate.slt @@ -5863,15 +5863,11 @@ SELECT FIRST_VALUE(column1) FROM t; ---- NULL -query I +query error DataFusion error: Error during planning: RESPECT NULLS and IGNORE NULLS are not supported for aggregate functions SELECT FIRST_VALUE(column1) RESPECT NULLS FROM t; ----- -NULL -query I +query error DataFusion error: Error during planning: RESPECT NULLS and IGNORE NULLS are not supported for aggregate functions SELECT FIRST_VALUE(column1) IGNORE NULLS FROM t; ----- -3 statement ok DROP TABLE t; @@ -5893,15 +5889,11 @@ SELECT FIRST_VALUE(column1 ORDER BY column2) FROM t; ---- NULL -query I +query error DataFusion error: Error during planning: RESPECT NULLS and IGNORE NULLS are not supported for aggregate functions SELECT FIRST_VALUE(column1 ORDER BY column2) RESPECT NULLS FROM t; ----- -NULL -query I +query error DataFusion error: Error during planning: RESPECT NULLS and IGNORE NULLS are not supported for aggregate functions SELECT FIRST_VALUE(column1 ORDER BY column2) IGNORE NULLS FROM t; ----- -4 statement ok DROP TABLE t; @@ -5915,15 +5907,11 @@ SELECT LAST_VALUE(column1) FROM t; ---- NULL -query I +query error DataFusion error: Error during planning: RESPECT NULLS and IGNORE NULLS are not supported for aggregate functions SELECT LAST_VALUE(column1) RESPECT NULLS FROM t; ----- -NULL -query I +query error DataFusion error: Error during planning: RESPECT NULLS and IGNORE NULLS are not supported for aggregate functions SELECT LAST_VALUE(column1) IGNORE NULLS FROM t; ----- -4 statement ok DROP TABLE t; @@ -5945,15 +5933,11 @@ SELECT LAST_VALUE(column1 ORDER BY column2 DESC) FROM t; ---- NULL -query I +query error DataFusion error: Error during planning: RESPECT NULLS and IGNORE NULLS are not supported for aggregate functions SELECT LAST_VALUE(column1 ORDER BY column2 DESC) RESPECT NULLS FROM t; ----- -NULL -query I +query error DataFusion error: Error during planning: RESPECT NULLS and IGNORE NULLS are not supported for aggregate functions SELECT LAST_VALUE(column1 ORDER BY column2 DESC) IGNORE NULLS FROM t; ----- -3 statement ok DROP TABLE t;