fix: use zero sums for empty AVG partial buffers - #5420
Open
sunchao wants to merge 1 commit into
Open
Conversation
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.
Why are the changes needed?
Closes #5418.
Spark initializes AVG buffers with a zero sum and adds partial sums without coalescing nulls. Comet's empty scalar partial currently exports a null sum instead. In the supported native-partial / Spark-final path, empty scan partitions can therefore turn a nonempty AVG result into
NULL.Decimal AVG must also distinguish an empty buffer from an overflow marker. Changing empty state to zero must not revive an overflowed accumulator or make an all-empty final aggregate divide by zero.
What changes were proposed in this PR?
NULLand using errors in ANSI mode versusNULLin legacy/TRY mode for overflow.This does not change aggregate mixed-execution eligibility. The separate planner-safety issue is tracked in #5419.
How was this PR tested?
main: the new Spark regression returned[NULL, NULL]instead of[2.0, 11.000000]; four of the eight new native tests also failed.cargo test -p datafusion-comet-spark-expr --lib: 646 passed.CometAggregateSuitefiltered with-Dsuites='org.apache.comet.exec.CometAggregateSuite avg': 14 passed, including empty input, mixed execution, decimal overflow, and TRY coverage.cargo fmt --all -- --check, andgit diff --checkpassed.