Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Panic/correctness issue in variance GroupsAccumulator #12615

Merged

Conversation

eejbyfeldt
Copy link
Contributor

@eejbyfeldt eejbyfeldt commented Sep 25, 2024

Which issue does this PR close?

Closes #12616.

Rationale for this change

The bug was in the orginal implementation in #12095. This fixes the
issue and modify a test case such that it would have caught it.

Current code panics in debug builds and produces incorrect results in release.

What changes are included in this PR?

Use staturating_sub instead to correct the behavior.

Are these changes tested?

Modified test case.

Are there any user-facing changes?

No,

The bug was in the orginal implementation in apache#12095. This fixes the
issue and modify a test case such that it would have caught it.
@github-actions github-actions bot added sqllogictest SQL Logic Tests (.slt) functions labels Sep 25, 2024
@eejbyfeldt eejbyfeldt changed the title fix: Panic in variance GroupsAccumulator fix: Panic/correctness issue in variance GroupsAccumulator Sep 25, 2024
@eejbyfeldt eejbyfeldt marked this pull request as ready for review September 25, 2024 08:49
@@ -470,7 +470,7 @@ impl VarianceGroupsAccumulator {

if let StatsType::Sample = self.stats_type {
counts.iter_mut().for_each(|count| {
*count -= 1;
*count = count.saturating_sub(1);
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we return error if count is already 0?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, I think producing null is the expected behavior. Note that we use the counts to calculate the null array after this.

Copy link
Contributor

@jayzhan211 jayzhan211 left a comment

Choose a reason for hiding this comment

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

👍

@alamb alamb merged commit 61e6db3 into apache:main Sep 25, 2024
27 checks passed
@alamb
Copy link
Contributor

alamb commented Sep 25, 2024

Thanks @eejbyfeldt and @jayzhan211

bgjackma pushed a commit to bgjackma/datafusion that referenced this pull request Sep 25, 2024
The bug was in the orginal implementation in apache#12095. This fixes the
issue and modify a test case such that it would have caught it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
functions sqllogictest SQL Logic Tests (.slt)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Panic/correctness issue in variance GroupsAccumulator
3 participants