-
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
change pre_cast_lit_in_comparison to unwrap_cast_in_comparison #3662
Conversation
vec![ | ||
"logical_plan", | ||
"Projection: #aggregate_test_100.c1\ | ||
\n Filter: CAST(#aggregate_test_100.c2 AS Int32) > Int32(10)\ |
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.
CAST(#aggregate_test_100.c2 AS Int32)
will be converted to #aggregate_test_100.c2
, and the Int32(10)
will be converted to Int8(10)
b194fa7
to
5c6c334
Compare
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 went through this PR carefully. Nice work @liukun4515
Arc::new(TypeCoercion::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 name is much easier to understand for me -- thank you
"logical_plan", | ||
"Projection: #aggregate_test_100.c1\ | ||
\n Filter: CAST(#aggregate_test_100.c2 AS Int32) > Int32(10)\ | ||
\n TableScan: aggregate_test_100 projection=[c1, c2], partial_filters=[CAST(#aggregate_test_100.c2 AS Int32) > Int32(10)]" |
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.
The key difference for anyone else following along is that
partial_filters=[CAST(#aggregate_test_100.c2 AS Int32) > Int32(10)]
Has become
partial_filters=[partial_filters=[#aggregate_test_100.c2 > Int8(10)]
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.
yes, we remove the cast for CAST(#aggregate_test_100.c2 AS Int32)
, and add cast for Int32(10)
vec![ | ||
lit(ScalarValue::Int32(Some(12))), | ||
lit(ScalarValue::Int64(Some(12))), |
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.
Is this change (so that all the IN
list types are the same) because type coercion will have already been done when this code is now called?
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.
Yes.
In this rule, we need to assume that the type coercion has been done for the expr or the plan.
fd65504
to
526e7f4
Compare
526e7f4
to
0a2e478
Compare
The ci failed, but we can merge it first. |
Benchmark runs are scheduled for baseline = f862eef and contender = a1b2112. a1b2112 is a master commit associated with this PR. Results will be available as each benchmark for each run completes. |
@alamb @liukun4515 This PR introduced regressions that I have documented in #3690. I don't know if it is better to revert this PR or try and fix. |
I would rather fix it but defer to you. I think #3676 fixes part of it. I will merge that and fix the other part tomorrow if @liukun4515 hasn't had a chance to do so |
@alamb @andygrove |
Which issue does this PR close?
In order to achieve the target of #3582, we need do the
type coercion
first before all optimizer rules.After done the
type coercion
, some of the expr will be wrapped by thecast/try_cast
, the rule ofpre_cast_lit_in_comparison
will not work, so we should refactor it.For example:
For this case
cast(left_expr as data_type) < lit(value as data_type)
, if the value can be converted to the type of left_expr, we can unwrap the cast for the exprcast(left_expr as data_type)
and add cast tolit(value as data_type)
and get the new literal exprcast(lit(value as data_type) as left_expr_data_type)
.Closes #3622
Rationale for this change
What changes are included in this PR?
Are there any user-facing changes?