Skip to content

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

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

Mola-maker wants to merge 1 commit into
apache:mainfrom
Mola-maker:fix/55575-substrait-ddof

Conversation

@Mola-maker

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

Copy link
Copy Markdown

Fixes #55575.

DecodeBasicAggregate mapped Substrait's distribution option backwards for variance and std_dev: POPULATION got ddof = 1 and SAMPLE got ddof = 0. VarianceOptions divides by N - ddof, so population needs ddof = 0 and sample needs ddof = 1. This swaps the two values; stddev shares the same code path.

Tests: corrected SubstraitRoundTrip.AggregateRelOptions (it encoded the buggy behavior) and added AggregateRelOptionsSample, AggregateRelVarianceSingleRowGroup, and AggregateRelVarianceSingleRowGroupSample (single-row group: 0.0 for POPULATION, NULL for SAMPLE).

Verification (fork CI, run 43289990482): arrow-substrait-substrait-test passed in the ASAN UBSAN and ARM64 jobs (113/113 in the latter). The run's overall failure is two unrelated issues: the Conda AVX2 job fails to link flight-grpc-example (mold: undefined symbol absl::lts_20240722::Mutex::Dtor()), and the ASAN job's only failing test is arrow-azurefs-test (Azurite emulator failed to start, Node ERR_REQUIRE_ESM).

…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!

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.

[Python][C++][Substrait] DecodeBasicAggregate inverts POPULATION (ddof=1) and SAMPLE (ddof=0) for variance and std_dev

2 participants