Skip to content

Apache DataFusion SQL Query Engine

functions: Remove NullHandling from scalar funcs (#14531)

Joseph Koshakow2aad9d2d91f6
diff --git a/datafusion/expr/src/lib.rs b/datafusion/expr/src/lib.rs
index 46c0f5a3dd..aaa65c676a 100644
--- a/datafusion/expr/src/lib.rs
+++ b/datafusion/expr/src/lib.rs
@@ -95,8 +95,8 @@ pub use udaf::{
SetMonotonicity, StatisticsArgs,
};
pub use udf::{
- scalar_doc_sections, NullHandling, ReturnInfo, ReturnTypeArgs, ScalarFunctionArgs,
- ScalarUDF, ScalarUDFImpl,
+ scalar_doc_sections, ReturnInfo, ReturnTypeArgs, ScalarFunctionArgs, ScalarUDF,
+ ScalarUDFImpl,
};
pub use udwf::{window_doc_sections, ReversedUDWF, WindowUDF, WindowUDFImpl};
pub use window_frame::{WindowFrame, WindowFrameBound, WindowFrameUnits};
diff --git a/datafusion/expr/src/udf.rs b/datafusion/expr/src/udf.rs
index 7c91b6b3b4..aa6a5cddad 100644
--- a/datafusion/expr/src/udf.rs
+++ b/datafusion/expr/src/udf.rs
@@ -200,11 +200,6 @@ impl ScalarUDF {
self.inner.return_type_from_args(args)
}
- /// Returns the behavior that this function has when any of the inputs are Null.
- pub fn null_handling(&self) -> NullHandling {
- self.inner.null_handling()
- }
-
/// Do the function rewrite
///
/// See [`ScalarUDFImpl::simplify`] for more details.
@@ -422,15 +417,6 @@ impl ReturnInfo {
}
}
-/// A function's behavior when the input is Null.
-#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Hash)]
-pub enum NullHandling {
- /// Null inputs are passed into the function implementation.
- PassThrough,
- /// Any Null input causes the function to return Null.
- Propagate,
-}
-
/// Trait for implementing user defined scalar functions.
///
/// This trait exposes the full API for implementing user defined functions and
@@ -603,11 +589,6 @@ pub trait ScalarUDFImpl: Debug + Send + Sync {
true
}
- /// Returns the behavior that this function has when any of the inputs are Null.
- fn null_handling(&self) -> NullHandling {
- NullHandling::PassThrough
- }
-
/// Invoke the function on `args`, returning the appropriate result
///
/// Note: This method is deprecated and will be removed in future releases.
diff --git a/datafusion/functions-nested/src/extract.rs b/datafusion/functions-nested/src/extract.rs
index b472316d03..33f7904c16 100644
--- a/datafusion/functions-nested/src/extract.rs
+++ b/datafusion/functions-nested/src/extract.rs
@@ -33,7 +33,7 @@ use datafusion_common::{
};
use datafusion_expr::{ArrayFunctionSignature, Expr, TypeSignature};
use datafusion_expr::{
- ColumnarValue, Documentation, NullHandling, ScalarUDFImpl, Signature, Volatility,
+ ColumnarValue, Documentation, ScalarUDFImpl, Signature, Volatility,
};
use datafusion_macros::user_doc;
use std::any::Any;
@@ -385,10 +385,6 @@ impl ScalarUDFImpl for ArraySlice {
Ok(arg_types[0].clone())
}
- fn null_handling(&self) -> NullHandling {
- NullHandling::Propagate
- }
-
fn invoke_batch(
&self,
args: &[ColumnarValue],
@@ -690,10 +686,6 @@ impl ScalarUDFImpl for ArrayPopFront {
Ok(arg_types[0].clone())
}
- fn null_handling(&self) -> NullHandling {
- NullHandling::Propagate
- }
-
fn invoke_batch(
&self,
args: &[ColumnarValue],
@@ -794,10 +786,6 @@ impl ScalarUDFImpl for ArrayPopBack {
Ok(arg_types[0].clone())
}
- fn null_handling(&self) -> NullHandling {
- NullHandling::Propagate
- }
-
fn invoke_batch(
&self,
args: &[ColumnarValue],
diff --git a/datafusion/physical-expr/src/scalar_function.rs b/datafusion/physical-expr/src/scalar_function.rs
index 1cd4b673ce..936adbc098 100644
--- a/datafusion/physical-expr/src/scalar_function.rs
+++ b/datafusion/physical-expr/src/scalar_function.rs
@@ -45,8 +45,7 @@ use datafusion_expr::interval_arithmetic::Interval;
use datafusion_expr::sort_properties::ExprProperties;
use datafusion_expr::type_coercion::functions::data_types_with_scalar_udf;
use datafusion_expr::{
- expr_vec_fmt, ColumnarValue, Expr, NullHandling, ReturnTypeArgs, ScalarFunctionArgs,
- ScalarUDF,
+ expr_vec_fmt, ColumnarValue, Expr, ReturnTypeArgs, ScalarFunctionArgs, ScalarUDF,
};
/// Physical expression of a scalar function
@@ -187,15 +186,6 @@ impl PhysicalExpr for ScalarFunctionExpr {
.map(|e| e.evaluate(batch))
.collect::<Result<Vec<_>>>()?;
- if self.fun.null_handling() == NullHandling::Propagate
- && args.iter().any(
- |arg| matches!(arg, ColumnarValue::Scalar(scalar) if scalar.is_null()),
- )
- {
- let null_value = ScalarValue::try_from(&self.return_type)?;
- return Ok(ColumnarValue::Scalar(null_value));
- }
-
let input_empty = args.is_empty();
let input_all_scalar = args
.iter()