Apache DataFusion SQL Query Engine
fix: `allocated_size` in `MaybeNullBufferBuilder` returns incorrect value (#24605)
Raz Luvaton0bda11f37e95
diff --git a/datafusion/physical-plan/src/aggregates/group_values/null_builder.rs b/datafusion/physical-plan/src/aggregates/group_values/null_builder.rsindex 6a84d685b6..cfde5e3c55 100644--- a/datafusion/physical-plan/src/aggregates/group_values/null_builder.rs+++ b/datafusion/physical-plan/src/aggregates/group_values/null_builder.rs@@ -63,8 +63,7 @@ impl MaybeNullBufferBuilder {/// return the number of heap allocated bytes used by this structure to store boolean valuespub fn allocated_size(&self) -> usize {- // NullBufferBuilder builder::allocated_size returns capacity in bits- self.nulls.allocated_size() / 8+ self.nulls.allocated_size()}/// Return a NullBuffer representing the accumulated nulls so far@@ -98,3 +97,19 @@ impl MaybeNullBufferBuilder {self.nulls.as_slice().is_some()}}++#[cfg(test)]+mod tests {+ use super::*;+ use arrow::array::BooleanBufferBuilder;++ #[test]+ fn allocated_size_should_return_bytes() {+ let mut expected = BooleanBufferBuilder::new(0);+ expected.append(true);+ let expected_capacity_in_bytes = expected.capacity() / 8;+ let mut builder = MaybeNullBufferBuilder::new();+ builder.append(true);+ assert_eq!(builder.allocated_size(), expected_capacity_in_bytes);+ }+}