Skip to content
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

Incorrect result for decimal cast #14450

Open
Blizzara opened this issue Feb 3, 2025 · 1 comment
Open

Incorrect result for decimal cast #14450

Blizzara opened this issue Feb 3, 2025 · 1 comment
Labels
bug Something isn't working

Comments

@Blizzara
Copy link
Contributor

Blizzara commented Feb 3, 2025

Describe the bug

Converting a decimal 5.20 from (4,2) to (3,2) leads to the value becoming 5.21

Something's gone wrong likely in the fixing of #13492 / apache/arrow-rs#6833?

Or, maybe there's some existing bug in the creation of the decimal array in the first place, and the Arrow bug was hiding it before?

Fyi @alamb @andygrove

To Reproduce

With datafusion-cli built from latest develop, and also from this arrow bump commit a407500:

> select cast(cast('5.20' as decimal(4,2)) as  decimal(3,2)), cast(cast(5.20 as decimal(4,2)) as  decimal(3,2));
+--------------+--------------+
| Utf8("5.20") | Float64(5.2) |
+--------------+--------------+
| 5.21         | 5.21         |
+--------------+--------------+
1 row(s) fetched. 
Elapsed 0.007 seconds.

Expected behavior

With commit 3082ac6807d3bac1dae1e8fb31490d2aa1aec19d (pre- arrow bump):

DataFusion CLI v44.0.0
> select cast(cast('5.20' as decimal(4,2)) as  decimal(3,2)), cast(cast(5.20 as decimal(4,2)) as  decimal(3,2));
+--------------+--------------+
| Utf8("5.20") | Float64(5.2) |
+--------------+--------------+
| 5.20         | 5.20         |
+--------------+--------------+
1 row(s) fetched. 
Elapsed 0.017 seconds.

Additional context

Couple other examples:

> select cast(cast('5.20' as decimal(5,3)) as  decimal(4,3)) as a, cast(cast('5.20' as decimal(5,2)) as  decimal(3,2)) as b, cast(cast('5.20' as decimal(5,3)) as  decimal(4,2)) as c;
+-------+------+------+
| a     | b    | c    |
+-------+------+------+
| 5.201 | 5.21 | 5.20 |
+-------+------+------+
1 row(s) fetched. 
> select cast(cast('5.20' as decimal(4,2)) as  decimal(2,2));
Arrow error: Invalid argument error: 521 is too large to store in a Decimal128 of precision 2. Max is 99
> select cast(cast('5.20' as decimal(5,3)) as  decimal(3,3));
Arrow error: Invalid argument error: 5201 is too large to store in a Decimal128 of precision 3. Max is 999

where does that additional +1 come from?

@Blizzara
Copy link
Contributor Author

Blizzara commented Feb 3, 2025

I reproed the issue in Arrow and filed a bug there as well: apache/arrow-rs#7069

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant