Struct re_sdk::external::arrow2::array::BinaryArray
pub struct BinaryArray<O>where
O: Offset,{
data_type: DataType,
offsets: OffsetsBuffer<O>,
values: Buffer<u8>,
validity: Option<Bitmap>,
}
Expand description
A BinaryArray
is Arrow’s semantically equivalent of an immutable Vec<Option<Vec<u8>>>
.
It implements Array
.
The size of this struct is O(1)
, as all data is stored behind an std::sync::Arc
.
§Example
use re_arrow2::array::BinaryArray;
use re_arrow2::bitmap::Bitmap;
use re_arrow2::buffer::Buffer;
let array = BinaryArray::<i32>::from([Some([1, 2].as_ref()), None, Some([3].as_ref())]);
assert_eq!(array.value(0), &[1, 2]);
assert_eq!(array.iter().collect::<Vec<_>>(), vec![Some([1, 2].as_ref()), None, Some([3].as_ref())]);
assert_eq!(array.values_iter().collect::<Vec<_>>(), vec![[1, 2].as_ref(), &[], &[3]]);
// the underlying representation:
assert_eq!(array.values(), &Buffer::from(vec![1, 2, 3]));
assert_eq!(array.offsets().buffer(), &Buffer::from(vec![0, 2, 2, 3]));
assert_eq!(array.validity(), Some(&Bitmap::from([true, false, true])));
§Generic parameter
The generic parameter Offset
can only be i32
or i64
and tradeoffs maximum array length with
memory usage:
- the sum of lengths of all elements cannot exceed
Offset::MAX
- the total size of the underlying data is
array.len() * size_of::<Offset>() + sum of lengths of all elements
§Safety
The following invariants hold:
- Two consecutives
offsets
casted (as
) tousize
are valid slices ofvalues
. len
is equal tovalidity.len()
, when defined.
Fields§
§data_type: DataType
§offsets: OffsetsBuffer<O>
§values: Buffer<u8>
§validity: Option<Bitmap>
Implementations§
§impl<O> BinaryArray<O>where
O: Offset,
impl<O> BinaryArray<O>where
O: Offset,
pub fn try_new(
data_type: DataType,
offsets: OffsetsBuffer<O>,
values: Buffer<u8>,
validity: Option<Bitmap>
) -> Result<BinaryArray<O>, Error>
pub fn try_new( data_type: DataType, offsets: OffsetsBuffer<O>, values: Buffer<u8>, validity: Option<Bitmap> ) -> Result<BinaryArray<O>, Error>
Returns a BinaryArray
created from its internal representation.
§Errors
This function returns an error iff:
- The last offset is not equal to the values’ length.
- the validity’s length is not equal to
offsets.len()
. - The
data_type
’scrate::datatypes::PhysicalType
is not equal to eitherBinary
orLargeBinary
.
§Implementation
This function is O(1)
pub fn from_slice<T, P>(slice: P) -> BinaryArray<O>
pub fn from_slice<T, P>(slice: P) -> BinaryArray<O>
Creates a new BinaryArray
from slices of &[u8]
.
pub fn from<T, P>(slice: P) -> BinaryArray<O>
pub fn from<T, P>(slice: P) -> BinaryArray<O>
Creates a new BinaryArray
from a slice of optional &[u8]
.
pub fn iter(
&self
) -> ZipValidity<&[u8], ArrayValuesIter<'_, BinaryArray<O>>, BitmapIter<'_>> ⓘ
pub fn iter( &self ) -> ZipValidity<&[u8], ArrayValuesIter<'_, BinaryArray<O>>, BitmapIter<'_>> ⓘ
Returns an iterator of Option<&[u8]>
over every element of this array.
pub fn values_iter(&self) -> ArrayValuesIter<'_, BinaryArray<O>> ⓘ
pub fn values_iter(&self) -> ArrayValuesIter<'_, BinaryArray<O>> ⓘ
Returns an iterator of &[u8]
over every element of this array, ignoring the validity
pub unsafe fn value_unchecked(&self, i: usize) -> &[u8] ⓘ
pub unsafe fn value_unchecked(&self, i: usize) -> &[u8] ⓘ
pub fn values(&self) -> &Buffer<u8>
pub fn values(&self) -> &Buffer<u8>
Returns the values of this BinaryArray
.
pub fn offsets(&self) -> &OffsetsBuffer<O>
pub fn offsets(&self) -> &OffsetsBuffer<O>
Returns the offsets of this BinaryArray
.
pub fn slice(&mut self, offset: usize, length: usize)
pub fn slice(&mut self, offset: usize, length: usize)
Slices this BinaryArray
.
§Implementation
This function is O(1)
.
§Panics
iff offset + length > self.len()
.
pub unsafe fn slice_unchecked(&mut self, offset: usize, length: usize)
pub unsafe fn slice_unchecked(&mut self, offset: usize, length: usize)
Slices this BinaryArray
.
§Implementation
This function is O(1)
.
§Safety
The caller must ensure that offset + length <= self.len()
.
pub fn sliced(self, offset: usize, length: usize) -> BinaryArray<O>
pub fn sliced(self, offset: usize, length: usize) -> BinaryArray<O>
pub unsafe fn sliced_unchecked(
self,
offset: usize,
length: usize
) -> BinaryArray<O>
pub unsafe fn sliced_unchecked( self, offset: usize, length: usize ) -> BinaryArray<O>
pub fn with_validity(self, validity: Option<Bitmap>) -> BinaryArray<O>
pub fn with_validity(self, validity: Option<Bitmap>) -> BinaryArray<O>
pub fn set_validity(&mut self, validity: Option<Bitmap>)
pub fn set_validity(&mut self, validity: Option<Bitmap>)
pub fn boxed(self) -> Box<dyn Array>
pub fn boxed(self) -> Box<dyn Array>
Boxes this array into a Box<dyn Array>
.
pub fn arced(self) -> Arc<dyn Array>
pub fn arced(self) -> Arc<dyn Array>
Arcs this array into a std::sync::Arc<dyn Array>
.
pub fn into_inner(
self
) -> (DataType, OffsetsBuffer<O>, Buffer<u8>, Option<Bitmap>)
pub fn into_inner( self ) -> (DataType, OffsetsBuffer<O>, Buffer<u8>, Option<Bitmap>)
Returns its internal representation
pub fn into_mut(self) -> Either<BinaryArray<O>, MutableBinaryArray<O>> ⓘ
pub fn into_mut(self) -> Either<BinaryArray<O>, MutableBinaryArray<O>> ⓘ
Try to convert this BinaryArray
to a MutableBinaryArray
pub fn new_empty(data_type: DataType) -> BinaryArray<O>
pub fn new_empty(data_type: DataType) -> BinaryArray<O>
Creates an empty BinaryArray
, i.e. whose .len
is zero.
pub fn new_null(data_type: DataType, length: usize) -> BinaryArray<O>
pub fn new_null(data_type: DataType, length: usize) -> BinaryArray<O>
Creates an null BinaryArray
, i.e. whose .null_count() == .len()
.
pub fn default_data_type() -> DataType
pub fn default_data_type() -> DataType
Returns the default DataType
, DataType::Binary
or DataType::LargeBinary
pub fn new(
data_type: DataType,
offsets: OffsetsBuffer<O>,
values: Buffer<u8>,
validity: Option<Bitmap>
) -> BinaryArray<O>
pub fn new( data_type: DataType, offsets: OffsetsBuffer<O>, values: Buffer<u8>, validity: Option<Bitmap> ) -> BinaryArray<O>
Alias for unwrapping Self::try_new
pub fn from_trusted_len_values_iter<T, I>(iterator: I) -> BinaryArray<O>
pub fn from_trusted_len_values_iter<T, I>(iterator: I) -> BinaryArray<O>
Returns a BinaryArray
from an iterator of trusted length.
The BinaryArray
is guaranteed to not have a validity
pub fn from_iter_values<T, I>(iterator: I) -> BinaryArray<O>
pub fn from_iter_values<T, I>(iterator: I) -> BinaryArray<O>
Returns a new BinaryArray
from a Iterator
of &[u8]
.
The BinaryArray
is guaranteed to not have a validity
pub unsafe fn from_trusted_len_iter_unchecked<I, P>(
iterator: I
) -> BinaryArray<O>
pub unsafe fn from_trusted_len_iter_unchecked<I, P>( iterator: I ) -> BinaryArray<O>
Creates a BinaryArray
from an iterator of trusted length.
§Safety
The iterator must be TrustedLen
.
I.e. that size_hint().1
correctly reports its length.
pub fn from_trusted_len_iter<I, P>(iterator: I) -> BinaryArray<O>
pub fn from_trusted_len_iter<I, P>(iterator: I) -> BinaryArray<O>
Creates a BinaryArray
from a TrustedLen
pub unsafe fn try_from_trusted_len_iter_unchecked<E, I, P>(
iterator: I
) -> Result<BinaryArray<O>, E>
pub unsafe fn try_from_trusted_len_iter_unchecked<E, I, P>( iterator: I ) -> Result<BinaryArray<O>, E>
Creates a BinaryArray
from an falible iterator of trusted length.
§Safety
The iterator must be TrustedLen
.
I.e. that size_hint().1
correctly reports its length.
pub fn try_from_trusted_len_iter<E, I, P>(iter: I) -> Result<BinaryArray<O>, E>
pub fn try_from_trusted_len_iter<E, I, P>(iter: I) -> Result<BinaryArray<O>, E>
Creates a BinaryArray
from an fallible iterator of trusted length.
Trait Implementations§
§impl<O> Arrow2Arrow for BinaryArray<O>where
O: Offset,
impl<O> Arrow2Arrow for BinaryArray<O>where
O: Offset,
§impl<O> Array for BinaryArray<O>where
O: Offset,
impl<O> Array for BinaryArray<O>where
O: Offset,
§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Any
, which enables downcasting to concrete types.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Any
, which enables mutable downcasting to concrete types.§fn len(&self) -> usize
fn len(&self) -> usize
Array
. Every array has a length corresponding to the number of
elements (slots).§fn data_type(&self) -> &DataType
fn data_type(&self) -> &DataType
DataType
of the Array
. In combination with Array::as_any
, this can be
used to downcast trait objects (dyn Array
) to concrete arrays.§fn null_count(&self) -> usize
fn null_count(&self) -> usize
§unsafe fn is_null_unchecked(&self, i: usize) -> bool
unsafe fn is_null_unchecked(&self, i: usize) -> bool
i
is null. Read more§impl<O> Clone for BinaryArray<O>
impl<O> Clone for BinaryArray<O>
§fn clone(&self) -> BinaryArray<O>
fn clone(&self) -> BinaryArray<O>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more§impl<O> Debug for BinaryArray<O>where
O: Offset,
impl<O> Debug for BinaryArray<O>where
O: Offset,
§impl<'a, O> From<GrowableBinary<'a, O>> for BinaryArray<O>where
O: Offset,
impl<'a, O> From<GrowableBinary<'a, O>> for BinaryArray<O>where
O: Offset,
§fn from(val: GrowableBinary<'a, O>) -> BinaryArray<O>
fn from(val: GrowableBinary<'a, O>) -> BinaryArray<O>
§impl<O> From<MutableBinaryArray<O>> for BinaryArray<O>where
O: Offset,
impl<O> From<MutableBinaryArray<O>> for BinaryArray<O>where
O: Offset,
§fn from(other: MutableBinaryArray<O>) -> BinaryArray<O>
fn from(other: MutableBinaryArray<O>) -> BinaryArray<O>
§impl<O> From<MutableBinaryValuesArray<O>> for BinaryArray<O>where
O: Offset,
impl<O> From<MutableBinaryValuesArray<O>> for BinaryArray<O>where
O: Offset,
§fn from(other: MutableBinaryValuesArray<O>) -> BinaryArray<O>
fn from(other: MutableBinaryValuesArray<O>) -> BinaryArray<O>
§impl<O, P> FromIterator<Option<P>> for BinaryArray<O>
impl<O, P> FromIterator<Option<P>> for BinaryArray<O>
§fn from_iter<I>(iter: I) -> BinaryArray<O>where
I: IntoIterator<Item = Option<P>>,
fn from_iter<I>(iter: I) -> BinaryArray<O>where
I: IntoIterator<Item = Option<P>>,
§impl<O> GenericBinaryArray<O> for BinaryArray<O>where
O: Offset,
impl<O> GenericBinaryArray<O> for BinaryArray<O>where
O: Offset,
§impl<'a, O> IntoIterator for &'a BinaryArray<O>where
O: Offset,
impl<'a, O> IntoIterator for &'a BinaryArray<O>where
O: Offset,
§type IntoIter = ZipValidity<&'a [u8], ArrayValuesIter<'a, BinaryArray<O>>, BitmapIter<'a>>
type IntoIter = ZipValidity<&'a [u8], ArrayValuesIter<'a, BinaryArray<O>>, BitmapIter<'a>>
§fn into_iter(self) -> <&'a BinaryArray<O> as IntoIterator>::IntoIter
fn into_iter(self) -> <&'a BinaryArray<O> as IntoIterator>::IntoIter
§impl<O> PartialEq<&(dyn Array + 'static)> for BinaryArray<O>where
O: Offset,
impl<O> PartialEq<&(dyn Array + 'static)> for BinaryArray<O>where
O: Offset,
§impl<O> PartialEq<BinaryArray<O>> for &(dyn Array + 'static)where
O: Offset,
impl<O> PartialEq<BinaryArray<O>> for &(dyn Array + 'static)where
O: Offset,
§fn eq(&self, other: &BinaryArray<O>) -> bool
fn eq(&self, other: &BinaryArray<O>) -> bool
self
and other
values to be equal, and is used
by ==
.§impl<O> PartialEq for BinaryArray<O>where
O: Offset,
impl<O> PartialEq for BinaryArray<O>where
O: Offset,
§fn eq(&self, other: &BinaryArray<O>) -> bool
fn eq(&self, other: &BinaryArray<O>) -> bool
self
and other
values to be equal, and is used
by ==
.Auto Trait Implementations§
impl<O> Freeze for BinaryArray<O>
impl<O> RefUnwindSafe for BinaryArray<O>
impl<O> Send for BinaryArray<O>
impl<O> Sync for BinaryArray<O>
impl<O> Unpin for BinaryArray<O>
impl<O> UnwindSafe for BinaryArray<O>
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> CheckedAs for T
impl<T> CheckedAs for T
source§fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
source§impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
source§fn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more