Skip to content

Commit 0ee0772

Browse files
committed
fix(test): correct initial-state assertions in allocation accounting test
GroupValuesPrimitive::new() calls HashTable::with_capacity(128), which immediately reserves backing storage. The previous assertions treated the map as unallocated (capacity == 0, allocation_size == 0), causing the test to fail on the very first check. Instead, capture the actual nonzero initial allocation_size() returned by the constructor and assert that: - map.capacity() >= 128 (matching the with_capacity argument) - allocation_size() > 0 (pre-allocation is real) - size() == values.allocated_size() + initial_map_bytes This makes the focused regression test pass while still exercising the exact accounting that the broader fix (using allocation_size() instead of the naive capacity * size_of formula) is meant to validate.
1 parent 472fd7d commit 0ee0772

1 file changed

Lines changed: 15 additions & 4 deletions

File tree

  • datafusion/physical-plan/src/aggregates/group_values/single_group_by

‎datafusion/physical-plan/src/aggregates/group_values/single_group_by/primitive.rs‎

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -327,12 +327,23 @@ mod tests {
327327
fn test_exact_hash_table_allocation_accounting() -> Result<()> {
328328
let mut group_values = GroupValuesPrimitive::<Int32Type>::new(DataType::Int32);
329329

330-
// 1. Initial state: map is unallocated
331-
assert_eq!(group_values.map.capacity(), 0);
332-
assert_eq!(group_values.map.allocation_size(), 0);
330+
// 1. Initial state: the constructor calls HashTable::with_capacity(128),
331+
// so the map already has a nonzero retained allocation. Capture it
332+
// and verify that size() accounts for it correctly.
333+
let initial_map_bytes = group_values.map.allocation_size();
334+
assert!(
335+
group_values.map.capacity() >= 128,
336+
"expected initial capacity >= 128, got {}",
337+
group_values.map.capacity(),
338+
);
339+
assert!(
340+
initial_map_bytes > 0,
341+
"expected nonzero initial allocation_size, got 0",
342+
);
333343
assert_eq!(
334344
group_values.size(),
335-
group_values.values.allocated_size() + group_values.map.allocation_size()
345+
group_values.values.allocated_size() + initial_map_bytes,
346+
"size() must include the pre-allocated map bytes",
336347
);
337348

338349
// 2. Insert keys and observe table allocation growth

0 commit comments

Comments
 (0)