edubraqd opened a new pull request, #24899: URL: https://github.com/apache/datafusion/pull/24899
## Which issue does this PR close? - Closes #24898. ## Rationale for this change `DecimalAverager::try_new` computed `10^sum_scale` and `10^target_scale` separately with `pow_wrapping(scale as u32)`. For a negative scale the exponent wraps and the result is 0, so `avg` divided by zero and panicked for any decimal input with a negative scale. ## What changes are included in this PR? The two factors were only ever used as the ratio `10^(target_scale - sum_scale)`, so `DecimalAverager` now stores that single multiplier, computed from the scale difference. The existing `Arithmetic Overflow in AvgAccumulator` error for a target scale smaller than the sum scale is kept (it is now the `scale_diff < 0` check). ## Are these changes tested? Yes. `avg_decimal_negative_scale` averages `Decimal128(10, -2)` values and checks the `Decimal128(14, 2)` result; it used to panic. The existing `average` and `functions-aggregate-common` unit tests pass. ## Are there any user-facing changes? `avg` over decimals with a negative scale returns a result instead of panicking. -- 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]
