Skip to content

Document and enforce compatibility between an aggregate's accumulators - #25710

Open
masonh22 wants to merge 11 commits into
apache:mainfrom
coralogix:agg-udf-accum-compat
Open

masonh22 wants to merge 11 commits into
apache:mainfrom
coralogix:agg-udf-accum-compat

Conversation

@masonh22

@masonh22 masonh22 commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

See #25660.

This change only documents/enforces this requirement for built-in aggregate UDF functions. Anyone who implements their own aggregate UDFs do not need to adhere to this requirement since vanilla datafusion doesn't require it. This does add a public test that user's can use to make sure this requirement is satisfied if they desire.

What changes are included in this PR?

This change adds:

  • Internal documentation explaining this requirement and how to check for it using the provided test function.
  • datafusion_functions_aggregate::testing::check_state_compatibility(): A generic test that identifies cases where the Accumulator and GroupsAccumulator of an AggregateUDF differ. This is exposed as a public function that can be used to test this requirement on AggregateUDFImpls implemented by downstream consumers. The test is run on all built-in default aggregation functions.
  • Fixes for approx_distinct() and avg(), which both violated this requirement

What is the testing strategy for this PR?

This adds a test to enforce this new requirement in a generic way.

Are there any user-facing changes?

This changes the intermediate state of the avg() accumulator to match the avg() groups accumulator, which some users may be affected by.

@github-actions github-actions Bot added the functions Changes to functions implementation label Sep 24, 2026
@masonh22
masonh22 force-pushed the agg-udf-accum-compat branch from eb9fcb7 to c3496a3 Compare October 5, 2026 17:16
@masonh22
masonh22 force-pushed the agg-udf-accum-compat branch from 99ca719 to 560040a Compare October 5, 2026 17:19
@masonh22
masonh22 force-pushed the agg-udf-accum-compat branch from 6c850b7 to 52043c8 Compare October 5, 2026 17:40
@masonh22 masonh22 changed the title Add a test to enforce compatibility between an aggregate's accumulators Document and enforce compatibility between an aggregate's accumulators Oct 5, 2026
@codecov-commenter

codecov-commenter commented Oct 5, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 75.80645% with 15 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.79%. Comparing base (8248a57) to head (5273fe3).
⚠️ Report is 71 commits behind head on main.

Files with missing lines Patch % Lines
...afusion/functions-aggregate/src/approx_distinct.rs 77.77% 7 Missing and 3 partials ⚠️
datafusion/functions-aggregate/src/average.rs 70.58% 4 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #25710      +/-   ##
==========================================
+ Coverage   82.66%   82.79%   +0.12%     
==========================================
  Files        1147     1147              
  Lines      446542   450917    +4375     
  Branches   446542   450917    +4375     
==========================================
+ Hits       369154   373318    +4164     
+ Misses      54986    54880     -106     
- Partials    22402    22719     +317     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions github-actions Bot added documentation Improvements or additions to documentation logical-expr Logical plan and expressions labels Oct 5, 2026
@masonh22 masonh22 changed the title Document and enforce compatibility between an aggregate's accumulators Document (internally) and enforce compatibility between an aggregate's accumulators Oct 7, 2026
@masonh22 masonh22 changed the title Document (internally) and enforce compatibility between an aggregate's accumulators Document and enforce compatibility between an aggregate's accumulators Oct 7, 2026
@masonh22
masonh22 marked this pull request as ready for review October 7, 2026 16:16
@masonh22

masonh22 commented Oct 7, 2026

Copy link
Copy Markdown
Contributor Author

@alamb tagging you because you might be interested in the optimization this enables, given that github considers you a contributor to Datafusion Query Cache

@alamb alamb left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @masonh22 and @thinkharderdev and @Dandandan

This looks like a nice improvement code and testing wise to me, though I am a little worried about the somewhat non standard testing feature (mostly that it add some tiny more amount of complexity to a system that is already pretty complicated).

I left some comments, but I also think this PR could be merged as is

Thank you for the cleanup 🙏

Comment thread docs/source/library-user-guide/upgrading/56.0.0.md Outdated
Comment thread datafusion/functions-aggregate/src/testing/state_compat.rs Outdated

@alamb alamb left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @masonh22

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation functions Changes to functions implementation logical-expr Logical plan and expressions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Document and enforce compatibility of the intermediate state produced by an AggregateUDFImpl's Accumulator and GroupsAccumulator

5 participants