-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Support negative scale decimals in decimal-to-integer conversions #19584
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
|
@alamb can you review the changes please . |
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.
Thank you for this PR @shifluxxc
I think the code looks good but I found the current test coverage in the .slt confusing
I think we need tests that try different types of decimals (including with negative scale), perhaps something like this (also adding Decimal32(9,-2), etc)? Though I don't fully comprehend the issue yet
# Test converting decimals to integers
statement ok
create table decimals as
select
arrow_cast(column1, 'Decimal32(9,2)') as dec32
from values
('123.45'),
('-678.90'),
('0.00');
query R
select log(dec32, 10) from decimals;
----
0.478127782968
NaN
0
| select cast(1.1 as decimal(2, 2)) + 1; | ||
|
|
||
| query I | ||
| SELECT CAST(123.45 AS INT); |
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.
these tests pass on main as well (so I don't think they cover the intended usecase)
log_decimal32 currently bypasses decimal32_to_i32 when the scale is negative, instead using a manual floating-point calculation, and is not used elsewhere except for log, so how should i test it ? |
If the callers guard against passing in negative scale then I think we won't need to change the existing functions. Thanks for checking this, I'll close the origina issue. |
|
Thanks @Jefffrey and @shifluxxc -- I am sorry I didn't better understand the issue |
Which issue does this PR close?
Rationale for this change
Decimal values with negative scale represent multiplication by a power of ten, but the decimal-to-integer conversion helpers previously rejected such values. This caused valid negative-scale decimals to fail during evaluation.
What changes are included in this PR?
Update decimal32_to_i32, decimal64_to_i64, and decimal128_to_i128 to correctly handle negative scales by multiplying
Are these changes tested?
Yes. Existing unit tests were updated and new cases were added to validate correct behavio