Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move overlay planning toExprPlanner #11398

Merged
merged 2 commits into from
Jul 11, 2024
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
7 changes: 7 additions & 0 deletions datafusion/expr/src/planner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,13 @@ pub trait ExprPlanner: Send + Sync {
) -> Result<PlannerResult<Vec<Expr>>> {
Ok(PlannerResult::Original(args))
}

/// Plans an overlay expression eg `overlay(str PLACING substr FROM pos [FOR count])`
///
/// Returns origin expression arguments if not possible
fn plan_overlay(&self, args: Vec<Expr>) -> Result<PlannerResult<Vec<Expr>>> {
Ok(PlannerResult::Original(args))
}
}

/// An operator with two arguments to plan
Expand Down
6 changes: 6 additions & 0 deletions datafusion/functions/src/core/planner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,10 @@ impl ExprPlanner for CoreFunctionPlanner {
),
)))
}

fn plan_overlay(&self, args: Vec<Expr>) -> Result<PlannerResult<Vec<Expr>>> {
Ok(PlannerResult::Planned(Expr::ScalarFunction(
ScalarFunction::new_udf(crate::string::overlay(), args),
)))
}
}
1 change: 0 additions & 1 deletion datafusion/functions/src/string/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@ pub fn functions() -> Vec<Arc<ScalarUDF>> {
lower(),
ltrim(),
octet_length(),
overlay(),
repeat(),
replace(),
rtrim(),
Expand Down
28 changes: 14 additions & 14 deletions datafusion/sql/src/expr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
}
}

not_impl_err!("Extract not supported by UserDefinedExtensionPlanners: {extract_args:?}")
not_impl_err!("Extract not supported by ExprPlanner: {extract_args:?}")
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

Thank you -- this is a nice drive by cleanup

}

SQLExpr::Array(arr) => self.sql_array_literal(arr.elem, schema),
Expand Down Expand Up @@ -292,7 +292,9 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
}
}

not_impl_err!("GetFieldAccess not supported by UserDefinedExtensionPlanners: {field_access_expr:?}")
not_impl_err!(
"GetFieldAccess not supported by ExprPlanner: {field_access_expr:?}"
)
}

SQLExpr::CompoundIdentifier(ids) => {
Expand Down Expand Up @@ -657,7 +659,7 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
PlannerResult::Original(args) => create_struct_args = args,
}
}
not_impl_err!("Struct not supported by UserDefinedExtensionPlanners: {create_struct_args:?}")
not_impl_err!("Struct not supported by ExprPlanner: {create_struct_args:?}")
}

fn sql_position_to_expr(
Expand All @@ -680,9 +682,7 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
}
}

not_impl_err!(
"Position not supported by UserDefinedExtensionPlanners: {position_args:?}"
)
not_impl_err!("Position not supported by ExprPlanner: {position_args:?}")
}

fn try_plan_dictionary_literal(
Expand Down Expand Up @@ -914,26 +914,26 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
schema: &DFSchema,
planner_context: &mut PlannerContext,
) -> Result<Expr> {
let fun = self
.context_provider
.get_function_meta("overlay")
.ok_or_else(|| {
internal_datafusion_err!("Unable to find expected 'overlay' function")
})?;
let arg = self.sql_expr_to_logical_expr(expr, schema, planner_context)?;
let what_arg =
self.sql_expr_to_logical_expr(overlay_what, schema, planner_context)?;
let from_arg =
self.sql_expr_to_logical_expr(overlay_from, schema, planner_context)?;
let args = match overlay_for {
let mut overlay_args = match overlay_for {
Some(for_expr) => {
let for_expr =
self.sql_expr_to_logical_expr(*for_expr, schema, planner_context)?;
vec![arg, what_arg, from_arg, for_expr]
}
None => vec![arg, what_arg, from_arg],
};
Ok(Expr::ScalarFunction(ScalarFunction::new_udf(fun, args)))
for planner in self.planners.iter() {
match planner.plan_overlay(overlay_args)? {
PlannerResult::Planned(expr) => return Ok(expr),
PlannerResult::Original(args) => overlay_args = args,
}
}
not_impl_err!("Overlay not supported by ExprPlanner: {overlay_args:?}")
}
}

Expand Down