`avg` over `Duration` panics with "attempt to add with overflow" in debug builds
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 78/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- rust
- Domain
- data-engineering
Research direction
Start in datafusion/functions-aggregate/src/average.rs and inspect DurationAvgAccumulator::update_batch, merge_batch, and retract_batch alongside add_avg_sum. Run the provided debug-build datafusion-cli SQL reproduction, then verify that duration averages wrap on overflow like sum and the other avg accumulators without panicking.
Written by the indexing model from the issue text.
Description
Describe the bug
DurationAvgAccumulator (datafusion/functions-aggregate/src/average.rs) keeps its running sum with plain += in update_batch / merge_batch and plain - in retract_batch. When the sum of the input durations does not fit in i64 this panics in debug builds and wraps silently in release builds.
The sum aggregate and the other avg accumulators deliberately wrap on overflow (see the comment on add_avg_sum: "Wraps on overflow, matching the sum aggregate and arrow::compute::sum"), so the Duration accumulator is the odd one out.
To Reproduce
Debug build of datafusion-cli:
SELECT avg(x) OVER (ROWS BETWEEN 1 PRECEDING AND CURRENT ROW)
FROM (VALUES (arrow_cast(9223372036854775807, 'Duration(Second)')),
(arrow_cast(9223372036854775807, 'Duration(Second)'))) t(x);
thread 'main' panicked at datafusion/functions-aggregate/src/average.rs:887:13:
attempt to add with overflow
The plain aggregate SELECT avg(x) FROM ... with the same values hits the same line.
Expected behavior
Consistent with sum and the other avg accumulators: wrap, never panic.
Additional context
Found while running a corpus of extreme-value literals against a debug build of datafusion-cli.
- Dominant language
- Rust
- Stars
- 9.3k
- Forks
- 2.4k
- Avg merge
- 3d 8h
- Merged PRs (30d)
- 354
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from apache/datafusion
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
apache/datafusion#25266 · 2 comments ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
apache/datafusion#25213 · 1 comment ·
-
documentation
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
apache/datafusion#25168 · 1 comment ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
apache/datafusion#24998 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
apache/datafusion#24913 ·
All issues in apache/datafusion
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
Eynzof/Hermes-CN-Desktop#610 ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
gitbutlerapp/gitbutler#15998 · 1 comment ·
-
bug triage:deciding
Difficulty 1/5 Under an hour Newbie friendliness 88/100
open-telemetry/otel-arrow#4132 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100