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

DataFusion incorrectly handle precision overflow when casting from integer to decimal #5825

Closed
viirya opened this issue Apr 1, 2023 · 0 comments · Fixed by #6041
Closed
Assignees
Labels
bug Something isn't working

Comments

@viirya
Copy link
Member

viirya commented Apr 1, 2023

Describe the bug

When casting from integer to decimal, if casted decimal exceeds the precision, e.g. cast(1234567 as decimal(7,3)), DataFusion doesn't handle it so the returned decimal is invalid. Whilst in Spark, the cast expression will return a null value indicating it's overflowing.

This is due to current behavior of cast kernel in arrow-rs. Although it checks if division or multiplication overflows in such cast operation, it doesn't check precision overflow. This is somehow related to decimal operation convention in arrow-rs, that is let user handle invalid values in decimal arrays. But for cast kernel, because it provides CastOptions which defines null behavior for invalid case, the behavior of not checking precision overflow becomes a bit inconsistent.

Proposed a fix at the upstream: apache/arrow-rs#3996

We can add some tests in DataFusion after new arrow-rs is released.

To Reproduce

In datafusion-cli, run the following query:

❯ select cast(1234567 as decimal(7,3));
+----------------+
| Int64(1234567) |
+----------------+
| 1234.567       |
+----------------+
1 row in set. Query took 0.016 seconds.

Expected behavior

cast(1234567 as decimal(7,3)) should return null.

Additional context

No response

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
1 participant