Skip to content

Commit

Permalink
rename methods and update docs
Browse files Browse the repository at this point in the history
Signed-off-by: remzi <13716567376yh@gmail.com>
  • Loading branch information
HaoYang670 committed Jul 26, 2022
1 parent 0895a80 commit 49c963c
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 32 deletions.
8 changes: 4 additions & 4 deletions arrow/src/array/builder/boolean_builder.rs
Expand Up @@ -84,20 +84,20 @@ impl BooleanBuilder {
#[inline]
pub fn append_value(&mut self, v: bool) {
self.values_builder.append(v);
self.null_buffer_builder.append_true();
self.null_buffer_builder.append_non_null();
}

/// Appends a null slot into the builder
#[inline]
pub fn append_null(&mut self) {
self.null_buffer_builder.append_false();
self.null_buffer_builder.append_null();
self.values_builder.advance(1);
}

/// Appends `n` `null`s into the builder.
#[inline]
pub fn append_nulls(&mut self, n: usize) {
self.null_buffer_builder.append_n_false(n);
self.null_buffer_builder.append_n_nulls(n);
self.values_builder.advance(n);
}

Expand All @@ -114,7 +114,7 @@ impl BooleanBuilder {
#[inline]
pub fn append_slice(&mut self, v: &[bool]) {
self.values_builder.append_slice(v);
self.null_buffer_builder.append_n_true(v.len());
self.null_buffer_builder.append_n_non_nulls(v.len());
}

/// Appends values from a slice of type `T` and a validity boolean slice.
Expand Down
4 changes: 2 additions & 2 deletions arrow/src/array/builder/fixed_size_binary_builder.rs
Expand Up @@ -64,7 +64,7 @@ impl FixedSizeBinaryBuilder {
))
} else {
self.values_builder.append_slice(value.as_ref());
self.null_buffer_builder.append_true();
self.null_buffer_builder.append_non_null();
Ok(())
}
}
Expand All @@ -74,7 +74,7 @@ impl FixedSizeBinaryBuilder {
pub fn append_null(&mut self) {
self.values_builder
.append_slice(&vec![0u8; self.value_length as usize][..]);
self.null_buffer_builder.append_false();
self.null_buffer_builder.append_null();
}

/// Builds the [`FixedSizeBinaryArray`] and reset this builder.
Expand Down
47 changes: 26 additions & 21 deletions arrow/src/array/builder/null_buffer_builder.rs
Expand Up @@ -43,51 +43,56 @@ impl NullBufferBuilder {
}
}

/// Appends `n` `true`s into the builder.
/// Appends `n` `true`s into the builder
/// to indicate that these `n` items are not nulls.
#[inline]
pub fn append_n_true(&mut self, n: usize) {
pub fn append_n_non_nulls(&mut self, n: usize) {
if let Some(buf) = self.bitmap_builder.as_mut() {
buf.append_n(n, true)
} else {
self.len += n;
}
}

/// Appends a `true` into the builder.
/// Appends a `true` into the builder
/// to indicate that this item is not null.
#[inline]
pub fn append_true(&mut self) {
pub fn append_non_null(&mut self) {
if let Some(buf) = self.bitmap_builder.as_mut() {
buf.append(true)
} else {
self.len += 1;
}
}

/// Appends `n` `false`s into the builder.
/// Appends `n` `false`s into the builder
/// to indicate that these `n` items are nulls.
#[inline]
pub fn append_n_false(&mut self, n: usize) {
pub fn append_n_nulls(&mut self, n: usize) {
self.materialize_if_needed();
self.bitmap_builder.as_mut().unwrap().append_n(n, false);
}

/// Appends a `false` into the builder.
/// Appends a `false` into the builder
/// to indicate that this item is null.
#[inline]
pub fn append_false(&mut self) {
pub fn append_null(&mut self) {
self.materialize_if_needed();
self.bitmap_builder.as_mut().unwrap().append(false);
}

/// Appends a boolean value into the builder.
#[inline]
pub fn append(&mut self, v: bool) {
if v {
self.append_true()
pub fn append(&mut self, not_null: bool) {
if not_null {
self.append_non_null()
} else {
self.append_false()
self.append_null()
}
}

/// Appends a boolean slice into the builder.
/// Appends a boolean slice into the builder
/// to indicate the validations of these items.
pub fn append_slice(&mut self, slice: &[bool]) {
if slice.iter().any(|v| !v) {
self.materialize_if_needed()
Expand Down Expand Up @@ -146,10 +151,10 @@ mod tests {
#[test]
fn test_null_buffer_builder() {
let mut builder = NullBufferBuilder::new(0);
builder.append_false();
builder.append_true();
builder.append_n_false(2);
builder.append_n_true(2);
builder.append_null();
builder.append_non_null();
builder.append_n_nulls(2);
builder.append_n_non_nulls(2);
assert_eq!(6, builder.len());

let buf = builder.finish().unwrap();
Expand All @@ -159,8 +164,8 @@ mod tests {
#[test]
fn test_null_buffer_builder_all_nulls() {
let mut builder = NullBufferBuilder::new(0);
builder.append_false();
builder.append_n_false(2);
builder.append_null();
builder.append_n_nulls(2);
builder.append_slice(&[false, false, false]);
assert_eq!(6, builder.len());

Expand All @@ -171,8 +176,8 @@ mod tests {
#[test]
fn test_null_buffer_builder_no_null() {
let mut builder = NullBufferBuilder::new(0);
builder.append_true();
builder.append_n_true(2);
builder.append_non_null();
builder.append_n_non_nulls(2);
builder.append_slice(&[true, true, true]);
assert_eq!(6, builder.len());

Expand Down
10 changes: 5 additions & 5 deletions arrow/src/array/builder/primitive_builder.rs
Expand Up @@ -81,20 +81,20 @@ impl<T: ArrowPrimitiveType> PrimitiveBuilder<T> {
/// Appends a value of type `T` into the builder
#[inline]
pub fn append_value(&mut self, v: T::Native) {
self.null_buffer_builder.append_true();
self.null_buffer_builder.append_non_null();
self.values_builder.append(v);
}

/// Appends a null slot into the builder
#[inline]
pub fn append_null(&mut self) {
self.null_buffer_builder.append_false();
self.null_buffer_builder.append_null();
self.values_builder.advance(1);
}

#[inline]
pub fn append_nulls(&mut self, n: usize) {
self.null_buffer_builder.append_n_false(n);
self.null_buffer_builder.append_n_nulls(n);
self.values_builder.advance(n);
}

Expand All @@ -110,7 +110,7 @@ impl<T: ArrowPrimitiveType> PrimitiveBuilder<T> {
/// Appends a slice of type `T` into the builder
#[inline]
pub fn append_slice(&mut self, v: &[T::Native]) {
self.null_buffer_builder.append_n_true(v.len());
self.null_buffer_builder.append_n_non_nulls(v.len());
self.values_builder.append_slice(v);
}

Expand Down Expand Up @@ -142,7 +142,7 @@ impl<T: ArrowPrimitiveType> PrimitiveBuilder<T> {
.1
.expect("append_trusted_len_iter requires an upper bound");

self.null_buffer_builder.append_n_true(len);
self.null_buffer_builder.append_n_non_nulls(len);
self.values_builder.append_trusted_len_iter(iter);
}

Expand Down

0 comments on commit 49c963c

Please sign in to comment.