Skip to content

Apache DataFusion SQL Query Engine

Deprecate confusingly named `UserDefinedFunctionPlanner` (#17247)

Andrew Lambd64b7c3b4b3f
diff --git a/datafusion/core/src/execution/session_state_defaults.rs b/datafusion/core/src/execution/session_state_defaults.rs
index a241738bd3..baf396f3f1 100644
--- a/datafusion/core/src/execution/session_state_defaults.rs
+++ b/datafusion/core/src/execution/session_state_defaults.rs
@@ -90,11 +90,10 @@ impl SessionStateDefaults {
Arc::new(functions_nested::planner::NestedFunctionPlanner),
#[cfg(feature = "nested_expressions")]
Arc::new(functions_nested::planner::FieldAccessPlanner),
- #[cfg(any(
- feature = "datetime_expressions",
- feature = "unicode_expressions"
- ))]
- Arc::new(functions::planner::UserDefinedFunctionPlanner),
+ #[cfg(feature = "datetime_expressions")]
+ Arc::new(functions::datetime::planner::DatetimeFunctionPlanner),
+ #[cfg(feature = "unicode_expressions")]
+ Arc::new(functions::unicode::planner::UnicodeFunctionPlanner),
Arc::new(functions_aggregate::planner::AggregateFunctionPlanner),
Arc::new(functions_window::planner::WindowFunctionPlanner),
];
diff --git a/datafusion/functions/src/datetime/mod.rs b/datafusion/functions/src/datetime/mod.rs
index dee40215c9..5729b1edae 100644
--- a/datafusion/functions/src/datetime/mod.rs
+++ b/datafusion/functions/src/datetime/mod.rs
@@ -30,6 +30,7 @@ pub mod date_trunc;
pub mod from_unixtime;
pub mod make_date;
pub mod now;
+pub mod planner;
pub mod to_char;
pub mod to_date;
pub mod to_local_time;
diff --git a/datafusion/functions/src/datetime/planner.rs b/datafusion/functions/src/datetime/planner.rs
new file mode 100644
index 0000000000..f4b64c3711
--- /dev/null
+++ b/datafusion/functions/src/datetime/planner.rs
@@ -0,0 +1,35 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+//! SQL planning extensions like [`DatetimeFunctionPlanner`]
+use datafusion_expr::expr::ScalarFunction;
+use datafusion_expr::planner::{ExprPlanner, PlannerResult};
+use datafusion_expr::Expr;
+
+#[derive(Default, Debug)]
+pub struct DatetimeFunctionPlanner;
+
+impl ExprPlanner for DatetimeFunctionPlanner {
+ fn plan_extract(
+ &self,
+ args: Vec<Expr>,
+ ) -> datafusion_common::Result<PlannerResult<Vec<Expr>>> {
+ Ok(PlannerResult::Planned(Expr::ScalarFunction(
+ ScalarFunction::new_udf(crate::datetime::date_part(), args),
+ )))
+ }
+}
diff --git a/datafusion/functions/src/planner.rs b/datafusion/functions/src/planner.rs
index 93edec7ece..7228cdc07e 100644
--- a/datafusion/functions/src/planner.rs
+++ b/datafusion/functions/src/planner.rs
@@ -24,9 +24,14 @@ use datafusion_expr::{
Expr,
};
+#[deprecated(
+ since = "0.50.0",
+ note = "Use UnicodeFunctionPlanner and DateTimeFunctionPlanner instead"
+)]
#[derive(Default, Debug)]
pub struct UserDefinedFunctionPlanner;
+#[expect(deprecated)]
impl ExprPlanner for UserDefinedFunctionPlanner {
#[cfg(feature = "datetime_expressions")]
fn plan_extract(&self, args: Vec<Expr>) -> Result<PlannerResult<Vec<Expr>>> {
diff --git a/datafusion/functions/src/unicode/mod.rs b/datafusion/functions/src/unicode/mod.rs
index 3c5cde3789..4a0dd21d74 100644
--- a/datafusion/functions/src/unicode/mod.rs
+++ b/datafusion/functions/src/unicode/mod.rs
@@ -26,6 +26,7 @@ pub mod find_in_set;
pub mod initcap;
pub mod left;
pub mod lpad;
+pub mod planner;
pub mod reverse;
pub mod right;
pub mod rpad;
diff --git a/datafusion/functions/src/unicode/planner.rs b/datafusion/functions/src/unicode/planner.rs
new file mode 100644
index 0000000000..e4f29be3d1
--- /dev/null
+++ b/datafusion/functions/src/unicode/planner.rs
@@ -0,0 +1,45 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+//! SQL planning extensions like [`UnicodeFunctionPlanner`]
+
+use datafusion_expr::expr::ScalarFunction;
+use datafusion_expr::planner::{ExprPlanner, PlannerResult};
+use datafusion_expr::Expr;
+
+#[derive(Default, Debug)]
+pub struct UnicodeFunctionPlanner;
+
+impl ExprPlanner for UnicodeFunctionPlanner {
+ fn plan_position(
+ &self,
+ args: Vec<Expr>,
+ ) -> datafusion_common::Result<PlannerResult<Vec<Expr>>> {
+ Ok(PlannerResult::Planned(Expr::ScalarFunction(
+ ScalarFunction::new_udf(crate::unicode::strpos(), args),
+ )))
+ }
+
+ fn plan_substring(
+ &self,
+ args: Vec<Expr>,
+ ) -> datafusion_common::Result<PlannerResult<Vec<Expr>>> {
+ Ok(PlannerResult::Planned(Expr::ScalarFunction(
+ ScalarFunction::new_udf(crate::unicode::substr(), args),
+ )))
+ }
+}
diff --git a/datafusion/sql/tests/cases/plan_to_sql.rs b/datafusion/sql/tests/cases/plan_to_sql.rs
index cffb062974..a35836420c 100644
--- a/datafusion/sql/tests/cases/plan_to_sql.rs
+++ b/datafusion/sql/tests/cases/plan_to_sql.rs
@@ -51,7 +51,7 @@ use datafusion_expr::builder::{
project, subquery_alias, table_scan_with_filter_and_fetch, table_scan_with_filters,
};
use datafusion_functions::core::planner::CoreFunctionPlanner;
-use datafusion_functions::planner::UserDefinedFunctionPlanner;
+use datafusion_functions::unicode::planner::UnicodeFunctionPlanner;
use datafusion_functions_nested::extract::array_element_udf;
use datafusion_functions_nested::planner::{FieldAccessPlanner, NestedFunctionPlanner};
use datafusion_sql::unparser::ast::{
@@ -1341,7 +1341,7 @@ where
.with_scalar_function(Arc::new(unicode::substr().as_ref().clone()))
.with_scalar_function(make_array_udf())
.with_expr_planner(Arc::new(CoreFunctionPlanner::default()))
- .with_expr_planner(Arc::new(UserDefinedFunctionPlanner))
+ .with_expr_planner(Arc::new(UnicodeFunctionPlanner))
.with_expr_planner(Arc::new(NestedFunctionPlanner))
.with_expr_planner(Arc::new(FieldAccessPlanner)),
};