Skip to content

Commit 7d465b8

Browse files
authored
Expose the null buffer of every builder that has one (#5754)
1 parent 3566328 commit 7d465b8

8 files changed

+40
-0
lines changed

arrow-array/src/builder/fixed_size_binary_builder.rs

+5
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,11 @@ impl FixedSizeBinaryBuilder {
115115
let array_data = unsafe { array_data_builder.build_unchecked() };
116116
FixedSizeBinaryArray::from(array_data)
117117
}
118+
119+
/// Returns the current null buffer as a slice
120+
pub fn validity_slice(&self) -> Option<&[u8]> {
121+
self.null_buffer_builder.as_slice()
122+
}
118123
}
119124

120125
impl ArrayBuilder for FixedSizeBinaryBuilder {

arrow-array/src/builder/fixed_size_list_builder.rs

+5
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,11 @@ where
208208

209209
FixedSizeListArray::new(field, self.list_len, values, nulls)
210210
}
211+
212+
/// Returns the current null buffer as a slice
213+
pub fn validity_slice(&self) -> Option<&[u8]> {
214+
self.null_buffer_builder.as_slice()
215+
}
211216
}
212217

213218
#[cfg(test)]

arrow-array/src/builder/generic_bytes_dictionary_builder.rs

+5
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,11 @@ where
299299

300300
DictionaryArray::from(unsafe { builder.build_unchecked() })
301301
}
302+
303+
/// Returns the current null buffer as a slice
304+
pub fn validity_slice(&self) -> Option<&[u8]> {
305+
self.keys_builder.validity_slice()
306+
}
302307
}
303308

304309
impl<K: ArrowDictionaryKeyType, T: ByteArrayType, V: AsRef<T::Native>> Extend<Option<V>>

arrow-array/src/builder/generic_bytes_view_builder.rs

+5
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,11 @@ impl<T: ByteViewType + ?Sized> GenericByteViewBuilder<T> {
146146
// SAFETY: valid by construction
147147
unsafe { GenericByteViewArray::new_unchecked(views, completed, nulls) }
148148
}
149+
150+
/// Returns the current null buffer as a slice
151+
pub fn validity_slice(&self) -> Option<&[u8]> {
152+
self.null_buffer_builder.as_slice()
153+
}
149154
}
150155

151156
impl<T: ByteViewType + ?Sized> Default for GenericByteViewBuilder<T> {

arrow-array/src/builder/generic_list_builder.rs

+5
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,11 @@ where
326326
pub fn offsets_slice(&self) -> &[OffsetSize] {
327327
self.offsets_builder.as_slice()
328328
}
329+
330+
/// Returns the current null buffer as a slice
331+
pub fn validity_slice(&self) -> Option<&[u8]> {
332+
self.null_buffer_builder.as_slice()
333+
}
329334
}
330335

331336
impl<O, B, V, E> Extend<Option<V>> for GenericListBuilder<O, B>

arrow-array/src/builder/map_builder.rs

+5
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,11 @@ impl<K: ArrayBuilder, V: ArrayBuilder> MapBuilder<K, V> {
226226

227227
MapArray::from(array_data)
228228
}
229+
230+
/// Returns the current null buffer as a slice
231+
pub fn validity_slice(&self) -> Option<&[u8]> {
232+
self.null_buffer_builder.as_slice()
233+
}
229234
}
230235

231236
impl<K: ArrayBuilder, V: ArrayBuilder> ArrayBuilder for MapBuilder<K, V> {

arrow-array/src/builder/primitive_dictionary_builder.rs

+5
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,11 @@ where
302302
pub fn values_slice_mut(&mut self) -> &mut [V::Native] {
303303
self.values_builder.values_slice_mut()
304304
}
305+
306+
/// Returns the current null buffer as a slice
307+
pub fn validity_slice(&self) -> Option<&[u8]> {
308+
self.keys_builder.validity_slice()
309+
}
305310
}
306311

307312
impl<K: ArrowDictionaryKeyType, P: ArrowPrimitiveType> Extend<Option<P::Native>>

arrow-array/src/builder/struct_builder.rs

+5
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,11 @@ impl StructBuilder {
381381
}
382382
});
383383
}
384+
385+
/// Returns the current null buffer as a slice
386+
pub fn validity_slice(&self) -> Option<&[u8]> {
387+
self.null_buffer_builder.as_slice()
388+
}
384389
}
385390

386391
#[cfg(test)]

0 commit comments

Comments
 (0)