From 13c8237564a06070b0f8f32ac19a90b054b01417 Mon Sep 17 00:00:00 2001 From: Andrew Lamb Date: Wed, 8 Oct 2025 15:51:32 -0400 Subject: [PATCH 1/2] Clarify documentation that ScalarUDFImpl::simplity must not change the schema --- datafusion/expr/src/udf.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/datafusion/expr/src/udf.rs b/datafusion/expr/src/udf.rs index bc9e62fe6211..d522158f7b6b 100644 --- a/datafusion/expr/src/udf.rs +++ b/datafusion/expr/src/udf.rs @@ -635,6 +635,14 @@ pub trait ScalarUDFImpl: Debug + DynEq + DynHash + Send + Sync { /// [`ExprSimplifyResult`] indicating the result of the simplification NOTE /// if the function cannot be simplified, the arguments *MUST* be returned /// unmodified + /// + /// # Notes + /// + /// The returned expression must have the same schema as the original + /// expression, including both the data type and nullability. For example, + /// if the original expression is nullable, the returned expression must + /// also be nullable, otherwise it may lead to schema verification errors + /// later in query planning. fn simplify( &self, args: Vec, From ce7bc3fc1170369919aa7f4f9b0d6c7e9c584f93 Mon Sep 17 00:00:00 2001 From: Andrew Lamb Date: Thu, 9 Oct 2025 14:48:47 -0400 Subject: [PATCH 2/2] Add comments to AggregateUDFImpl and WindowUDFImpl --- datafusion/expr/src/udaf.rs | 7 +++++++ datafusion/expr/src/udwf.rs | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/datafusion/expr/src/udaf.rs b/datafusion/expr/src/udaf.rs index fa71a76c09c7..bfd699d81485 100644 --- a/datafusion/expr/src/udaf.rs +++ b/datafusion/expr/src/udaf.rs @@ -671,6 +671,13 @@ pub trait AggregateUDFImpl: Debug + DynEq + DynHash + Send + Sync { /// /// closure returns simplified [Expr] or an error. /// + /// # Notes + /// + /// The returned expression must have the same schema as the original + /// expression, including both the data type and nullability. For example, + /// if the original expression is nullable, the returned expression must + /// also be nullable, otherwise it may lead to schema verification errors + /// later in query planning. fn simplify(&self) -> Option { None } diff --git a/datafusion/expr/src/udwf.rs b/datafusion/expr/src/udwf.rs index 402add0391e1..abe3df637589 100644 --- a/datafusion/expr/src/udwf.rs +++ b/datafusion/expr/src/udwf.rs @@ -358,6 +358,13 @@ pub trait WindowUDFImpl: Debug + DynEq + DynHash + Send + Sync { /// Or, a closure with two arguments: /// * 'window_function': [crate::expr::WindowFunction] for which simplified has been invoked /// * 'info': [crate::simplify::SimplifyInfo] + /// + /// # Notes + /// The returned expression must have the same schema as the original + /// expression, including both the data type and nullability. For example, + /// if the original expression is nullable, the returned expression must + /// also be nullable, otherwise it may lead to schema verification errors + /// later in query planning. fn simplify(&self) -> Option { None }