Skip to content

fix: reject groups accumulator for distinct bitwise aggregates - #24989

Open
jackylee-ch wants to merge 1 commit into
apache:mainfrom
jackylee-ch:fix-distinct-bitwise-groups-accumulator
Open

fix: reject groups accumulator for distinct bitwise aggregates#24989
jackylee-ch wants to merge 1 commit into
apache:mainfrom
jackylee-ch:fix-distinct-bitwise-groups-accumulator

Conversation

@jackylee-ch

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

  • N/A

Rationale for this change

bit_xor(DISTINCT c) with GROUP BY fails with Invalid argument error: column types must match schema types, expected List(Int16) but found Int16. groups_accumulator_supported ignored is_distinct, so the plan got the non-distinct PrimitiveGroupsAccumulator while state_fields declared the distinct List state. XOR is also not idempotent, so duplicates change the result: 5 ^ 5 ^ 9 = 9 but 5 ^ 9 = 12.

What changes are included in this PR?

groups_accumulator_supported now returns !args.is_distinct, matching sum, avg and count.

What is the testing strategy for this PR?

Two aggregate.slt queries covering the two shapes SingleDistinctToGroupBy does not rewrite (a non-distinct aggregate alongside, and a FILTER). Both fail on main with the error above and pass with this change.

Are there any user-facing changes?

bit_and/bit_or/bit_xor with DISTINCT and GROUP BY now return correct results. No API change.

@github-actions github-actions Bot added sqllogictest SQL Logic Tests (.slt) functions Changes to functions implementation labels Sep 6, 2026
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.67%. Comparing base (5b389eb) to head (c779379).

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #24989      +/-   ##
==========================================
- Coverage   81.67%   81.67%   -0.01%     
==========================================
  Files        1126     1126              
  Lines      414524   414524              
  Branches   414524   414524              
==========================================
- Hits       338558   338545      -13     
- Misses      56054    56062       +8     
- Partials    19912    19917       +5     

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

jayzhan211
jayzhan211 previously approved these changes Sep 7, 2026

@jayzhan211 jayzhan211 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.

Thanks @jackylee-ch 👍🏻

@jayzhan211
jayzhan211 dismissed their stale review September 7, 2026 12:50

Wait, I found an issue

fn groups_accumulator_supported(&self, _args: AccumulatorArgs) -> bool {
true
fn groups_accumulator_supported(&self, args: AccumulatorArgs) -> bool {
!args.is_distinct

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.

Should we limit operator to XOR only, since AND and OR are idempotent so DISTINCT does not change their result and they keep the vectorized path.

Also, do we need to handle null case? This could be a follow-up issue

Suggested change
!args.is_distinct
!(args.is_distinct && self.operation == BitwiseOperationType::Xor)

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

Labels

functions Changes to functions implementation sqllogictest SQL Logic Tests (.slt)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants