Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions datafusion/core/src/execution/session_state_defaults.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for some reason both datetime and unicode expressions were in the same planner, which is not the same pattern for the other features 🤷 -- so I propose making main follow the existing pattern

#[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),
];
Expand Down
1 change: 1 addition & 0 deletions datafusion/functions/src/datetime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
35 changes: 35 additions & 0 deletions datafusion/functions/src/datetime/planner.rs
Original file line number Diff line number Diff line change
@@ -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),
)))
}
}
5 changes: 5 additions & 0 deletions datafusion/functions/src/planner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>>> {
Expand Down
1 change: 1 addition & 0 deletions datafusion/functions/src/unicode/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
45 changes: 45 additions & 0 deletions datafusion/functions/src/unicode/planner.rs
Original file line number Diff line number Diff line change
@@ -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),
)))
}
}
4 changes: 2 additions & 2 deletions datafusion/sql/tests/cases/plan_to_sql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -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)),
};
Expand Down