Skip to content

feat(spark): add distinct handling for Spark aggregate functions - #25384

Draft
mkleen wants to merge 1 commit into
apache:mainfrom
mkleen:spark-aggregate-distinct-handling
Draft

mkleen wants to merge 1 commit into
apache:mainfrom
mkleen:spark-aggregate-distinct-handling

Conversation

@mkleen

@mkleen mkleen commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

#25288 adds distinct handling to udfs, which let an aggregate declare whether DISTINCT can change its result. This pr adds distinct handling on the Spark aggregates to match what their accumulators actually do:

  • collect_set: Insensitive, the accumulator always deduplicates.
  • collect_list, try_sum: Unsupported, the accumulators ignore is_distinct and silently return the non-distinct result.
  • avg: Unsupported, the accumulator rejects DISTINCT with an error.

What changes are included in this PR?

see above.

What is the testing strategy for this PR?

  • Unit tests
  • slt

Are there any user-facing changes?

No

LLM-generated code disclosure

This PR includes LLM-generated code and comments. All LLM-generated content has been manually reviewed.

Override `AggregateUDFImpl::distinct_handling` on the Spark aggregates to
match what their accumulators actually do:

- `collect_set`: `Insensitive`, the accumulator always deduplicates, so
  `EliminateAggregateDistinct` can drop a redundant `DISTINCT`.
- `collect_list`, `try_sum`: `Unsupported`, the accumulators ignore
  `is_distinct` and silently return the non-distinct result.
- `avg`: `Unsupported`, the accumulator rejects `DISTINCT` with an error.

Adds unit tests asserting each function's tag and a sqllogictest showing
`collect_set(DISTINCT x)` is planned as `collect_set(x)`.

Closes apache#25375

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@github-actions github-actions Bot added sqllogictest SQL Logic Tests (.slt) spark labels Sep 16, 2026
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.93%. Comparing base (140c7c5) to head (ed513cb).

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #25384   +/-   ##
=======================================
  Coverage   81.93%   81.93%           
=======================================
  Files        1136     1136           
  Lines      429152   429180   +28     
  Branches   429152   429180   +28     
=======================================
+ Hits       351633   351669   +36     
+ Misses      56475    56466    -9     
- Partials    21044    21045    +1     

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

@mkleen mkleen changed the title feat(spark): report distinct_handling for Spark aggregate functions feat(spark): add distinct handling for Spark aggregate functions Sep 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

spark sqllogictest SQL Logic Tests (.slt)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Spark aggregate functions do not report distinct_handling

2 participants