-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Move UnwrapCastInComparison
into Simplifier
#15012
Conversation
@@ -243,7 +242,6 @@ impl Optimizer { | |||
let rules: Vec<Arc<dyn OptimizerRule + Sync + Send>> = vec![ | |||
Arc::new(EliminateNestedUnion::new()), | |||
Arc::new(SimplifyExpressions::new()), | |||
Arc::new(UnwrapCastInComparison::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 is great -- it will also reduce the number of times the entire plan tree gets walked/massaged
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.
Thank you so much @jayzhan211 -- this looks awesome
I don't think we should delete the tests, but otherwise this PR could be merged in my opinion
// no additional rewrites possible | ||
expr => Transformed::no(expr), | ||
}) | ||
} | ||
} | ||
|
||
fn unwrap_cast_in_comparison_for_binary<S: SimplifyInfo>( |
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.
As the expr_simplifer.rs module is getting big, we could consider putting the code that supports the casting into a different module (for example unwrap_cast.rs
for example)
use datafusion_expr::utils::merge_schema; | ||
use datafusion_expr::{lit, Expr, ExprSchemable, LogicalPlan}; | ||
|
||
/// [`UnwrapCastInComparison`] attempts to remove casts from |
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.
Would it be possible to keep these comments? I think the context / content is important
Maybe the could be put as module level comments in unwrap_cast.rs if you move that code into the simplifier
use datafusion_expr::{cast, col, in_list, try_cast}; | ||
|
||
#[test] | ||
fn test_not_unwrap_cast_comparison() { |
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 think these tests probably should be ported too. Would you like some help with that ? I bet we could find people to do so
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.
Sure, we can file issue to increase more tests. Btw, I didn't add any new tests because I think the existing test is enough, it catches my bug during my implementation
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 am thinking that these tests likely cover a bunch of corner cases like decimal precision and different timestamp types that may not be fully covered in .slt
I'll try and help either port them or file a ticket to do so
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 agree with @alamb. We need to somehow preserve these tests within this PR
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.
Since this PR seems to improve performance non trivially, I will work on porting the tests now. I'll see how far I get
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 a proposed change to this PR to port the tests (turns out to be much easier than I thought):
![]() BTW this PR seems to significantly IMPROVE planning performance. Perhaps as it has reduced a plan copy 🤔 I will rerun the benchmarks to make sure, but if I can reproduce the results I am that much more incentivized to help port the tests / get this in. Thanks you @jayzhan211 🚀 |
Yeah I consistently see signfiicantly faster planing with this PR 🚀
|
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 am also working on a test that shows that this PR fixes the issue in the ticket
use datafusion_expr::{cast, col, in_list, try_cast}; | ||
|
||
#[test] | ||
fn test_not_unwrap_cast_comparison() { |
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 am thinking that these tests likely cover a bunch of corner cases like decimal precision and different timestamp types that may not be fully covered in .slt
I'll try and help either port them or file a ticket to do so
Port `unwrap_cast` tests to `ExprSimplifier`
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.
Looking a lot better now, thank you @jayzhan211 and @alamb
I also filed a ticket to explore making planning fster by more consolidation |
Thank you @jayzhan211 and @berkaysynnada |
* add unwrap in simplify expr * rm unwrap cast * return err * rename * fix * fmt * add unwrap_cast module to simplify expressions * tweak comment * Move tests * Rewrite to use simplifier schema * Update tests for simplify logic --------- Co-authored-by: Andrew Lamb <andrew@nerdnetworks.org>
Which issue does this PR close?
SessionContext::create_physical_expr
does not unwrap casts (and thus is not always optimal) #14987.Rationale for this change
What changes are included in this PR?
Are these changes tested?
Are there any user-facing changes?