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
Describe the bug
The current average implementation assumes that the sum of the values in
DecimalAveragerdoesn'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
Currently fails with:
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