Skip to content

Commit 37ad8a5

Browse files
authored
Clarify documentation that ScalarUDFImpl::simplity must not change the schema (#17981)
* Clarify documentation that ScalarUDFImpl::simplity must not change the schema * Add comments to AggregateUDFImpl and WindowUDFImpl
1 parent 0ffc433 commit 37ad8a5

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

datafusion/expr/src/udaf.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,13 @@ pub trait AggregateUDFImpl: Debug + DynEq + DynHash + Send + Sync {
671671
///
672672
/// closure returns simplified [Expr] or an error.
673673
///
674+
/// # Notes
675+
///
676+
/// The returned expression must have the same schema as the original
677+
/// expression, including both the data type and nullability. For example,
678+
/// if the original expression is nullable, the returned expression must
679+
/// also be nullable, otherwise it may lead to schema verification errors
680+
/// later in query planning.
674681
fn simplify(&self) -> Option<AggregateFunctionSimplification> {
675682
None
676683
}

datafusion/expr/src/udf.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,14 @@ pub trait ScalarUDFImpl: Debug + DynEq + DynHash + Send + Sync {
635635
/// [`ExprSimplifyResult`] indicating the result of the simplification NOTE
636636
/// if the function cannot be simplified, the arguments *MUST* be returned
637637
/// unmodified
638+
///
639+
/// # Notes
640+
///
641+
/// The returned expression must have the same schema as the original
642+
/// expression, including both the data type and nullability. For example,
643+
/// if the original expression is nullable, the returned expression must
644+
/// also be nullable, otherwise it may lead to schema verification errors
645+
/// later in query planning.
638646
fn simplify(
639647
&self,
640648
args: Vec<Expr>,

datafusion/expr/src/udwf.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,13 @@ pub trait WindowUDFImpl: Debug + DynEq + DynHash + Send + Sync {
358358
/// Or, a closure with two arguments:
359359
/// * 'window_function': [crate::expr::WindowFunction] for which simplified has been invoked
360360
/// * 'info': [crate::simplify::SimplifyInfo]
361+
///
362+
/// # Notes
363+
/// The returned expression must have the same schema as the original
364+
/// expression, including both the data type and nullability. For example,
365+
/// if the original expression is nullable, the returned expression must
366+
/// also be nullable, otherwise it may lead to schema verification errors
367+
/// later in query planning.
361368
fn simplify(&self) -> Option<WindowFunctionSimplification> {
362369
None
363370
}

0 commit comments

Comments
 (0)