Skip to content

Document decimal AVG wrapping arithmetic#23685

Open
sakshichitnis27 wants to merge 1 commit into
apache:mainfrom
sakshichitnis27:issue-23665-decimal-avg-helpers
Open

Document decimal AVG wrapping arithmetic#23685
sakshichitnis27 wants to merge 1 commit into
apache:mainfrom
sakshichitnis27:issue-23665-decimal-avg-helpers

Conversation

@sakshichitnis27

Copy link
Copy Markdown

Which issue does this PR close?

Rationale for this change

Decimal AVG intentionally uses wrapping arithmetic with a widened intermediate sum type. The existing direct add_wrapping and sub_wrapping calls made that invariant difficult to audit.

What changes are included in this PR?

  • Added small private helpers documenting the widened/headroom contract.
  • Updated scalar, grouped, merge, retract, and AVG(DISTINCT) decimal paths to use the helpers.
  • Kept the existing state types, return types, and arithmetic behavior unchanged.

Are these changes tested?

  • cargo fmt --all -- --check
  • cargo test -p datafusion-functions-aggregate avg --lib
  • cargo test -p datafusion-functions-aggregate-common avg_distinct --lib
  • cargo clippy -p datafusion-functions-aggregate-common --all-targets -- -D warnings

Are there any user-facing changes?

No.

@github-actions github-actions Bot added the functions Changes to functions implementation label Jul 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

functions Changes to functions implementation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Document decimal AVG wrapping arithmetic behind explicit helpers

1 participant