-
Notifications
You must be signed in to change notification settings - Fork 1.9k
fix coercion of null for decimal math in binary_rules #3549
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
fix coercion of null for decimal math in binary_rules #3549
Conversation
| ), | ||
| } | ||
| (Null, dec_type @ Decimal128(_, _)) | (dec_type @ Decimal128(_, _), Null) => { | ||
| Some(dec_type.clone()) |
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 the actual fix, the rest is some refactoring
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.
Could the same coercion (Null to that type) be applied for all the other numeric types as well?
In other words, I wonder if we need to special case Decimal128 ? Is it to skip the special decimal coercion logic below?
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, it's basically to shortcut that next match arm for figuring out the Decimal's precision and scale, which depends on the datatype being math'd to the decimal ... none of that matters if it's a null, you just need to return the same datatype. Back further up the chain, the null gets cast to this datatype.
The other number types don't have the rules that Decimals do, so you'll see in the same match they just return their own datatype, no complexity.
Codecov Report
@@ Coverage Diff @@
## master #3549 +/- ##
==========================================
+ Coverage 85.80% 85.89% +0.09%
==========================================
Files 300 301 +1
Lines 55506 56045 +539
==========================================
+ Hits 47625 48142 +517
- Misses 7881 7903 +22
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
why the result is cc @kmitchener |
|
@liukun4515 it's just the naming of the expression. the actual datatype is Decimal. ❯ select arrow_typeof(null + 1::decimal);
+------------------------------+
| arrowtypeof(NULL + Int64(1)) |
+------------------------------+
| Decimal128(38, 10) |
+------------------------------+
1 row in set. Query took 0.045 seconds.Naming of resulting columns after casting is kinda weird, but unrelated to this PR. ❯ select 1::decimal;
+--------------+
| Int64(1) |
+--------------+
| 1.0000000000 |
+--------------+
1 row in set. Query took 0.008 seconds.
❯ select 1::float;
+----------+
| Int64(1) |
+----------+
| 1 |
+----------+
1 row in set. Query took 0.005 seconds.
❯ select 1::text;
+----------+
| Int64(1) |
+----------+
| 1 |
+----------+
1 row in set. Query took 0.005 seconds. |
alamb
left a comment
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.
LGTM -- thanks @kmitchener
| (_, DataType::Null) => { | ||
| if can_cast_types(&DataType::Null, lhs_type) { | ||
| Some(lhs_type.clone()) | ||
| (DataType::Null, other_type) | (other_type, DataType::Null) => { |
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 a nice cleanup
| ), | ||
| } | ||
| (Null, dec_type @ Decimal128(_, _)) | (dec_type @ Decimal128(_, _), Null) => { | ||
| Some(dec_type.clone()) |
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.
Could the same coercion (Null to that type) be applied for all the other numeric types as well?
In other words, I wonder if we need to special case Decimal128 ? Is it to skip the special decimal coercion logic below?
But this make me confused. cc @alamb Do you have any comments about this. this fix looks good to me expect this header. |
I agree the header name for constants looks non ideal. I seem to remember a discussion we had somewhere else to maybe make the names of constants different but I couldn't find it |
|
Benchmark runs are scheduled for baseline = b134fa4 and contender = a080c03. a080c03 is a master commit associated with this PR. Results will be available as each benchmark for each run completes. |
Maybe this can help us. #3568 (comment) |
Which issue does this PR close?
Closes #3479 . This fix can close that issue -- there's another issue for adding support for casting utf8 to decimal.
Rationale for this change
Prior to this fix:
After this fix:
What changes are included in this PR?
Are there any user-facing changes?