Blizzara opened a new issue, #14450:
URL: https://github.com/apache/datafusion/issues/14450

   ### 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 
https://github.com/apache/datafusion/issues/13492 / 
https://github.com/apache/arrow-rs/issues/6833
   
   Fyi @alamb @andygrove
   
   ### To Reproduce
   
   With datafusion-cli built from latest develop, and also from this arrow bump 
commit 
https://github.com/apache/datafusion/commit/a40750033e87b00dc9e12e19a64f64f42c027c1c:
   ```
   > 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?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org
For additional commands, e-mail: github-h...@datafusion.apache.org

Reply via email to