Skip to content

Conversation

@shifluxxc
Copy link
Contributor

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

@github-actions github-actions bot added sqllogictest SQL Logic Tests (.slt) functions Changes to functions implementation labels Dec 31, 2025
@shifluxxc
Copy link
Contributor Author

@alamb can you review the changes please .

Copy link
Contributor

@alamb alamb left a 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);
Copy link
Contributor

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

functions Changes to functions implementation sqllogictest SQL Logic Tests (.slt)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants