Jefffrey commented on code in PR #7013:
URL: https://github.com/apache/arrow-rs/pull/7013#discussion_r1929186012
##########
arrow-buffer/src/builder/null.rs:
##########
@@ -134,6 +133,42 @@ impl NullBufferBuilder {
}
}
+ /// Returns the capacity of the buffer
+ #[inline]
+ pub fn capacity(&self) -> usize {
+ if let Some(buf) = self.bitmap_builder.as_ref() {
+ buf.capacity()
+ } else {
+ 0
+ }
+ }
+
+ /// Gets a bit in the buffer at `index`
+ #[inline]
+ pub fn is_valid(&mut self, index: usize) -> bool {
+ if let Some(buf) = self.bitmap_builder.as_mut() {
+ buf.get_bit(index)
+ } else {
+ true
+ }
+ }
+
+ /// Truncates the builder to the given length
+ ///
+ /// If `len` is greater than the buffer's current length, this has no
effect
+ #[inline]
+ pub fn truncate(&mut self, len: usize) {
+ if len > self.len {
+ return;
+ }
Review Comment:
Consider this test case:
```rust
#[test]
fn test123() {
let mut builder = NullBufferBuilder::new(0);
assert_eq!(builder.len(), 0);
builder.append_n_nulls(2);
assert_eq!(builder.len(), 2);
builder.truncate(1);
assert_eq!(builder.len(), 1); // fails here
}
```
It would fail at the last assertion because it was materialized after
appending two nulls, but then truncating down to 1 is a noop since the internal
`self.len` stays 0 (not updated after materialization); `len > self.len` -> `1
> 0` -> true
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]