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

   ### Describe the bug
   
   The current average implementation assumes that the sum of the values in 
`DecimalAverager` doesn't overflow for the Decimals underlying native type (i32 
for Decimal32 etc).
   The count is assumed to be a u64, so even an avg of `[1_i32; i32::MAX + 1]` 
will overflow.
   
   ### To Reproduce
   
   ```
   select avg(d), arrow_typeof(avg(d))
   from (
     select arrow_cast(99999, 'Decimal32(5, 0)') as d
     from generate_series(1, 21476)
   ) t;
   ```
   Currently fails with:
   ```
   query failed: DataFusion error: Execution error: Arithmetic Overflow in 
AvgAccumulator
   ```
   
   ### Expected behavior
   
   Averages shouldn't overflow on intermediate state and should also return 
correct results even if the intermediate state is bigger.
   
   ### Additional context
   
   _No response_


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