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 940efd3b42 Made userDefinedFunctionPlanner to uniform the usages 
(#11318)
940efd3b42 is described below

commit 940efd3b4240bcc4a44ab02342a10ca2663318a0
Author: Xin Li <[email protected]>
AuthorDate: Sun Jul 7 18:04:19 2024 -0700

    Made userDefinedFunctionPlanner to uniform the usages (#11318)
---
 datafusion/core/src/execution/session_state.rs     |  9 +++---
 datafusion/functions/src/datetime/mod.rs           |  1 -
 datafusion/functions/src/lib.rs                    |  3 ++
 datafusion/functions/src/{datetime => }/planner.rs | 14 +++++++--
 datafusion/functions/src/unicode/mod.rs            |  1 -
 datafusion/functions/src/unicode/planner.rs        | 36 ----------------------
 6 files changed, 19 insertions(+), 45 deletions(-)

diff --git a/datafusion/core/src/execution/session_state.rs 
b/datafusion/core/src/execution/session_state.rs
index ad557b1225..d056b91c27 100644
--- a/datafusion/core/src/execution/session_state.rs
+++ b/datafusion/core/src/execution/session_state.rs
@@ -238,10 +238,11 @@ impl SessionState {
             Arc::new(functions_array::planner::ArrayFunctionPlanner),
             #[cfg(feature = "array_expressions")]
             Arc::new(functions_array::planner::FieldAccessPlanner),
-            #[cfg(feature = "datetime_expressions")]
-            Arc::new(functions::datetime::planner::ExtractPlanner),
-            #[cfg(feature = "unicode_expressions")]
-            Arc::new(functions::unicode::planner::PositionPlanner),
+            #[cfg(any(
+                feature = "datetime_expressions",
+                feature = "unicode_expressions"
+            ))]
+            Arc::new(functions::planner::UserDefinedFunctionPlanner),
         ];
 
         let mut new_self = SessionState {
diff --git a/datafusion/functions/src/datetime/mod.rs 
b/datafusion/functions/src/datetime/mod.rs
index 8365a38f41..9c2f80856b 100644
--- a/datafusion/functions/src/datetime/mod.rs
+++ b/datafusion/functions/src/datetime/mod.rs
@@ -30,7 +30,6 @@ 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_timestamp;
diff --git a/datafusion/functions/src/lib.rs b/datafusion/functions/src/lib.rs
index 4bc24931d0..433a4f90d9 100644
--- a/datafusion/functions/src/lib.rs
+++ b/datafusion/functions/src/lib.rs
@@ -130,6 +130,9 @@ make_stub_package!(crypto, "crypto_expressions");
 pub mod unicode;
 make_stub_package!(unicode, "unicode_expressions");
 
+#[cfg(any(feature = "datetime_expressions", feature = "unicode_expressions"))]
+pub mod planner;
+
 mod utils;
 
 /// Fluent-style API for creating `Expr`s
diff --git a/datafusion/functions/src/datetime/planner.rs 
b/datafusion/functions/src/planner.rs
similarity index 71%
rename from datafusion/functions/src/datetime/planner.rs
rename to datafusion/functions/src/planner.rs
index 4265ce42a5..b00d5cf608 100644
--- a/datafusion/functions/src/datetime/planner.rs
+++ b/datafusion/functions/src/planner.rs
@@ -15,7 +15,7 @@
 // specific language governing permissions and limitations
 // under the License.
 
-//! SQL planning extensions like [`ExtractPlanner`]
+//! SQL planning extensions like [`UserDefinedFunctionPlanner`]
 
 use datafusion_common::Result;
 use datafusion_expr::{
@@ -25,12 +25,20 @@ use datafusion_expr::{
 };
 
 #[derive(Default)]
-pub struct ExtractPlanner;
+pub struct UserDefinedFunctionPlanner;
 
-impl UserDefinedSQLPlanner for ExtractPlanner {
+impl UserDefinedSQLPlanner for UserDefinedFunctionPlanner {
+    #[cfg(feature = "datetime_expressions")]
     fn plan_extract(&self, args: Vec<Expr>) -> 
Result<PlannerResult<Vec<Expr>>> {
         Ok(PlannerResult::Planned(Expr::ScalarFunction(
             ScalarFunction::new_udf(crate::datetime::date_part(), args),
         )))
     }
+
+    #[cfg(feature = "unicode_expressions")]
+    fn plan_position(&self, args: Vec<Expr>) -> 
Result<PlannerResult<Vec<Expr>>> {
+        Ok(PlannerResult::Planned(Expr::ScalarFunction(
+            ScalarFunction::new_udf(crate::unicode::strpos(), args),
+        )))
+    }
 }
diff --git a/datafusion/functions/src/unicode/mod.rs 
b/datafusion/functions/src/unicode/mod.rs
index a391b8ba11..9e8c07cd36 100644
--- a/datafusion/functions/src/unicode/mod.rs
+++ b/datafusion/functions/src/unicode/mod.rs
@@ -25,7 +25,6 @@ pub mod character_length;
 pub mod find_in_set;
 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
deleted file mode 100644
index 4d6f73321b..0000000000
--- a/datafusion/functions/src/unicode/planner.rs
+++ /dev/null
@@ -1,36 +0,0 @@
-// 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 [`PositionPlanner`]
-
-use datafusion_common::Result;
-use datafusion_expr::{
-    expr::ScalarFunction,
-    planner::{PlannerResult, UserDefinedSQLPlanner},
-    Expr,
-};
-
-#[derive(Default)]
-pub struct PositionPlanner;
-
-impl UserDefinedSQLPlanner for PositionPlanner {
-    fn plan_position(&self, args: Vec<Expr>) -> 
Result<PlannerResult<Vec<Expr>>> {
-        Ok(PlannerResult::Planned(Expr::ScalarFunction(
-            ScalarFunction::new_udf(crate::unicode::strpos(), args),
-        )))
-    }
-}


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to