Skip to content

Commit 4e8efec

Browse files
dharanadfindepi
authored andcommitted
Move overlay planning toExprPlanner (apache#11398)
* move overlay to expr planner * typo
1 parent c77ac73 commit 4e8efec

File tree

4 files changed

+27
-15
lines changed

4 files changed

+27
-15
lines changed

datafusion/expr/src/planner.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,13 @@ pub trait ExprPlanner: Send + Sync {
161161
) -> Result<PlannerResult<Vec<Expr>>> {
162162
Ok(PlannerResult::Original(args))
163163
}
164+
165+
/// Plans an overlay expression eg `overlay(str PLACING substr FROM pos [FOR count])`
166+
///
167+
/// Returns origin expression arguments if not possible
168+
fn plan_overlay(&self, args: Vec<Expr>) -> Result<PlannerResult<Vec<Expr>>> {
169+
Ok(PlannerResult::Original(args))
170+
}
164171
}
165172

166173
/// An operator with two arguments to plan

datafusion/functions/src/core/planner.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,10 @@ impl ExprPlanner for CoreFunctionPlanner {
5656
),
5757
)))
5858
}
59+
60+
fn plan_overlay(&self, args: Vec<Expr>) -> Result<PlannerResult<Vec<Expr>>> {
61+
Ok(PlannerResult::Planned(Expr::ScalarFunction(
62+
ScalarFunction::new_udf(crate::string::overlay(), args),
63+
)))
64+
}
5965
}

datafusion/functions/src/string/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,6 @@ pub fn functions() -> Vec<Arc<ScalarUDF>> {
182182
lower(),
183183
ltrim(),
184184
octet_length(),
185-
overlay(),
186185
repeat(),
187186
replace(),
188187
rtrim(),

datafusion/sql/src/expr/mod.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
193193
}
194194
}
195195

196-
not_impl_err!("Extract not supported by UserDefinedExtensionPlanners: {extract_args:?}")
196+
not_impl_err!("Extract not supported by ExprPlanner: {extract_args:?}")
197197
}
198198

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

295-
not_impl_err!("GetFieldAccess not supported by UserDefinedExtensionPlanners: {field_access_expr:?}")
295+
not_impl_err!(
296+
"GetFieldAccess not supported by ExprPlanner: {field_access_expr:?}"
297+
)
296298
}
297299

298300
SQLExpr::CompoundIdentifier(ids) => {
@@ -657,7 +659,7 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
657659
PlannerResult::Original(args) => create_struct_args = args,
658660
}
659661
}
660-
not_impl_err!("Struct not supported by UserDefinedExtensionPlanners: {create_struct_args:?}")
662+
not_impl_err!("Struct not supported by ExprPlanner: {create_struct_args:?}")
661663
}
662664

663665
fn sql_position_to_expr(
@@ -680,9 +682,7 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
680682
}
681683
}
682684

683-
not_impl_err!(
684-
"Position not supported by UserDefinedExtensionPlanners: {position_args:?}"
685-
)
685+
not_impl_err!("Position not supported by ExprPlanner: {position_args:?}")
686686
}
687687

688688
fn try_plan_dictionary_literal(
@@ -914,26 +914,26 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
914914
schema: &DFSchema,
915915
planner_context: &mut PlannerContext,
916916
) -> Result<Expr> {
917-
let fun = self
918-
.context_provider
919-
.get_function_meta("overlay")
920-
.ok_or_else(|| {
921-
internal_datafusion_err!("Unable to find expected 'overlay' function")
922-
})?;
923917
let arg = self.sql_expr_to_logical_expr(expr, schema, planner_context)?;
924918
let what_arg =
925919
self.sql_expr_to_logical_expr(overlay_what, schema, planner_context)?;
926920
let from_arg =
927921
self.sql_expr_to_logical_expr(overlay_from, schema, planner_context)?;
928-
let args = match overlay_for {
922+
let mut overlay_args = match overlay_for {
929923
Some(for_expr) => {
930924
let for_expr =
931925
self.sql_expr_to_logical_expr(*for_expr, schema, planner_context)?;
932926
vec![arg, what_arg, from_arg, for_expr]
933927
}
934928
None => vec![arg, what_arg, from_arg],
935929
};
936-
Ok(Expr::ScalarFunction(ScalarFunction::new_udf(fun, args)))
930+
for planner in self.planners.iter() {
931+
match planner.plan_overlay(overlay_args)? {
932+
PlannerResult::Planned(expr) => return Ok(expr),
933+
PlannerResult::Original(args) => overlay_args = args,
934+
}
935+
}
936+
not_impl_err!("Overlay not supported by ExprPlanner: {overlay_args:?}")
937937
}
938938
}
939939

0 commit comments

Comments
 (0)