-
Notifications
You must be signed in to change notification settings - Fork 1.7k
fix decimal precision issue in simplify expression optimize rule #15588
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
Conversation
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 @shehabgamin
Do you have some time to review this PR
Yes! Will carve out some time on Monday. Thanks @jayzhan211 !! |
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.
@jayzhan211 Nice job! Just left some minor comments :)
| match BinaryTypeCoercer::new(&left_type, op, &right_type).get_result_type() { | ||
| Ok(result_type) => { | ||
| // Only cast if the types differ | ||
| if left_type != result_type { |
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.
We might as well check if right_type != result_type too to be extra safe, right?
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 we only care about left side expr, whatever right side is the result doesn't change
| match BinaryTypeCoercer::new(&left_type, op, &right_type).get_result_type() { | ||
| Ok(result_type) => { | ||
| // Only cast if the types differ | ||
| if right_type != result_type { |
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.
We might as well check if left_type != result_type too to be extra safe, right?
| { | ||
| Ok(result_type) => { | ||
| // Only cast if the types differ | ||
| if left_type != result_type { |
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.
We might as well check if right_type != result_type too to be extra safe, right?
| // Check if resulting type would be different due to coercion | ||
| let left_type = info.get_data_type(&left)?; | ||
| let right_type = info.get_data_type(right)?; | ||
| match BinaryTypeCoercer::new(&left_type, &Operator::Divide, &right_type) |
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 should be op instead of &Operator::Divide
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 function is only used in Divide not other op, different op may behave differently.
In Multiple case, I switch left and right instead.
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.
@jayzhan211 Got it! Was going to suggest to rename the function for clarity but it looks like you did that in your latest commit!
| info: &S, | ||
| left: Box<Expr>, | ||
| right: &Expr, | ||
| ) -> Result<Transformed<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.
Pass in op: &Operator,
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 op is required if it fits well more then 1 op
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.
@jayzhan211 @alamb LGTM!
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.
Thanks @jayzhan211 and @shehabgamin
…che#15588) * fix decimal precision * return expr if fail to find the casted type * move fn out * comment * fmt * fix * fix name and doc
Which issue does this PR close?
Rationale for this change
What changes are included in this PR?
Are these changes tested?
Are there any user-facing changes?