pub struct GenericByteArray<T: ByteArrayType> {
data_type: DataType,
value_offsets: OffsetBuffer<T::Offset>,
value_data: Buffer,
nulls: Option<NullBuffer>,
}
Expand description
An array of variable length byte arrays
See StringArray
and LargeStringArray
for storing utf8 encoded string data
See BinaryArray
and LargeBinaryArray
for storing arbitrary bytes
§Example: From a Vec
let arr: GenericByteArray<Utf8Type> = vec!["hello", "world", ""].into();
assert_eq!(arr.value_data(), b"helloworld");
assert_eq!(arr.value_offsets(), &[0, 5, 10, 10]);
let values: Vec<_> = arr.iter().collect();
assert_eq!(values, &[Some("hello"), Some("world"), Some("")]);
§Example: From an optional Vec
let arr: GenericByteArray<Utf8Type> = vec![Some("hello"), Some("world"), Some(""), None].into();
assert_eq!(arr.value_data(), b"helloworld");
assert_eq!(arr.value_offsets(), &[0, 5, 10, 10, 10]);
let values: Vec<_> = arr.iter().collect();
assert_eq!(values, &[Some("hello"), Some("world"), Some(""), None]);
§Example: From an iterator of option
let arr: GenericByteArray<Utf8Type> = (0..5).map(|x| (x % 2 == 0).then(|| x.to_string())).collect();
let values: Vec<_> = arr.iter().collect();
assert_eq!(values, &[Some("0"), None, Some("2"), None, Some("4")]);
§Example: Using Builder
let mut builder = GenericByteBuilder::<Utf8Type>::new();
builder.append_value("hello");
builder.append_null();
builder.append_value("world");
let array = builder.finish();
let values: Vec<_> = array.iter().collect();
assert_eq!(values, &[Some("hello"), None, Some("world")]);
Fields§
§data_type: DataType
§value_offsets: OffsetBuffer<T::Offset>
§value_data: Buffer
§nulls: Option<NullBuffer>
Implementations§
Source§impl<OffsetSize: OffsetSizeTrait> GenericByteArray<GenericBinaryType<OffsetSize>>
impl<OffsetSize: OffsetSizeTrait> GenericByteArray<GenericBinaryType<OffsetSize>>
Sourcepub const fn get_data_type() -> DataType
👎Deprecated: please use Self::DATA_TYPE
instead
pub const fn get_data_type() -> DataType
Self::DATA_TYPE
insteadGet the data type of the array.
Sourcepub fn from_vec(v: Vec<&[u8]>) -> Self
pub fn from_vec(v: Vec<&[u8]>) -> Self
Creates a GenericBinaryArray from a vector of byte slices
See also Self::from_iter_values
Sourcepub fn from_opt_vec(v: Vec<Option<&[u8]>>) -> Self
pub fn from_opt_vec(v: Vec<Option<&[u8]>>) -> Self
Creates a GenericBinaryArray from a vector of Optional (null) byte slices
fn from_list(v: GenericListArray<OffsetSize>) -> Self
Sourcepub fn take_iter<'a>(
&'a self,
indexes: impl Iterator<Item = Option<usize>> + 'a,
) -> impl Iterator<Item = Option<&'a [u8]>>
pub fn take_iter<'a>( &'a self, indexes: impl Iterator<Item = Option<usize>> + 'a, ) -> impl Iterator<Item = Option<&'a [u8]>>
Returns an iterator that returns the values of array.value(i)
for an iterator with each element i
Sourcepub unsafe fn take_iter_unchecked<'a>(
&'a self,
indexes: impl Iterator<Item = Option<usize>> + 'a,
) -> impl Iterator<Item = Option<&'a [u8]>>
pub unsafe fn take_iter_unchecked<'a>( &'a self, indexes: impl Iterator<Item = Option<usize>> + 'a, ) -> impl Iterator<Item = Option<&'a [u8]>>
Returns an iterator that returns the values of array.value(i)
for an iterator with each element i
§Safety
caller must ensure that the indexes in the iterator are less than the array.len()
Source§impl<T: ByteArrayType> GenericByteArray<T>
impl<T: ByteArrayType> GenericByteArray<T>
Sourcepub fn new(
offsets: OffsetBuffer<T::Offset>,
values: Buffer,
nulls: Option<NullBuffer>,
) -> Self
pub fn new( offsets: OffsetBuffer<T::Offset>, values: Buffer, nulls: Option<NullBuffer>, ) -> Self
Create a new GenericByteArray
from the provided parts, panicking on failure
§Panics
Panics if GenericByteArray::try_new
returns an error
Sourcepub fn try_new(
offsets: OffsetBuffer<T::Offset>,
values: Buffer,
nulls: Option<NullBuffer>,
) -> Result<Self, ArrowError>
pub fn try_new( offsets: OffsetBuffer<T::Offset>, values: Buffer, nulls: Option<NullBuffer>, ) -> Result<Self, ArrowError>
Create a new GenericByteArray
from the provided parts, returning an error on failure
§Errors
offsets.len() - 1 != nulls.len()
- Any consecutive pair of
offsets
does not denote a valid slice ofvalues
Sourcepub unsafe fn new_unchecked(
offsets: OffsetBuffer<T::Offset>,
values: Buffer,
nulls: Option<NullBuffer>,
) -> Self
pub unsafe fn new_unchecked( offsets: OffsetBuffer<T::Offset>, values: Buffer, nulls: Option<NullBuffer>, ) -> Self
Create a new GenericByteArray
from the provided parts, without validation
§Safety
Safe if Self::try_new
would not error
Sourcepub fn new_null(len: usize) -> Self
pub fn new_null(len: usize) -> Self
Create a new GenericByteArray
of length len
where all values are null
Sourcepub fn from_iter_values<Ptr, I>(iter: I) -> Self
pub fn from_iter_values<Ptr, I>(iter: I) -> Self
Creates a GenericByteArray
based on an iterator of values without nulls
Sourcepub fn into_parts(self) -> (OffsetBuffer<T::Offset>, Buffer, Option<NullBuffer>)
pub fn into_parts(self) -> (OffsetBuffer<T::Offset>, Buffer, Option<NullBuffer>)
Deconstruct this array into its constituent parts
Sourcepub fn value_length(&self, i: usize) -> T::Offset
pub fn value_length(&self, i: usize) -> T::Offset
Sourcepub fn offsets(&self) -> &OffsetBuffer<T::Offset>
pub fn offsets(&self) -> &OffsetBuffer<T::Offset>
Returns a reference to the offsets of this array
Unlike Self::value_offsets
this returns the [OffsetBuffer
]
allowing for zero-copy cloning
Sourcepub fn values(&self) -> &Buffer
pub fn values(&self) -> &Buffer
Returns the values of this array
Unlike Self::value_data
this returns the [Buffer
]
allowing for zero-copy cloning
Sourcepub fn value_data(&self) -> &[u8] ⓘ
pub fn value_data(&self) -> &[u8] ⓘ
Returns the raw value data
Sourcepub fn value_offsets(&self) -> &[T::Offset]
pub fn value_offsets(&self) -> &[T::Offset]
Returns the offset values in the offsets buffer
Sourcepub unsafe fn value_unchecked(&self, i: usize) -> &T::Native
pub unsafe fn value_unchecked(&self, i: usize) -> &T::Native
Returns the element at index i
§Safety
Caller is responsible for ensuring that the index is within the bounds of the array
Sourcepub fn slice(&self, offset: usize, length: usize) -> Self
pub fn slice(&self, offset: usize, length: usize) -> Self
Returns a zero-copy slice of this array with the indicated offset and length.
Sourcepub fn into_builder(self) -> Result<GenericByteBuilder<T>, Self>
pub fn into_builder(self) -> Result<GenericByteBuilder<T>, Self>
Returns GenericByteBuilder
of this byte array for mutating its values if the underlying
offset and data buffers are not shared by others.
Source§impl<OffsetSize: OffsetSizeTrait> GenericByteArray<GenericStringType<OffsetSize>>
impl<OffsetSize: OffsetSizeTrait> GenericByteArray<GenericStringType<OffsetSize>>
Sourcepub const fn get_data_type() -> DataType
👎Deprecated: please use Self::DATA_TYPE
instead
pub const fn get_data_type() -> DataType
Self::DATA_TYPE
insteadGet the data type of the array.
Sourcepub fn num_chars(&self, i: usize) -> usize
pub fn num_chars(&self, i: usize) -> usize
Returns the number of Unicode Scalar Value
in the string at index i
.
§Performance
This function has O(n)
time complexity where n
is the string length.
If you can make sure that all chars in the string are in the range U+0x0000
~ U+0x007F
,
please use the function value_length
which has O(1) time complexity.
Sourcepub fn take_iter<'a>(
&'a self,
indexes: impl Iterator<Item = Option<usize>> + 'a,
) -> impl Iterator<Item = Option<&'a str>>
pub fn take_iter<'a>( &'a self, indexes: impl Iterator<Item = Option<usize>> + 'a, ) -> impl Iterator<Item = Option<&'a str>>
Returns an iterator that returns the values of array.value(i)
for an iterator with each element i
Sourcepub unsafe fn take_iter_unchecked<'a>(
&'a self,
indexes: impl Iterator<Item = Option<usize>> + 'a,
) -> impl Iterator<Item = Option<&'a str>>
pub unsafe fn take_iter_unchecked<'a>( &'a self, indexes: impl Iterator<Item = Option<usize>> + 'a, ) -> impl Iterator<Item = Option<&'a str>>
Returns an iterator that returns the values of array.value(i)
for an iterator with each element i
§Safety
caller must ensure that the indexes in the iterator are less than the array.len()
Sourcepub fn try_from_binary(
v: GenericBinaryArray<OffsetSize>,
) -> Result<Self, ArrowError>
pub fn try_from_binary( v: GenericBinaryArray<OffsetSize>, ) -> Result<Self, ArrowError>
Fallibly creates a GenericStringArray
from a GenericBinaryArray
returning
an error if GenericBinaryArray
contains invalid UTF-8 data
Trait Implementations§
Source§impl<T: ByteArrayType> Array for GenericByteArray<T>
impl<T: ByteArrayType> Array for GenericByteArray<T>
Source§fn data_type(&self) -> &DataType
fn data_type(&self) -> &DataType
DataType
] of this array. Read moreSource§fn slice(&self, offset: usize, length: usize) -> ArrayRef
fn slice(&self, offset: usize, length: usize) -> ArrayRef
Source§fn offset(&self) -> usize
fn offset(&self) -> usize
0
. Read moreSource§fn nulls(&self) -> Option<&NullBuffer>
fn nulls(&self) -> Option<&NullBuffer>
Source§fn get_buffer_memory_size(&self) -> usize
fn get_buffer_memory_size(&self) -> usize
Source§fn get_array_memory_size(&self) -> usize
fn get_array_memory_size(&self) -> usize
get_buffer_memory_size()
and
includes the overhead of the data structures that contain the pointers to the various buffers.Source§fn logical_nulls(&self) -> Option<NullBuffer>
fn logical_nulls(&self) -> Option<NullBuffer>
NullBuffer
] that represents the logical
null values of this array, if any. Read moreSource§fn null_count(&self) -> usize
fn null_count(&self) -> usize
Source§fn logical_null_count(&self) -> usize
fn logical_null_count(&self) -> usize
Source§fn is_nullable(&self) -> bool
fn is_nullable(&self) -> bool
false
if the array is guaranteed to not contain any logical nulls Read moreSource§impl<'a, T: ByteArrayType> ArrayAccessor for &'a GenericByteArray<T>
impl<'a, T: ByteArrayType> ArrayAccessor for &'a GenericByteArray<T>
Source§impl<T: ByteArrayType> Clone for GenericByteArray<T>
impl<T: ByteArrayType> Clone for GenericByteArray<T>
Source§impl<T: ByteArrayType> Debug for GenericByteArray<T>
impl<T: ByteArrayType> Debug for GenericByteArray<T>
Source§impl<FROM, V> From<&GenericByteArray<FROM>> for GenericByteViewArray<V>where
FROM: ByteArrayType,
FROM::Offset: OffsetSizeTrait + ToPrimitive,
V: ByteViewType<Native = FROM::Native>,
impl<FROM, V> From<&GenericByteArray<FROM>> for GenericByteViewArray<V>where
FROM: ByteArrayType,
FROM::Offset: OffsetSizeTrait + ToPrimitive,
V: ByteViewType<Native = FROM::Native>,
Efficiently convert a GenericByteArray
to a GenericByteViewArray
For example this method can convert a StringArray
to a
StringViewArray
.
If the offsets are all less than u32::MAX, the new GenericByteViewArray
is built without copying the underlying string data (views are created
directly into the existing buffer)
Source§fn from(byte_array: &GenericByteArray<FROM>) -> Self
fn from(byte_array: &GenericByteArray<FROM>) -> Self
Source§impl<T: ByteArrayType> From<ArrayData> for GenericByteArray<T>
impl<T: ByteArrayType> From<ArrayData> for GenericByteArray<T>
Source§impl<OffsetSize: OffsetSizeTrait> From<GenericByteArray<GenericBinaryType<OffsetSize>>> for GenericStringArray<OffsetSize>
impl<OffsetSize: OffsetSizeTrait> From<GenericByteArray<GenericBinaryType<OffsetSize>>> for GenericStringArray<OffsetSize>
Source§fn from(v: GenericBinaryArray<OffsetSize>) -> Self
fn from(v: GenericBinaryArray<OffsetSize>) -> Self
Source§impl<OffsetSize: OffsetSizeTrait> From<GenericByteArray<GenericStringType<OffsetSize>>> for GenericBinaryArray<OffsetSize>
impl<OffsetSize: OffsetSizeTrait> From<GenericByteArray<GenericStringType<OffsetSize>>> for GenericBinaryArray<OffsetSize>
Source§fn from(value: GenericStringArray<OffsetSize>) -> Self
fn from(value: GenericStringArray<OffsetSize>) -> Self
Source§impl<T: ByteArrayType> From<GenericByteArray<T>> for ArrayData
impl<T: ByteArrayType> From<GenericByteArray<T>> for ArrayData
Source§fn from(array: GenericByteArray<T>) -> Self
fn from(array: GenericByteArray<T>) -> Self
Source§impl<'a, Ptr, T: ByteArrayType> FromIterator<&'a Option<Ptr>> for GenericByteArray<T>
impl<'a, Ptr, T: ByteArrayType> FromIterator<&'a Option<Ptr>> for GenericByteArray<T>
Source§impl<Ptr, T: ByteArrayType> FromIterator<Option<Ptr>> for GenericByteArray<T>
impl<Ptr, T: ByteArrayType> FromIterator<Option<Ptr>> for GenericByteArray<T>
Source§impl<'a, T: ByteArrayType> IntoIterator for &'a GenericByteArray<T>
impl<'a, T: ByteArrayType> IntoIterator for &'a GenericByteArray<T>
Auto Trait Implementations§
impl<T> Freeze for GenericByteArray<T>
impl<T> RefUnwindSafe for GenericByteArray<T>
impl<T> Send for GenericByteArray<T>
impl<T> Sync for GenericByteArray<T>
impl<T> Unpin for GenericByteArray<T>
impl<T> UnwindSafe for GenericByteArray<T>
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§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)