Skip to content

Commit

Permalink
Made userDefinedFunctionPlanner to uniform the usages
Browse files Browse the repository at this point in the history
  • Loading branch information
xinlifoobar committed Jul 7, 2024
1 parent e693ed7 commit 872c6bb
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 45 deletions.
9 changes: 5 additions & 4 deletions datafusion/core/src/execution/session_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 0 additions & 1 deletion datafusion/functions/src/datetime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions datafusion/functions/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand All @@ -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),
)))
}
}
1 change: 0 additions & 1 deletion datafusion/functions/src/unicode/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
36 changes: 0 additions & 36 deletions datafusion/functions/src/unicode/planner.rs

This file was deleted.

0 comments on commit 872c6bb

Please sign in to comment.