Repository navigation
fix: track struct array memory correctly on EmitTo::First in MinMaxStructState (#26891) - #26906
Open
lucasmeyer-dev wants to merge 2 commits into
Open
lucasmeyer-dev wants to merge 2 commits into
lucasmeyer-dev wants to merge 2 commits into
Conversation
…ructState (apache#26891) In `MinMaxStructState::emit_to`, emitting groups via `EmitTo::First(n)` previously computed `first_data_capacity` by summing `s.len()` for each emitted struct array. Because each group stores a 1-row `StructArray`, `s.len()` evaluated to 1, causing the byte subtraction from `total_data_bytes` to only decrease by row counts instead of the actual array memory allocated by `get_array_memory_size()`. This caused memory accounting in `MinMaxStructState` to retain phantom bytes across emitted groups during ordered/streaming aggregations, eventually triggering `ResourcesExhausted` in memory-bounded execution streams. Fix this by summing `s.get_array_memory_size()` on the emitted struct arrays, mirroring the allocation logic in `set_value`, and add a regression unit test verifying accurate memory decrement and zero residual bytes upon full emission. Closes apache#26891 Signed-off-by: Lucas Meyer <[email protected]>
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?
Closes #26891.
Rationale for this change
When emitting groups via
EmitTo::First(n)inMinMaxStructState, memory tracking subtracteds.len()for each emitted group instead of the actual array memory size. Since each group holds a single-rowStructArray,total_data_bytesonly decreased by 1 byte per group, causing memory usage to remain accounted for after emission.What changes are included in this PR?
MinMaxStructState::emit_to, sums.get_array_memory_size()across emitted structs when handlingEmitTo::First(n).test_min_max_struct_state_emit_to_first_memory_accountingto verify memory reduction on partial emission.What is the testing strategy for this PR?
test_min_max_struct_state_emit_to_first_memory_accountingindatafusion/functions-aggregate/src/min_max/min_max_struct.rs.Are there any user-facing changes?
No.