-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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 and better tests for expression re-rewriting / aliasing #3727
Conversation
cec55d1
to
a82ad9e
Compare
} | ||
|
||
Ok(expr) | ||
rewrite_preserving_name(expr, &mut expr_rewrite) |
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.
fyi @thinkharderdev
@@ -637,7 +621,8 @@ mod test { | |||
let mut config = OptimizerConfig::default(); | |||
let plan = rule.optimize(&plan, &mut config)?; | |||
assert_eq!( | |||
"Projection: a IN ([CAST(Int32(1) AS Int64), CAST(Int8(4) AS Int64), Int64(8)])\n EmptyRelation", | |||
"Projection: a IN ([CAST(Int32(1) AS Int64), CAST(Int8(4) AS Int64), Int64(8)]) AS a IN (Map { iter: Iter([Int32(1), Int8(4), Int64(8)]) })\ |
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.
cc @liukun4515 -- I think this is an improvement (and maybe a bug fix 🤔 )
let expr = expr.rewrite(&mut expr_rewriter)?; | ||
add_alias_if_changed(&original_name, expr) | ||
}) | ||
.map(|expr| rewrite_preserving_name(expr, &mut expr_rewriter)) |
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 PR basically refactors the code into rewrite_preserving_name
, adds tests, and calls it in a few places
/// `Expr::Sort` as appropriate | ||
fn name_for_alias(expr: &Expr) -> Result<String> { | ||
match expr { | ||
Expr::Sort { expr, .. } => name_for_alias(expr), |
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.
I missed this issue #3710
But I want to know why we need to do the special branch for Sort
Expr?
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.
Basically because calling Expr::name()
on a Expr::Sort
will throw an error:
I am not super thrilled in general about how this works -- I wonder if I should support calling Expr::name()
on Expr::Sort
🤔
I think there are may place which use the Do we need to fix all of them? |
That is an excellent point @liukun4515 -- I think we probably do. I will file a follow on ticket to track and do so |
Github actions is having issues I think -- the CI failures are not related to changes in this PR |
I have less knowledge about the alias for the expr, can you explain when and where we should do the alias for the expr which will be rewrited. |
I will file a ticket that explains the issue in more detail |
@liukun4515 I have filed #3794 which describes the issue more generally and explains why and when aliases are needed |
I will take a look your issue with this pr #3788, but it will take more time for this. |
Unless there are objections, I plan to merge this PR as it doesn't change any behavior and adds additional test coverage. We can continue to improve the code in other places it may be renaming incorrectly as part of #3794 |
Thanks @alamb , LGTM. Let's merge! |
Benchmark runs are scheduled for baseline = 61c38b7 and contender = e27e86b. e27e86b is a master commit associated with this PR. Results will be available as each benchmark for each run completes. |
🥳 |
Draft as it builds on #3710Which issue does this PR close?
re #3704
Rationale for this change
There are at least three places that we have rediscovered the issue of names changing when rewriting expressions such as #3704, #3555 and https://github.com/apache/arrow-datafusion/blob/master/datafusion/optimizer/src/simplify_expressions.rs#L316
I hope we can avoid other tricky bugs in the future
What changes are included in this PR?
rewrite_preserving_name
that handles aliasing during rewritesrewrite_preserving_name
Are there any user-facing changes?
no