You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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 forcast
kernel, because it providesCastOptions
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:
Expected behavior
cast(1234567 as decimal(7,3))
should return null.Additional context
No response
The text was updated successfully, but these errors were encountered: