Add NullBuffer::try_from_unsliced helper and refactor call sites#9411
Add NullBuffer::try_from_unsliced helper and refactor call sites#9411Eyad3skr wants to merge 2 commits intoapache:mainfrom
NullBuffer::try_from_unsliced helper and refactor call sites#9411Conversation
alamb
left a comment
There was a problem hiding this comment.
Thank you @Eyad3skr -- this looks nice to me
cc @liamzwbao in case you have time to help reivew
arrow-buffer/src/buffer/null.rs
Outdated
| pub fn buffer(&self) -> &Buffer { | ||
| self.buffer.inner() | ||
| } | ||
| /// Create a [`NullBuffer`] from an *unsliced* validity bitmap (`offset = 0`) of length `len`. |
There was a problem hiding this comment.
Could you also update this comment to reflect the offset is in bits (not bytes)? Mixing the units is a common mistake so making sure the documentation is as clear as possible would help
arrow-buffer/src/buffer/null.rs
Outdated
| /// Create a [`NullBuffer`] from an *unsliced* validity bitmap (`offset = 0`) of length `len`. | ||
| /// | ||
| /// Returns `None` if there are no nulls (all values valid). | ||
| pub fn try_from_unsliced(buffer: impl Into<Buffer>, len: usize) -> Option<Self> { |
There was a problem hiding this comment.
Maybe we should call it from_buffer? try_* probably should be reserved for functions that return a result, and its probably better to be direct that we're constructing directly from a buffer?
|
@alamb I guess there is nothing else to take care after anymore? maybe if someone can just trigger/approve the CI pipeline workflows left that would be awesome. |
Done! |
|
Seems like the CI is broken |
Implements a helper to replace the pattern of creating a
BooleanBufferfrom an unsliced validity bitmap and filtering by null count. Previously this was done withBooleanBuffer::new(...)plusSome(NullBuffer::new(...)).filter(|n| n.null_count() > 0);now it is a single call toNullBuffer::try_from_unsliced(buffer, len), which returnsSome(NullBuffer)when there are nulls andNonewhen all values are valid.try_from_unslicedinarrow-buffer/src/buffer/null.rswith tests for nulls, all valid, all null, emptyFixedSizeBinaryArray::try_from_iter_with_sizeandtry_from_sparse_iter_with_sizeto use ittake_nullsinarrow-selectto use itCloses #9385