From e17342cc6801f341eba8ee8262785c21dd0a9c2a Mon Sep 17 00:00:00 2001 From: Andy Grove Date: Tue, 10 Dec 2024 08:55:26 -0700 Subject: [PATCH] Deprecate ScalarUDFImpl::return_type and revert a breaking API change --- datafusion/expr/src/udf.rs | 4 ++++ datafusion/functions/src/datetime/date_part.rs | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/datafusion/expr/src/udf.rs b/datafusion/expr/src/udf.rs index 809c78f30eff..238bc3bcbeca 100644 --- a/datafusion/expr/src/udf.rs +++ b/datafusion/expr/src/udf.rs @@ -174,6 +174,7 @@ impl ScalarUDF { /// /// See [`ScalarUDFImpl::return_type`] for more details. pub fn return_type(&self, arg_types: &[DataType]) -> Result { + #[allow(deprecated)] self.inner.return_type(arg_types) } @@ -450,6 +451,7 @@ pub trait ScalarUDFImpl: Debug + Send + Sync { /// is recommended to return [`DataFusionError::Internal`]. /// /// [`DataFusionError::Internal`]: datafusion_common::DataFusionError::Internal + #[deprecated(since = "44.0.0", note = "Use `return_type_from_exprs` instead")] fn return_type(&self, arg_types: &[DataType]) -> Result; /// What [`DataType`] will be returned by this function, given the @@ -483,6 +485,7 @@ pub trait ScalarUDFImpl: Debug + Send + Sync { _schema: &dyn ExprSchema, arg_types: &[DataType], ) -> Result { + #[allow(deprecated)] self.return_type(arg_types) } @@ -756,6 +759,7 @@ impl ScalarUDFImpl for AliasedScalarUDFImpl { } fn return_type(&self, arg_types: &[DataType]) -> Result { + #[allow(deprecated)] self.inner.return_type(arg_types) } diff --git a/datafusion/functions/src/datetime/date_part.rs b/datafusion/functions/src/datetime/date_part.rs index b8c58a11d999..03387d58b44d 100644 --- a/datafusion/functions/src/datetime/date_part.rs +++ b/datafusion/functions/src/datetime/date_part.rs @@ -148,7 +148,9 @@ impl ScalarUDFImpl for DatePartFunc { } fn return_type(&self, _arg_types: &[DataType]) -> Result { - internal_err!("return_type_from_exprs shoud be called instead") + // return type could be Float32 or Int32 depending on the input arguments + // return_type_from_exprs should be called instead + Ok(DataType::Float64) } fn return_type_from_exprs(