Unify AVG group state conversion and filter handling across Spark and built-in accumulators#22639
Open
kosiew wants to merge 4 commits into
Open
Unify AVG group state conversion and filter handling across Spark and built-in accumulators#22639kosiew wants to merge 4 commits into
kosiew wants to merge 4 commits into
Conversation
…rk integration - Added shared helper for average calculations in `avg.rs` with conversion to average state. - Exported the aggregate module in `groups_accumulator.rs`. - Updated Spark's average function to maintain state order and count type. - Added tests for common helper null/filter semantics and Spark null filter cases.
…ve data type integrity - Updated built-in Avg to utilize shared `convert_to_avg_state`. - Ensured the order of state is preserved as [count, sum]. - Maintained count type as UInt64. - Ensured sum data type consistency for Decimal and Duration. Added tests for: - Float64: validating count/sum order and null filter semantics. - Decimal128: checking sum type and input null semantics. - DurationNanosecond: verifying sum type and filter semantics.
- Added assert_validity test helpers for improved validation in tests - Reduced repeated null assertions to streamline code - Shortened common helper tests using local imports and type aliasing - Introduced built-in Avg avg_state test helper - Added comment for decimal test closure to clarify the unused avg_fn by convert_to_state
…lter - Implemented logic to skip false and NULL values in merge_batch. - Maintained skipping of null converted state rows. - Added regression test: merge_batch_applies_filter. - Introduced spark_avg_state test helper for better testing. - Refactored code to eliminate repeated state[0]/state[1] decode boilerplate.
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?
Rationale for this change
Spark AVG and the built-in AVG implementations maintained separate logic for converting input values into group-accumulator state, including null and filter handling. This duplication increased the risk of behavioral divergence and made maintenance more difficult.
This change introduces a shared helper for AVG state conversion and aligns null/filter semantics across both implementations. It also ensures that Spark AVG applies filters consistently during state merges, reducing the chance of discrepancies between the two implementations.
What changes are included in this PR?
Added a shared AVG state conversion helper in
functions-aggregate-common:groups_accumulator::avg::convert_to_avg_stateRefactored the built-in AVG implementation to use the shared helper instead of maintaining local null-mask and state-conversion logic.
Refactored the Spark AVG implementation to use the same shared helper for
convert_to_state.Updated Spark AVG
merge_batchto skip rows that are:NULLfilter values).Preserved implementation-specific state ordering:
[count, sum][sum, count]Added regression tests covering:
Are these changes tested?
Yes.
New unit tests were added for the shared helper and both AVG implementations:
functions-aggregate-commonconvert_to_avg_state_applies_input_nulls_to_sum_and_countconvert_to_avg_state_applies_filter_nulls_to_sum_and_countconvert_to_avg_state_preserves_sum_data_typeBuilt-in AVG (
functions-aggregate)float64_convert_to_state_uses_count_sum_order_and_null_filterdecimal_convert_to_state_preserves_sum_type_and_nullsduration_convert_to_state_preserves_sum_type_and_applies_filterSpark AVG
convert_to_state_with_null_filtermerge_batch_applies_filterExisting AVG tests continue to validate state round-tripping and related behavior.
Are there any user-facing changes?
No user-facing changes are intended. This PR refactors and aligns internal AVG group-accumulator state handling and adds regression coverage for null and filter semantics.
LLM-generated code disclosure
This PR includes LLM-generated code and comments. All LLM-generated content has been manually reviewed and tested.