Skip to content

Commit

Permalink
fix: NullBufferBuilder::allocated_size should return Size in Bytes (#…
Browse files Browse the repository at this point in the history
…7122)

Co-authored-by: Shuoze Li <[email protected]>
  • Loading branch information
shuozel and Shuozeli authored Feb 12, 2025
1 parent 78c9df9 commit ef7d753
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions arrow-buffer/src/builder/null.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,11 @@ impl NullBufferBuilder {
self.bitmap_builder.as_mut().map(|b| b.as_slice_mut())
}

/// Return the allocated size of this builder, in bits, useful for memory accounting.
/// Return the allocated size of this builder, in bytes, useful for memory accounting.
pub fn allocated_size(&self) -> usize {
self.bitmap_builder
.as_ref()
.map(|b| b.capacity())
.map(|b| b.capacity() / 8)
.unwrap_or(0)
}
}
Expand Down Expand Up @@ -250,7 +250,7 @@ mod tests {
builder.append_n_nulls(2);
builder.append_n_non_nulls(2);
assert_eq!(6, builder.len());
assert_eq!(512, builder.allocated_size());
assert_eq!(64, builder.allocated_size());

let buf = builder.finish().unwrap();
assert_eq!(&[0b110010_u8], buf.validity());
Expand All @@ -263,7 +263,7 @@ mod tests {
builder.append_n_nulls(2);
builder.append_slice(&[false, false, false]);
assert_eq!(6, builder.len());
assert_eq!(512, builder.allocated_size());
assert_eq!(64, builder.allocated_size());

let buf = builder.finish().unwrap();
assert_eq!(&[0b0_u8], buf.validity());
Expand Down Expand Up @@ -327,7 +327,7 @@ mod tests {
builder.append_null();
builder.append_non_null();
assert_eq!(builder.as_slice().unwrap(), &[0xFF, 0b10111111]);
assert_eq!(builder.allocated_size(), 512);
assert_eq!(builder.allocated_size(), 64);
}

#[test]
Expand Down

0 comments on commit ef7d753

Please sign in to comment.