pub struct GenericBinaryArray<O: OffsetSizeTrait> { /* private fields */ }Expand description
A column of variable-length byte strings.
Use the BinaryArray and LargeBinaryArray aliases rather than naming
the offset parameter directly.
Implementations§
Source§impl<O: OffsetSizeTrait> GenericBinaryArray<O>
impl<O: OffsetSizeTrait> GenericBinaryArray<O>
Sourcepub fn try_new(
offsets: ScalarBuffer<O>,
values: Buffer,
validity: Option<Bitmap>,
) -> Result<Self>
pub fn try_new( offsets: ScalarBuffer<O>, values: Buffer, validity: Option<Bitmap>, ) -> Result<Self>
Builds an array from its three buffers, validating the offsets.
§Errors
- The offset errors listed on
validate_offsets. DataError::ValidityLengthMismatchwhen the bitmap length is wrong.
use astrs_data::array::{Array, BinaryArray};
use astrs_data::{Buffer, ScalarBuffer};
let array = BinaryArray::try_new(
ScalarBuffer::from_slice(&[0, 2, 5]),
Buffer::from_slice(b"aabbb"),
None,
)?;
assert_eq!(array.get(1), Some(&b"bbb"[..]));Sourcepub unsafe fn new_unchecked(
offsets: ScalarBuffer<O>,
values: Buffer,
validity: Option<Bitmap>,
) -> Self
pub unsafe fn new_unchecked( offsets: ScalarBuffer<O>, values: Buffer, validity: Option<Bitmap>, ) -> Self
Builds an array from its three buffers without validating offsets.
§Safety
This constructor is unsafe by contract, not by memory model: the
accessors stay memory-safe whatever the offsets say (they use checked
slicing and return None). Skipping validation means a malformed
buffer silently produces None values instead of a decode error, which
hides corruption. Only use it for offsets this crate itself produced —
for example when re-wrapping buffers taken out of another array.
Callers must guarantee that offsets holds len + 1 non-decreasing,
non-negative entries, all within values.len(), and that validity
(if present) covers exactly len slots.
Sourcepub fn from_values<V: AsRef<[u8]>>(values: impl IntoIterator<Item = V>) -> Self
pub fn from_values<V: AsRef<[u8]>>(values: impl IntoIterator<Item = V>) -> Self
Builds an array with no nulls from any iterator of byte slices.
use astrs_data::array::{Array, LargeBinaryArray};
let array = LargeBinaryArray::from_values([&b"one"[..], &b"two"[..]]);
assert_eq!(array.len(), 2);
assert_eq!(array.null_count(), 0);Sourcepub fn from_opt_iter<V: AsRef<[u8]>>(
values: impl IntoIterator<Item = Option<V>>,
) -> Self
pub fn from_opt_iter<V: AsRef<[u8]>>( values: impl IntoIterator<Item = Option<V>>, ) -> Self
Builds an array from optional byte slices.
Sourcepub fn value_offsets(&self) -> &[O]
pub fn value_offsets(&self) -> &[O]
The offset buffer, len + 1 entries.
Sourcepub const fn offsets_buffer(&self) -> &ScalarBuffer<O>
pub const fn offsets_buffer(&self) -> &ScalarBuffer<O>
The offset buffer as a shareable typed window.
GenericBinaryArray::value_offsets hands out a slice, which the IPC
encoder cannot put on the wire without copying it. This accessor lets
it clone the window instead — one atomic increment, no bytes moved.
use astrs_data::array::BinaryArray;
let array = BinaryArray::from_values([&b"ab"[..], &b"c"[..]]);
assert_eq!(array.offsets_buffer().as_slice(), &[0, 2, 3]);Sourcepub const fn value_data(&self) -> &Buffer
pub const fn value_data(&self) -> &Buffer
The flat value region every slot points into.
Sourcepub fn value(&self, index: usize) -> Option<&[u8]>
pub fn value(&self, index: usize) -> Option<&[u8]>
The raw slot bytes at index, ignoring validity.
Returns None only when index is out of range.
Sourcepub fn get(&self, index: usize) -> Option<&[u8]>
pub fn get(&self, index: usize) -> Option<&[u8]>
The logical value at index: None when the slot is null or out of
range.
Sourcepub fn value_length(&self, index: usize) -> Option<usize>
pub fn value_length(&self, index: usize) -> Option<usize>
Byte length of slot index, ignoring validity.
Sourcepub fn total_value_bytes(&self) -> usize
pub fn total_value_bytes(&self) -> usize
Total bytes the values occupy, across the whole array.
Sourcepub fn slice(&self, offset: usize, len: usize) -> Self
pub fn slice(&self, offset: usize, len: usize) -> Self
A zero-copy sub-range, clamped to the array (the crate-wide slicing convention).
Only the offset buffer is narrowed; the value region is shared as-is.
Sourcepub fn try_slice(&self, offset: usize, len: usize) -> Result<Self>
pub fn try_slice(&self, offset: usize, len: usize) -> Result<Self>
Checked GenericBinaryArray::slice.
§Errors
DataError::SliceOutOfBounds when the window leaves the array.
Sourcepub fn with_validity(&self, validity: Option<Bitmap>) -> Result<Self>
pub fn with_validity(&self, validity: Option<Bitmap>) -> Result<Self>
Returns a copy with a different validity bitmap.
§Errors
DataError::ValidityLengthMismatch when the bitmap length is wrong.
Trait Implementations§
Source§impl<O: OffsetSizeTrait> Array for GenericBinaryArray<O>
impl<O: OffsetSizeTrait> Array for GenericBinaryArray<O>
Source§fn as_any(&self) -> &dyn Any
fn as_any(&self) -> &dyn Any
ArrayExt::downcast.Source§fn validity(&self) -> Option<&Bitmap>
fn validity(&self) -> Option<&Bitmap>
None when every slot is valid. Read moreSource§fn buffer_memory_size(&self) -> usize
fn buffer_memory_size(&self) -> usize
Source§fn null_count(&self) -> usize
fn null_count(&self) -> usize
Source§impl<'a, O: OffsetSizeTrait> ArrayAccessor for &'a GenericBinaryArray<O>
impl<'a, O: OffsetSizeTrait> ArrayAccessor for &'a GenericBinaryArray<O>
Source§impl<O: Clone + OffsetSizeTrait> Clone for GenericBinaryArray<O>
impl<O: Clone + OffsetSizeTrait> Clone for GenericBinaryArray<O>
Source§impl<O: OffsetSizeTrait> Debug for GenericBinaryArray<O>
impl<O: OffsetSizeTrait> Debug for GenericBinaryArray<O>
impl<O: OffsetSizeTrait> Eq for GenericBinaryArray<O>
Source§impl<O: OffsetSizeTrait, V: AsRef<[u8]>> FromIterator<Option<V>> for GenericBinaryArray<O>
impl<O: OffsetSizeTrait, V: AsRef<[u8]>> FromIterator<Option<V>> for GenericBinaryArray<O>
Source§impl<'a, O: OffsetSizeTrait> IntoIterator for &'a GenericBinaryArray<O>
impl<'a, O: OffsetSizeTrait> IntoIterator for &'a GenericBinaryArray<O>
Source§impl<O: OffsetSizeTrait> PartialEq for GenericBinaryArray<O>
impl<O: OffsetSizeTrait> PartialEq for GenericBinaryArray<O>
Source§impl<O: OffsetSizeTrait> TryFrom<GenericBinaryArray<O>> for GenericStringArray<O>
impl<O: OffsetSizeTrait> TryFrom<GenericBinaryArray<O>> for GenericStringArray<O>
Auto Trait Implementations§
impl<O> !Freeze for GenericBinaryArray<O>
impl<O> RefUnwindSafe for GenericBinaryArray<O>where
ScalarBuffer<O>: RefUnwindSafe,
impl<O> Send for GenericBinaryArray<O>where
ScalarBuffer<O>: Send,
impl<O> Sync for GenericBinaryArray<O>where
ScalarBuffer<O>: Sync,
impl<O> Unpin for GenericBinaryArray<O>where
ScalarBuffer<O>: Unpin,
impl<O> UnsafeUnpin for GenericBinaryArray<O>where
ScalarBuffer<O>: UnsafeUnpin,
impl<O> UnwindSafe for GenericBinaryArray<O>where
ScalarBuffer<O>: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<A> IntoArrayRef for Awhere
A: Array,
impl<A> IntoArrayRef for Awhere
A: Array,
Source§fn into_array_ref(self) -> ArrayRef
fn into_array_ref(self) -> ArrayRef
self into a shared, dynamically typed column.