-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Avoid changing expression names during constant folding #1319
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
Changes from 10 commits
a656b44
fe8445d
ebf67d3
8e52b94
3191563
1cfbba0
46315a1
aa8cf15
7c22b5d
166b41a
d767aeb
8d715de
eec7cbe
2a7652d
22dac02
546d2a2
6e53b53
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -92,6 +92,10 @@ impl OptimizerRule for ConstantFolding { | |
| .expressions() | ||
| .into_iter() | ||
| .map(|e| { | ||
| // We need to keep original expression name, if any. | ||
| // Constant folding should not change expression name. | ||
| let name = &e.name(plan.schema()); | ||
|
|
||
| // TODO iterate until no changes are made | ||
| // during rewrite (evaluating constants can | ||
| // enable new simplifications and | ||
|
|
@@ -101,7 +105,30 @@ impl OptimizerRule for ConstantFolding { | |
| // fold constants and then simplify | ||
| .rewrite(&mut const_evaluator)? | ||
| .rewrite(&mut simplifier)?; | ||
| Ok(new_e) | ||
|
|
||
| let new_name = &new_e.name(plan.schema()); | ||
|
|
||
| // Some plans will be candidates in projection pushdown rule to | ||
| // trim expressions based on expression names. We need to keep | ||
| // expression name for them. | ||
| let is_plan_for_projection_pushdown = matches!( | ||
| plan, | ||
| LogicalPlan::Window { .. } | ||
|
||
| | LogicalPlan::Aggregate { .. } | ||
| | LogicalPlan::Union { .. } | ||
| ); | ||
|
|
||
| if let (Ok(expr_name), Ok(new_expr_name)) = (name, new_name) { | ||
| if expr_name != new_expr_name | ||
| && is_plan_for_projection_pushdown | ||
| { | ||
| Ok(new_e.alias(expr_name)) | ||
| } else { | ||
| Ok(new_e) | ||
| } | ||
| } else { | ||
| Ok(new_e) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I worry we may be silently ignoring some real issues in the future. However, I tried checking So I suppose this is as good as we are going to do for now |
||
| } | ||
| }) | ||
| .collect::<Result<Vec<_>>>()?; | ||
|
|
||
|
|
@@ -733,7 +760,7 @@ mod tests { | |
| .build()?; | ||
|
|
||
| let expected = "\ | ||
| Aggregate: groupBy=[[#test.a, #test.c]], aggr=[[MAX(#test.b), MIN(#test.b)]]\ | ||
| Aggregate: groupBy=[[#test.a, #test.c]], aggr=[[MAX(#test.b) AS MAX(test.b = Boolean(true)), MIN(#test.b)]]\ | ||
| \n Projection: #test.a, #test.c, #test.b\ | ||
| \n TableScan: test projection=None"; | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍