pub struct Utf8Array<O>where
O: Offset,{
data_type: DataType,
offsets: OffsetsBuffer<O>,
values: Buffer<u8>,
validity: Option<Bitmap>,
}
Expand description
A Utf8Array
is arrow’s semantic equivalent of an immutable Vec<Option<String>>
.
Cloning and slicing this struct is O(1)
.
§Example
use re_arrow2::bitmap::Bitmap;
use re_arrow2::buffer::Buffer;
use re_arrow2::array::Utf8Array;
let array = Utf8Array::<i32>::from([Some("hi"), None, Some("there")]);
assert_eq!(array.value(0), "hi");
assert_eq!(array.iter().collect::<Vec<_>>(), vec![Some("hi"), None, Some("there")]);
assert_eq!(array.values_iter().collect::<Vec<_>>(), vec!["hi", "", "there"]);
// the underlying representation
assert_eq!(array.validity(), Some(&Bitmap::from([true, false, true])));
assert_eq!(array.values(), &Buffer::from(b"hithere".to_vec()));
assert_eq!(array.offsets().buffer(), &Buffer::from(vec![0, 2, 2, 2 + 5]));
§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
. - A slice of
values
taken from two consecutivesoffsets
is validutf8
. len
is equal tovalidity.len()
, when defined.
Fields§
§data_type: DataType
§offsets: OffsetsBuffer<O>
§values: Buffer<u8>
§validity: Option<Bitmap>
Implementations§
§impl<O> Utf8Array<O>where
O: Offset,
impl<O> Utf8Array<O>where
O: Offset,
pub fn try_new(
data_type: DataType,
offsets: OffsetsBuffer<O>,
values: Buffer<u8>,
validity: Option<Bitmap>
) -> Result<Utf8Array<O>, Error>
pub fn try_new( data_type: DataType, offsets: OffsetsBuffer<O>, values: Buffer<u8>, validity: Option<Bitmap> ) -> Result<Utf8Array<O>, Error>
Returns a Utf8Array
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 eitherUtf8
orLargeUtf8
. - The
values
between two consecutiveoffsets
are not valid utf8
§Implementation
This function is O(N)
- checking utf8 is O(N)
pub fn from_slice<T, P>(slice: P) -> Utf8Array<O>
pub fn from_slice<T, P>(slice: P) -> Utf8Array<O>
Returns a Utf8Array
from a slice of &str
.
A convenience method that uses Self::from_trusted_len_values_iter
.
pub fn from<T, P>(slice: P) -> Utf8Array<O>
pub fn from<T, P>(slice: P) -> Utf8Array<O>
Returns a new Utf8Array
from a slice of &str
.
A convenience method that uses Self::from_trusted_len_iter
.
pub fn iter(
&self
) -> ZipValidity<&str, ArrayValuesIter<'_, Utf8Array<O>>, BitmapIter<'_>> ⓘ
pub fn iter( &self ) -> ZipValidity<&str, ArrayValuesIter<'_, Utf8Array<O>>, BitmapIter<'_>> ⓘ
Returns an iterator of Option<&str>
pub fn values_iter(&self) -> ArrayValuesIter<'_, Utf8Array<O>> ⓘ
pub fn values_iter(&self) -> ArrayValuesIter<'_, Utf8Array<O>> ⓘ
Returns an iterator of &str
pub fn value(&self, i: usize) -> &str
pub fn value(&self, i: usize) -> &str
Returns the value of the element at index i
, ignoring the array’s validity.
§Panic
This function panics iff i >= self.len
.
pub unsafe fn value_unchecked(&self, i: usize) -> &str
pub unsafe fn value_unchecked(&self, i: usize) -> &str
Returns the value of the element at index i
, ignoring the array’s validity.
§Safety
This function is safe iff i < self.len
.
pub fn offsets(&self) -> &OffsetsBuffer<O>
pub fn offsets(&self) -> &OffsetsBuffer<O>
Returns the offsets of this Utf8Array
.
pub unsafe fn slice_unchecked(&mut self, offset: usize, length: usize)
pub unsafe fn slice_unchecked(&mut self, offset: usize, length: usize)
pub unsafe fn sliced_unchecked(
self,
offset: usize,
length: usize
) -> Utf8Array<O>
pub unsafe fn sliced_unchecked( self, offset: usize, length: usize ) -> Utf8Array<O>
pub fn with_validity(self, validity: Option<Bitmap>) -> Utf8Array<O>
pub fn with_validity(self, validity: Option<Bitmap>) -> Utf8Array<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<Utf8Array<O>, MutableUtf8Array<O>> ⓘ
pub fn into_mut(self) -> Either<Utf8Array<O>, MutableUtf8Array<O>> ⓘ
Try to convert this Utf8Array
to a MutableUtf8Array
pub fn new_empty(data_type: DataType) -> Utf8Array<O>
pub fn new_empty(data_type: DataType) -> Utf8Array<O>
Returns a new empty Utf8Array
.
The array is guaranteed to have no elements nor validity.
pub fn new_null(data_type: DataType, length: usize) -> Utf8Array<O>
pub fn new_null(data_type: DataType, length: usize) -> Utf8Array<O>
Returns a new Utf8Array
whose all slots are null / None
.
pub fn default_data_type() -> DataType
pub fn default_data_type() -> DataType
Returns a default DataType
of this array, which depends on the generic parameter O
: DataType::Utf8
or DataType::LargeUtf8
pub unsafe fn try_new_unchecked(
data_type: DataType,
offsets: OffsetsBuffer<O>,
values: Buffer<u8>,
validity: Option<Bitmap>
) -> Result<Utf8Array<O>, Error>
pub unsafe fn try_new_unchecked( data_type: DataType, offsets: OffsetsBuffer<O>, values: Buffer<u8>, validity: Option<Bitmap> ) -> Result<Utf8Array<O>, Error>
Creates a new Utf8Array
without checking for offsets monotinicity nor utf8-validity
§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 eitherUtf8
orLargeUtf8
.
§Safety
This function is unsound iff:
- The
values
between two consecutiveoffsets
are not valid utf8
§Implementation
This function is O(1)
pub fn new(
data_type: DataType,
offsets: OffsetsBuffer<O>,
values: Buffer<u8>,
validity: Option<Bitmap>
) -> Utf8Array<O>
pub fn new( data_type: DataType, offsets: OffsetsBuffer<O>, values: Buffer<u8>, validity: Option<Bitmap> ) -> Utf8Array<O>
Creates a new Utf8Array
.
§Panics
This function panics 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 eitherUtf8
orLargeUtf8
. - The
values
between two consecutiveoffsets
are not valid utf8
§Implementation
This function is O(N)
- checking utf8 is O(N)
pub unsafe fn new_unchecked(
data_type: DataType,
offsets: OffsetsBuffer<O>,
values: Buffer<u8>,
validity: Option<Bitmap>
) -> Utf8Array<O>
pub unsafe fn new_unchecked( data_type: DataType, offsets: OffsetsBuffer<O>, values: Buffer<u8>, validity: Option<Bitmap> ) -> Utf8Array<O>
Creates a new Utf8Array
without checking for offsets monotinicity.
§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 eitherUtf8
orLargeUtf8
.
§Safety
This function is unsound iff:
- the offsets are not monotonically increasing
- The
values
between two consecutiveoffsets
are not valid utf8
§Implementation
This function is O(1)
pub fn from_trusted_len_values_iter<T, I>(iterator: I) -> Utf8Array<O>
pub fn from_trusted_len_values_iter<T, I>(iterator: I) -> Utf8Array<O>
Returns a (non-null) Utf8Array
created from a TrustedLen
of &str
.
§Implementation
This function is O(N)
pub fn from_iter_values<T, I>(iterator: I) -> Utf8Array<O>
pub fn from_iter_values<T, I>(iterator: I) -> Utf8Array<O>
pub unsafe fn from_trusted_len_iter_unchecked<I, P>(iterator: I) -> Utf8Array<O>
pub unsafe fn from_trusted_len_iter_unchecked<I, P>(iterator: I) -> Utf8Array<O>
Creates a Utf8Array
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) -> Utf8Array<O>
pub fn from_trusted_len_iter<I, P>(iterator: I) -> Utf8Array<O>
Creates a Utf8Array
from an iterator of trusted length.
pub unsafe fn try_from_trusted_len_iter_unchecked<E, I, P>(
iterator: I
) -> Result<Utf8Array<O>, E>
pub unsafe fn try_from_trusted_len_iter_unchecked<E, I, P>( iterator: I ) -> Result<Utf8Array<O>, E>
Creates a Utf8Array
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<Utf8Array<O>, E>
pub fn try_from_trusted_len_iter<E, I, P>(iter: I) -> Result<Utf8Array<O>, E>
Creates a Utf8Array
from an fallible iterator of trusted length.
Trait Implementations§
§impl<O> Arrow2Arrow for Utf8Array<O>where
O: Offset,
impl<O> Arrow2Arrow for Utf8Array<O>where
O: Offset,
§impl<O> Array for Utf8Array<O>where
O: Offset,
impl<O> Array for Utf8Array<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<'a, O> From<GrowableUtf8<'a, O>> for Utf8Array<O>where
O: Offset,
impl<'a, O> From<GrowableUtf8<'a, O>> for Utf8Array<O>where
O: Offset,
§fn from(val: GrowableUtf8<'a, O>) -> Utf8Array<O>
fn from(val: GrowableUtf8<'a, O>) -> Utf8Array<O>
§impl<O> From<MutableUtf8Array<O>> for Utf8Array<O>where
O: Offset,
impl<O> From<MutableUtf8Array<O>> for Utf8Array<O>where
O: Offset,
§fn from(other: MutableUtf8Array<O>) -> Utf8Array<O>
fn from(other: MutableUtf8Array<O>) -> Utf8Array<O>
§impl<O> From<MutableUtf8ValuesArray<O>> for Utf8Array<O>where
O: Offset,
impl<O> From<MutableUtf8ValuesArray<O>> for Utf8Array<O>where
O: Offset,
§fn from(other: MutableUtf8ValuesArray<O>) -> Utf8Array<O>
fn from(other: MutableUtf8ValuesArray<O>) -> Utf8Array<O>
§impl<O, P> FromIterator<Option<P>> for Utf8Array<O>
impl<O, P> FromIterator<Option<P>> for Utf8Array<O>
§impl<O> GenericBinaryArray<O> for Utf8Array<O>where
O: Offset,
impl<O> GenericBinaryArray<O> for Utf8Array<O>where
O: Offset,
§impl<'a, O> IntoIterator for &'a Utf8Array<O>where
O: Offset,
impl<'a, O> IntoIterator for &'a Utf8Array<O>where
O: Offset,
§type IntoIter = ZipValidity<&'a str, ArrayValuesIter<'a, Utf8Array<O>>, BitmapIter<'a>>
type IntoIter = ZipValidity<&'a str, ArrayValuesIter<'a, Utf8Array<O>>, BitmapIter<'a>>
§impl<O> PartialEq<&(dyn Array + 'static)> for Utf8Array<O>where
O: Offset,
impl<O> PartialEq<&(dyn Array + 'static)> for Utf8Array<O>where
O: Offset,
§impl<O> PartialEq<Utf8Array<O>> for &(dyn Array + 'static)where
O: Offset,
impl<O> PartialEq<Utf8Array<O>> for &(dyn Array + 'static)where
O: Offset,
Auto Trait Implementations§
impl<O> Freeze for Utf8Array<O>
impl<O> RefUnwindSafe for Utf8Array<O>
impl<O> Send for Utf8Array<O>
impl<O> Sync for Utf8Array<O>
impl<O> Unpin for Utf8Array<O>
impl<O> UnwindSafe for Utf8Array<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