-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Consolidate ConstantFolding
and SimplifyExpression
#1375
Conversation
ConstantFolding
and SimplifyExpression
fd1c9b8
to
882356e
Compare
ConstantFolding
and SimplifyExpression
ConstantFolding
and SimplifyExpression
// projected columns. With just the projected schema, it's not possible to infer types for | ||
// expressions that references non-projected columns within the same project plan or its | ||
// children plans. | ||
let mut simplifier = |
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.
this logic is moved from ConstantFolding
// TODO combine simplify into Simplifier | ||
let e = simplify(&e); |
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.
Here is the call into the existing simplify
function that is in the SimplifyExpressions
pass (originally written by @jgoday)
let new_name = &new_e.name(plan.schema()); | ||
|
||
// TODO simplify this logic | ||
if let (Ok(expr_name), Ok(new_expr_name)) = (name, new_name) { |
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.
@@ -1562,4 +1556,388 @@ mod tests { | |||
.unwrap(), | |||
) | |||
} | |||
|
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.
these tests are just moved from constant_folding.rs
Arc::new(ConstantFolding::new()), | ||
// Simplify expressions first to maximize the chance | ||
// of applying other optimizations | ||
Arc::new(SimplifyExpressions::new()), |
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.
This change has the additional benefit of allowing even more filters to be pushed down (e.g. column * 1 < 5
which is simplified by the code in simplify
to column < 5
can now also be pushed down
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.
nice simplification and tests :)
Which issue does this PR close?
Builds on #1374
Re #1160 (more sophisticated expression simplification) and #1316 don't change names during constant folding
Rationale for this change
ConstantFolding
andSimplifyExpression
both simplify expressions, in slightly different ways, which is confusing and redundant.It also means bug fixes such as #1319 didn't get applied to
SimplifyExpression
.For example, on master (not the column name is
column1
, due to the simplification that has occured):On this branch the column is correctly named:
What changes are included in this PR?
ConstantFolding
optimizer pass by compilingConstantFolding
intoSimplifyExpression
optimizer passNote:
I plan more PRs to combine
simplify
andSimplifier
logic but to keep reviews easier I am going to do that in another PR