Skip to content

GH-55575: [C++][Substrait] Fix inverted ddof for POPULATION/SAMPLE in DecodeBasicAggregate - #55582

Open
Mola-maker wants to merge 2 commits into
apache:mainfrom
Mola-maker:fix/55575-substrait-ddof
Open

Mola-maker wants to merge 2 commits into
apache:mainfrom
Mola-maker:fix/55575-substrait-ddof

Conversation

@Mola-maker

@Mola-maker Mola-maker commented Nov 13, 2026 •

Copy link
Copy Markdown

Rationale for this change

DecodeBasicAggregate inverted the variance and std_dev distribution options for Substrait: POPULATION was mapped to ddof = 1 and SAMPLE to ddof = 0, causing calculation errors (such as returning NULL for single rows) due to the reversed N - ddof divisor.

What changes are included in this PR?

  • Fixed ddof mapping in DecodeBasicAggregate: POPULATION set to ddof = 0, SAMPLE set to ddof = 1.
  • Updated the SubstraitRoundTrip.AggregateRelOptions test case.
  • Added unit tests AggregateRelOptionsSample, AggregateRelVarianceSingleRowGroup, and AggregateRelVarianceSingleRowGroupSample for edge cases.

Are these changes tested?

Yes. Updated round-trip tests and added new unit tests and all 113 fork CI tasks (ASAN/UBSAN and ARM64) passed.

Are there any user-facing changes?

Yes. Fixed a bug where POPULATION and SAMPLE options were inverted when executing variance or std_dev in Substrait plans.

Was AI used for this PR?

AI tools helped furnishing my code.

PR code and description written by:

  • Human
  • AI

Reviewed before submission by:

  • Human
  • AI
  • Not reviewed

…PLE in DecodeBasicAggregate

DecodeBasicAggregate mapped POPULATION to ddof=1 and SAMPLE to ddof=0,
which is backwards: VarianceOptions uses N - ddof as the divisor, so
population variance needs ddof=0 and sample variance needs ddof=1.
The swap made a POPULATION request silently compute sample variance
(and return NULL on a 1-row group), and vice versa.

Fix the mapping and correct the AggregateRelOptions test, which encoded
the buggy behavior, and add coverage for the SAMPLE distribution and
for a single-row group (0.0 for POPULATION, NULL for SAMPLE). stddev
shares this code path, so it is fixed by the same change.
@github-actions

Copy link
Copy Markdown

⚠️ GitHub issue #55575 has been automatically assigned in GitHub to PR creator.

@Reranko05

Copy link
Copy Markdown
Collaborator

@Mola-maker Pls use ARROW PR template.

@Mola-maker

Copy link
Copy Markdown
Author

ok,I'll rewrite the pr tomorrow.Thanks!

@github-actions

Copy link
Copy Markdown

⚠️ GitHub issue #55575 has been automatically assigned in GitHub to PR creator.

@Mola-maker

Copy link
Copy Markdown
Author

@Reranko05 I've updated my PR &ready for review.Thanks!

@github-actions

Copy link
Copy Markdown

⚠️ GitHub issue #55575 has been automatically assigned in GitHub to PR creator.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants