Skip to content

Commit

Permalink
Expose the null buffer of every builder that has one (#5754)
Browse files Browse the repository at this point in the history
  • Loading branch information
HadrienG2 committed May 13, 2024
1 parent 3566328 commit 7d465b8
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 0 deletions.
5 changes: 5 additions & 0 deletions arrow-array/src/builder/fixed_size_binary_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ impl FixedSizeBinaryBuilder {
let array_data = unsafe { array_data_builder.build_unchecked() };
FixedSizeBinaryArray::from(array_data)
}

/// Returns the current null buffer as a slice
pub fn validity_slice(&self) -> Option<&[u8]> {
self.null_buffer_builder.as_slice()
}
}

impl ArrayBuilder for FixedSizeBinaryBuilder {
Expand Down
5 changes: 5 additions & 0 deletions arrow-array/src/builder/fixed_size_list_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,11 @@ where

FixedSizeListArray::new(field, self.list_len, values, nulls)
}

/// Returns the current null buffer as a slice
pub fn validity_slice(&self) -> Option<&[u8]> {
self.null_buffer_builder.as_slice()
}
}

#[cfg(test)]
Expand Down
5 changes: 5 additions & 0 deletions arrow-array/src/builder/generic_bytes_dictionary_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,11 @@ where

DictionaryArray::from(unsafe { builder.build_unchecked() })
}

/// Returns the current null buffer as a slice
pub fn validity_slice(&self) -> Option<&[u8]> {
self.keys_builder.validity_slice()
}
}

impl<K: ArrowDictionaryKeyType, T: ByteArrayType, V: AsRef<T::Native>> Extend<Option<V>>
Expand Down
5 changes: 5 additions & 0 deletions arrow-array/src/builder/generic_bytes_view_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,11 @@ impl<T: ByteViewType + ?Sized> GenericByteViewBuilder<T> {
// SAFETY: valid by construction
unsafe { GenericByteViewArray::new_unchecked(views, completed, nulls) }
}

/// Returns the current null buffer as a slice
pub fn validity_slice(&self) -> Option<&[u8]> {
self.null_buffer_builder.as_slice()
}
}

impl<T: ByteViewType + ?Sized> Default for GenericByteViewBuilder<T> {
Expand Down
5 changes: 5 additions & 0 deletions arrow-array/src/builder/generic_list_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,11 @@ where
pub fn offsets_slice(&self) -> &[OffsetSize] {
self.offsets_builder.as_slice()
}

/// Returns the current null buffer as a slice
pub fn validity_slice(&self) -> Option<&[u8]> {
self.null_buffer_builder.as_slice()
}
}

impl<O, B, V, E> Extend<Option<V>> for GenericListBuilder<O, B>
Expand Down
5 changes: 5 additions & 0 deletions arrow-array/src/builder/map_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,11 @@ impl<K: ArrayBuilder, V: ArrayBuilder> MapBuilder<K, V> {

MapArray::from(array_data)
}

/// Returns the current null buffer as a slice
pub fn validity_slice(&self) -> Option<&[u8]> {
self.null_buffer_builder.as_slice()
}
}

impl<K: ArrayBuilder, V: ArrayBuilder> ArrayBuilder for MapBuilder<K, V> {
Expand Down
5 changes: 5 additions & 0 deletions arrow-array/src/builder/primitive_dictionary_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,11 @@ where
pub fn values_slice_mut(&mut self) -> &mut [V::Native] {
self.values_builder.values_slice_mut()
}

/// Returns the current null buffer as a slice
pub fn validity_slice(&self) -> Option<&[u8]> {
self.keys_builder.validity_slice()
}
}

impl<K: ArrowDictionaryKeyType, P: ArrowPrimitiveType> Extend<Option<P::Native>>
Expand Down
5 changes: 5 additions & 0 deletions arrow-array/src/builder/struct_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,11 @@ impl StructBuilder {
}
});
}

/// Returns the current null buffer as a slice
pub fn validity_slice(&self) -> Option<&[u8]> {
self.null_buffer_builder.as_slice()
}
}

#[cfg(test)]
Expand Down

0 comments on commit 7d465b8

Please sign in to comment.