Move UnwrapCastInComparison into Simplifier#15012
Conversation
| 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.
this is great -- it will also reduce the number of times the entire plan tree gets walked/massaged
alamb
left a comment
There was a problem hiding this comment.
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
| } | ||
| } | ||
|
|
||
| fn unwrap_cast_in_comparison_for_binary<S: SimplifyInfo>( |
There was a problem hiding this comment.
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.
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.
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.
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.
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.
I agree with @alamb. We need to somehow preserve these tests within this PR
There was a problem hiding this comment.
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.
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 🚀 |
alamb
left a comment
There was a problem hiding this comment.
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.
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`
berkaysynnada
left a comment
There was a problem hiding this comment.
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 <[email protected]>

Which issue does this PR close?
SessionContext::create_physical_exprdoes 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?