This is an automated email from the ASF dual-hosted git repository.
jayzhan pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/datafusion.git
The following commit(s) were added to refs/heads/main by this push:
new bb1611578f chore: remove ScalarUDFImpl::return_type_from_exprs (#15130)
bb1611578f is described below
commit bb1611578f8af42aacf611cb580940964665702d
Author: Arttu <[email protected]>
AuthorDate: Wed Mar 12 12:47:20 2025 +0000
chore: remove ScalarUDFImpl::return_type_from_exprs (#15130)
* chore: remove ScalarUDFImpl::return_type_from_exprs
use `return_type_from_args` instead
* clippy
---
.../user_defined/user_defined_scalar_functions.rs | 2 +-
datafusion/expr/src/udf.rs | 40 ++--------------------
datafusion/functions-nested/src/extract.rs | 32 ++---------------
datafusion/functions/src/core/union_extract.rs | 4 +--
datafusion/physical-expr/src/lib.rs | 4 ---
datafusion/physical-expr/src/scalar_function.rs | 36 ++-----------------
datafusion/physical-plan/src/execution_plan.rs | 2 +-
datafusion/physical-plan/src/lib.rs | 2 +-
8 files changed, 11 insertions(+), 111 deletions(-)
diff --git
a/datafusion/core/tests/user_defined/user_defined_scalar_functions.rs
b/datafusion/core/tests/user_defined/user_defined_scalar_functions.rs
index 57bac9c6df..87694d83bb 100644
--- a/datafusion/core/tests/user_defined/user_defined_scalar_functions.rs
+++ b/datafusion/core/tests/user_defined/user_defined_scalar_functions.rs
@@ -795,7 +795,7 @@ impl ScalarUDFImpl for TakeUDF {
&self.signature
}
fn return_type(&self, _args: &[DataType]) -> Result<DataType> {
- not_impl_err!("Not called because the return_type_from_exprs is
implemented")
+ not_impl_err!("Not called because the return_type_from_args is
implemented")
}
/// This function returns the type of the first or second argument based on
diff --git a/datafusion/expr/src/udf.rs b/datafusion/expr/src/udf.rs
index d724209d9d..86bc5852b8 100644
--- a/datafusion/expr/src/udf.rs
+++ b/datafusion/expr/src/udf.rs
@@ -172,7 +172,7 @@ impl ScalarUDF {
///
/// # Notes
///
- /// If a function implement [`ScalarUDFImpl::return_type_from_exprs`],
+ /// If a function implement [`ScalarUDFImpl::return_type_from_args`],
/// its [`ScalarUDFImpl::return_type`] should raise an error.
///
/// See [`ScalarUDFImpl::return_type`] for more details.
@@ -180,22 +180,6 @@ impl ScalarUDF {
self.inner.return_type(arg_types)
}
- /// The datatype this function returns given the input argument input
types.
- /// This function is used when the input arguments are [`Expr`]s.
- ///
- ///
- /// See [`ScalarUDFImpl::return_type_from_exprs`] for more details.
- #[allow(deprecated)]
- pub fn return_type_from_exprs(
- &self,
- args: &[Expr],
- schema: &dyn ExprSchema,
- arg_types: &[DataType],
- ) -> Result<DataType> {
- // If the implementation provides a return_type_from_exprs, use it
- self.inner.return_type_from_exprs(args, schema, arg_types)
- }
-
/// Return the datatype this function returns given the input argument
types.
///
/// See [`ScalarUDFImpl::return_type_from_args`] for more details.
@@ -351,7 +335,7 @@ pub struct ScalarFunctionArgs<'a> {
pub args: Vec<ColumnarValue>,
/// The number of rows in record batch being evaluated
pub number_rows: usize,
- /// The return type of the scalar function returned (from `return_type` or
`return_type_from_exprs`)
+ /// The return type of the scalar function returned (from `return_type` or
`return_type_from_args`)
/// when creating the physical expression from the logical expression
pub return_type: &'a DataType,
}
@@ -540,16 +524,6 @@ pub trait ScalarUDFImpl: Debug + Send + Sync {
/// [`DataFusionError::Internal`]:
datafusion_common::DataFusionError::Internal
fn return_type(&self, arg_types: &[DataType]) -> Result<DataType>;
- #[deprecated(since = "45.0.0", note = "Use `return_type_from_args`
instead")]
- fn return_type_from_exprs(
- &self,
- _args: &[Expr],
- _schema: &dyn ExprSchema,
- arg_types: &[DataType],
- ) -> Result<DataType> {
- self.return_type(arg_types)
- }
-
/// What type will be returned by this function, given the arguments?
///
/// By default, this function calls [`Self::return_type`] with the
@@ -889,16 +863,6 @@ impl ScalarUDFImpl for AliasedScalarUDFImpl {
&self.aliases
}
- #[allow(deprecated)]
- fn return_type_from_exprs(
- &self,
- args: &[Expr],
- schema: &dyn ExprSchema,
- arg_types: &[DataType],
- ) -> Result<DataType> {
- self.inner.return_type_from_exprs(args, schema, arg_types)
- }
-
fn return_type_from_args(&self, args: ReturnTypeArgs) ->
Result<ReturnInfo> {
self.inner.return_type_from_args(args)
}
diff --git a/datafusion/functions-nested/src/extract.rs
b/datafusion/functions-nested/src/extract.rs
index 0f50f62dd8..321dda55ce 100644
--- a/datafusion/functions-nested/src/extract.rs
+++ b/datafusion/functions-nested/src/extract.rs
@@ -1001,9 +1001,9 @@ where
mod tests {
use super::array_element_udf;
use arrow::datatypes::{DataType, Field};
- use datafusion_common::{Column, DFSchema, ScalarValue};
+ use datafusion_common::{Column, DFSchema};
use datafusion_expr::expr::ScalarFunction;
- use datafusion_expr::{cast, Expr, ExprSchemable};
+ use datafusion_expr::{Expr, ExprSchemable};
use std::collections::HashMap;
// Regression test for https://github.com/apache/datafusion/issues/13755
@@ -1037,34 +1037,6 @@ mod tests {
fixed_size_list_type
);
- // ScalarUDFImpl::return_type_from_exprs with typed exprs
- assert_eq!(
- udf.return_type_from_exprs(
- &[
- cast(Expr::Literal(ScalarValue::Null), array_type.clone()),
- cast(Expr::Literal(ScalarValue::Null), index_type.clone()),
- ],
- &schema,
- &[array_type.clone(), index_type.clone()]
- )
- .unwrap(),
- fixed_size_list_type
- );
-
- // ScalarUDFImpl::return_type_from_exprs with exprs not carrying type
- assert_eq!(
- udf.return_type_from_exprs(
- &[
- Expr::Column(Column::new_unqualified("my_array")),
- Expr::Column(Column::new_unqualified("my_index")),
- ],
- &schema,
- &[array_type.clone(), index_type.clone()]
- )
- .unwrap(),
- fixed_size_list_type
- );
-
// Via ExprSchemable::get_type (e.g. SimplifyInfo)
let udf_expr = Expr::ScalarFunction(ScalarFunction {
func: array_element_udf(),
diff --git a/datafusion/functions/src/core/union_extract.rs
b/datafusion/functions/src/core/union_extract.rs
index 95814197d8..420eeed42c 100644
--- a/datafusion/functions/src/core/union_extract.rs
+++ b/datafusion/functions/src/core/union_extract.rs
@@ -82,8 +82,8 @@ impl ScalarUDFImpl for UnionExtractFun {
}
fn return_type(&self, _: &[DataType]) -> Result<DataType> {
- // should be using return_type_from_exprs and not calling the default
implementation
- internal_err!("union_extract should return type from exprs")
+ // should be using return_type_from_args and not calling the default
implementation
+ internal_err!("union_extract should return type from args")
}
fn return_type_from_args(&self, args: ReturnTypeArgs) ->
Result<ReturnInfo> {
diff --git a/datafusion/physical-expr/src/lib.rs
b/datafusion/physical-expr/src/lib.rs
index 0a448fa6a2..3671eaef13 100644
--- a/datafusion/physical-expr/src/lib.rs
+++ b/datafusion/physical-expr/src/lib.rs
@@ -36,10 +36,6 @@ mod partitioning;
mod physical_expr;
pub mod planner;
mod scalar_function;
-pub mod udf {
- #[allow(deprecated)]
- pub use crate::scalar_function::create_physical_expr;
-}
pub mod statistics;
pub mod utils;
pub mod window;
diff --git a/datafusion/physical-expr/src/scalar_function.rs
b/datafusion/physical-expr/src/scalar_function.rs
index bd38fb22cc..cf8cc6e00c 100644
--- a/datafusion/physical-expr/src/scalar_function.rs
+++ b/datafusion/physical-expr/src/scalar_function.rs
@@ -39,12 +39,12 @@ use crate::PhysicalExpr;
use arrow::array::{Array, RecordBatch};
use arrow::datatypes::{DataType, Schema};
-use datafusion_common::{internal_err, DFSchema, Result, ScalarValue};
+use datafusion_common::{internal_err, Result, ScalarValue};
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, ReturnTypeArgs, ScalarFunctionArgs,
ScalarUDF,
+ expr_vec_fmt, ColumnarValue, ReturnTypeArgs, ScalarFunctionArgs, ScalarUDF,
};
/// Physical expression of a scalar function
@@ -261,35 +261,3 @@ impl PhysicalExpr for ScalarFunctionExpr {
})
}
}
-
-/// Create a physical expression for the UDF.
-#[deprecated(since = "45.0.0", note = "use ScalarFunctionExpr::new() instead")]
-pub fn create_physical_expr(
- fun: &ScalarUDF,
- input_phy_exprs: &[Arc<dyn PhysicalExpr>],
- input_schema: &Schema,
- args: &[Expr],
- input_dfschema: &DFSchema,
-) -> Result<Arc<dyn PhysicalExpr>> {
- let input_expr_types = input_phy_exprs
- .iter()
- .map(|e| e.data_type(input_schema))
- .collect::<Result<Vec<_>>>()?;
-
- // verify that input data types is consistent with function's
`TypeSignature`
- data_types_with_scalar_udf(&input_expr_types, fun)?;
-
- // Since we have arg_types, we don't need args and schema.
- let return_type =
- fun.return_type_from_exprs(args, input_dfschema, &input_expr_types)?;
-
- Ok(Arc::new(
- ScalarFunctionExpr::new(
- fun.name(),
- Arc::new(fun.clone()),
- input_phy_exprs.to_vec(),
- return_type,
- )
- .with_nullable(fun.is_nullable(args, input_dfschema)),
- ))
-}
diff --git a/datafusion/physical-plan/src/execution_plan.rs
b/datafusion/physical-plan/src/execution_plan.rs
index 851e504b69..d7556bc07c 100644
--- a/datafusion/physical-plan/src/execution_plan.rs
+++ b/datafusion/physical-plan/src/execution_plan.rs
@@ -27,7 +27,7 @@ pub use datafusion_execution::{RecordBatchStream,
SendableRecordBatchStream};
pub use datafusion_expr::{Accumulator, ColumnarValue};
pub use datafusion_physical_expr::window::WindowExpr;
pub use datafusion_physical_expr::{
- expressions, udf, Distribution, Partitioning, PhysicalExpr,
+ expressions, Distribution, Partitioning, PhysicalExpr,
};
use std::any::Any;
diff --git a/datafusion/physical-plan/src/lib.rs
b/datafusion/physical-plan/src/lib.rs
index 2cd9e8b52a..7c6cac0a36 100644
--- a/datafusion/physical-plan/src/lib.rs
+++ b/datafusion/physical-plan/src/lib.rs
@@ -35,7 +35,7 @@ pub use datafusion_expr::{Accumulator, ColumnarValue};
pub use datafusion_physical_expr::window::WindowExpr;
use datafusion_physical_expr::PhysicalSortExpr;
pub use datafusion_physical_expr::{
- expressions, udf, Distribution, Partitioning, PhysicalExpr,
+ expressions, Distribution, Partitioning, PhysicalExpr,
};
pub use crate::display::{DefaultDisplay, DisplayAs, DisplayFormatType,
VerboseDisplay};
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]