edubraqd opened a new pull request, #24897:
URL: https://github.com/apache/datafusion/pull/24897

   ## Which issue does this PR close?
   
   - Closes #24896.
   
   ## Rationale for this change
   
   `try_cast_numeric_literal` computes `10_i128.pow(scale as u32)` for both the 
literal's and the target's decimal scale. A negative scale wraps to a huge 
exponent, so simplifying `arrow_cast(1, 'Decimal128(10, -2)') = 100` panicked 
with "attempt to multiply with overflow" in the `unwrap_cast` simplifier.
   
   ## What changes are included in this PR?
   
   A negative scale means the decimal holds multiples of `10^-scale`, so the 
integer rescaling this path relies on does not apply. 
`try_cast_numeric_literal` now returns `None` when either side has a negative 
scale, so the simplifier leaves the cast in place, the same way it already does 
for other casts it cannot express.
   
   ## Are these changes tested?
   
   Yes. `test_try_cast_to_type_negative_scale_decimal` covers a negative-scale 
target for `Decimal32`/`Decimal64`/`Decimal128` and a negative-scale literal; 
each used to panic.
   
   ## Are there any user-facing changes?
   
   No panic. Such comparisons are no longer simplified by `unwrap_cast`; they 
were never simplified correctly before, since the process panicked.
   


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to