Repository navigation
fix: use HashTable::allocation_size() in GroupValuesColumn::size() - #26093
Draft
mohitgurav20 wants to merge 18 commits into
Draft
mohitgurav20 wants to merge 18 commits into
mohitgurav20 wants to merge 18 commits into
Conversation
…te_record_batch_view_buffers
…s://github.com/mohitgurav20/datafusion into fix/dedup-stringview-buffers-collectleft-joins
Address Codecov partial/missing coverage gaps identified in PR review: - test_dedup_view_array_zero_buffers_is_noop: covers the early-return path in deduplicate_view_array_buffers when data_buffers is empty (all inline). - test_dedup_view_array_mixed_inline_long_and_nulls: exercises the view rewriting loop with a mix of long strings (>12 bytes, non-inline), short inline strings, and null entries — covering the inline-skip branch and null buffer preservation together. - test_dedup_view_array_binary_view_direct: validates the same deduplication logic on BinaryViewArray directly (distinct from the Utf8View path). - test_dedup_record_batch_mixed_view_and_non_view_columns: ensures deduplicate_record_batch_view_buffers deduplicates both Utf8View and BinaryView columns while Arc-cloning non-view columns (Int32, Utf8) unchanged — covering the _ => Arc::clone(col) arm. - test_concat_build_batches_reverse_order_deduplication: calls concat_build_batches with reverse=true and 4 batches (two pairs of duplicates), verifying reversed row order and that 4 raw buffer handles collapse to 2 unique buffers after deduplication. Enhanced concat_build_batches_deduplicates_view_buffers and concat_build_batches_deduplicates_binary_view_buffers to include inline values, null entries, and non-view (Int32) columns. Expanded concat_build_batches_deduplicates_slices_regression from 2 to 4 batches so has_duplicates is true and the deduplication code path actually runs.
… path Two targeted fixes to push patch coverage toward 100%: 1. Remove uncovered error branches from test_concat_build_batches_reverse_order_deduplication. The previous version returned Result<()> and used ? on RecordBatch::try_new and concat_build_batches. Each ? generates two LLVM branches -- Ok (taken) and Err (never taken in tests) -- which Codecov reports as partial lines. Converting to () + .expect() collapses each call to a single branch, eliminating all partials. 2. Add test_concat_build_batches_grow_branch to exercise the retained > held path in concat_build_batches (line 2997). Prior tests always produced batches where deduplication shrank the retained size, so only the else/shrink branch at line 3001 was ever hit. The new test passes inputs_reserved = 0 directly, making held == 0, so any non-empty batch forces the try_grow call on line 2998.
…erage gaps Codecov reported multiple partial missing lines due to the Err branches of ? operators never being taken. By changing deduplicate_record_batch_view_buffers to return RecordBatch directly instead of Result<RecordBatch> (since RecordBatch::try_new with the same schema and matching column lengths cannot fail), we eliminate the ? operator at the call site in concat_build_batches. We also remove the unneeded .unwrap() calls from the test assertions.
Fixes apache#25736 The previous implementation tracked map memory via a map_size: usize field that was updated incrementally using insert_accounted. That approach charges only the entry-capacity portion of the hashbrown allocation, silently omitting control bytes and trailing layout. The resulting GroupValues::size() underreports the true retained memory, particularly for small or recently grown tables. This commit replaces the approximate accounting with a direct call to HashTable::allocation_size(), which reports the complete allocation as observed by the allocator. This is the same approach already used by ArrowBytesMap::size() in physical-expr-common. Changes: - Remove the map_size: usize field and all insert_accounted call sites that maintained it; use insert_unique (the plain hashbrown insert) instead. - Remove the now-unused HashTableAllocExt import from the production path (the test module retains what it still needs). - Remove the size_of import that was only used in the deleted clear_shrink map_size update. - Update GroupValuesColumn::size() to use self.map.allocation_size(). - Add four focused unit tests covering the acceptance criteria from the issue: map growth accounting, forced-collision chain independence, retained capacity after partial emit, and correct reuse after full emit.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #26093 +/- ##
==========================================
+ Coverage 82.72% 82.74% +0.01%
==========================================
Files 1147 1147
Lines 448179 448753 +574
Branches 448179 448753 +574
==========================================
+ Hits 370754 371318 +564
- Misses 54895 54899 +4
- Partials 22530 22536 +6 ☔ 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?
GroupValuesColumn#25736Rationale for this change
GroupValuesColumnstores its hash map as aHashTable<(u64, GroupIndexView)>,but
size()was computing the map's contribution using a hand-maintainedmap_sizefield — incremented viainsert_accountedon every insert.That only accounts for the raw entry storage, not hashbrown's internal
control bytes or trailing layout padding.
The result:
GroupValues::size()quietly underreports real memory,especially right after a table growth. This weakens memory-pool
enforcement and spill decisions.
ArrowBytesMapalready solves this correctly withHashTable::allocation_size().This PR brings
GroupValuesColumnin line with that.What changes are included in this PR?
Only
datafusion/physical-plan/src/aggregates/group_values/multi_group_by/mod.rsis touched.map_size: usizefield and everyinsert_accountedcall that maintained itinsert_accountedwithinsert_unique(hashbrown's plain insert) — no behavioural change, just stops threading an accumulator throughGroupValuesColumn::size()now callsself.map.allocation_size()directly, matchingArrowBytesMap::size()HashTableAllocExt,size_ofWhat is the testing strategy for this PR?
Four focused unit tests added, one per acceptance criterion from the issue:
map_allocation_size_included_in_size_after_growthsize()covers the fullallocation_size()collision_chain_size_is_separate_from_map_allocationgroup_index_listsare tracked independentlysize_reflects_retained_capacity_after_partial_emitEmitTo::Firstdoesn't shrink the map allocation — retained capacity stays chargedreuse_after_full_emit_produces_correct_groupssize()stays accurateAll 116 tests in
aggregates::group_values::multi_group_bypass locally.Are there any user-facing changes?
No. This is a memory-accounting fix only. Group values, group IDs, and query
results are completely unchanged.