fix: stabilize grouped correlation with centered moments - #24953
Draft
bvolpato wants to merge 1 commit into
Draft
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #24953 +/- ##
==========================================
- Coverage 81.61% 81.61% -0.01%
==========================================
Files 1124 1124
Lines 411978 412086 +108
Branches 411978 412086 +108
==========================================
+ Hits 336236 336318 +82
- Misses 55936 55941 +5
- Partials 19806 19827 +21 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
No linked issue. The regression below reproduces the problem on current upstream.
Rationale for this change
Grouped CORR uses raw sums whose subtraction loses precision when values have a large common offset. It can return a negative correlation for a column correlated with itself:
Group 1 can return
-1instead of1.What changes are included in this PR?
aggregate.slt.What is the testing strategy for this PR?
35f58f53cde2f634c21f6370e385cf1d7e9bc55cand pass with the fix.cargo test --locked -p datafusion-functions-aggregate --lib: 210 passed.cargo fmt --all -- --checkandgit diff --checkpassed.aggregate.slt.Are there any user-facing changes?
Grouped CORR produces stable results for the covered large-offset inputs. Floating-point results can differ in their final bits. SQL signatures and output types remain unchanged.
Downsides
Centered updates add arithmetic, including per-row divisions. The grouped intermediate state representation changes from raw sums to centered moments, so partial states produced by the old implementation cannot be mixed with the new representation.