This is an automated email from the ASF dual-hosted git repository.
comphead 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 42fe050420 Add fast paths for try_process_unnest (#16389)
42fe050420 is described below
commit 42fe050420571b4cdedfa662b84d3ab2f7bc0fe3
Author: Simon Vandel Sillesen <[email protected]>
AuthorDate: Sun Jun 15 07:41:07 2025 +0200
Add fast paths for try_process_unnest (#16389)
* Add fast paths for try_process_unnest
* refmt
---
datafusion/sql/src/select.rs | 29 +++++++++++++++++++++++++++++
1 file changed, 29 insertions(+)
diff --git a/datafusion/sql/src/select.rs b/datafusion/sql/src/select.rs
index 9fad274b51..b50fbf6812 100644
--- a/datafusion/sql/src/select.rs
+++ b/datafusion/sql/src/select.rs
@@ -307,6 +307,15 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
let mut intermediate_plan = input;
let mut intermediate_select_exprs = select_exprs;
+ // Fast path: If there is are no unnests in the select_exprs, wrap the
plan in a projection
+ if !intermediate_select_exprs
+ .iter()
+ .any(has_unnest_expr_recursively)
+ {
+ return LogicalPlanBuilder::from(intermediate_plan)
+ .project(intermediate_select_exprs)?
+ .build();
+ }
// Each expr in select_exprs can contains multiple unnest stage
// The transformation happen bottom up, one at a time for each
iteration
@@ -374,6 +383,12 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
fn try_process_aggregate_unnest(&self, input: LogicalPlan) ->
Result<LogicalPlan> {
match input {
+ // Fast path if there are no unnest in group by
+ LogicalPlan::Aggregate(ref agg)
+ if !&agg.group_expr.iter().any(has_unnest_expr_recursively) =>
+ {
+ Ok(input)
+ }
LogicalPlan::Aggregate(agg) => {
let agg_expr = agg.aggr_expr.clone();
let (new_input, new_group_by_exprs) =
@@ -939,3 +954,17 @@ fn check_conflicting_windows(window_defs:
&[NamedWindowDefinition]) -> Result<()
}
Ok(())
}
+
+/// Returns true if the expression recursively contains an `Expr::Unnest`
expression
+fn has_unnest_expr_recursively(expr: &Expr) -> bool {
+ let mut has_unnest = false;
+ let _ = expr.apply(|e| {
+ if let Expr::Unnest(_) = e {
+ has_unnest = true;
+ Ok(TreeNodeRecursion::Stop)
+ } else {
+ Ok(TreeNodeRecursion::Continue)
+ }
+ });
+ has_unnest
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]