Struct arrow::array::PrimitiveArray
source · [−]pub struct PrimitiveArray<T>where
T: ArrowPrimitiveType,{ /* private fields */ }
Expand description
Array whose elements are of primitive types.
Example: From an iterator of values
use arrow_array::{Array, PrimitiveArray, types::Int32Type};
let arr: PrimitiveArray<Int32Type> = PrimitiveArray::from_iter_values((0..10).map(|x| x + 1));
assert_eq!(10, arr.len());
assert_eq!(0, arr.null_count());
for i in 0..10i32 {
assert_eq!(i + 1, arr.value(i as usize));
}
Implementations
sourceimpl<T> PrimitiveArray<T>where
T: ArrowPrimitiveType,
impl<T> PrimitiveArray<T>where
T: ArrowPrimitiveType,
sourcepub fn values(&self) -> &[<T as ArrowPrimitiveType>::Native]
pub fn values(&self) -> &[<T as ArrowPrimitiveType>::Native]
Returns a slice of the values of this array
pub fn builder(capacity: usize) -> PrimitiveBuilder<T>
sourcepub unsafe fn value_unchecked(
&self,
i: usize
) -> <T as ArrowPrimitiveType>::Native
pub unsafe fn value_unchecked(
&self,
i: usize
) -> <T as ArrowPrimitiveType>::Native
Returns the primitive value at index i
.
Safety
caller must ensure that the passed in offset is less than the array len()
sourcepub fn value(&self, i: usize) -> <T as ArrowPrimitiveType>::Native
pub fn value(&self, i: usize) -> <T as ArrowPrimitiveType>::Native
sourcepub fn from_iter_values<I>(iter: I) -> PrimitiveArray<T>where
I: IntoIterator<Item = <T as ArrowPrimitiveType>::Native>,
pub fn from_iter_values<I>(iter: I) -> PrimitiveArray<T>where
I: IntoIterator<Item = <T as ArrowPrimitiveType>::Native>,
Creates a PrimitiveArray based on an iterator of values without nulls
sourcepub fn from_value(
value: <T as ArrowPrimitiveType>::Native,
count: usize
) -> PrimitiveArray<T>
pub fn from_value(
value: <T as ArrowPrimitiveType>::Native,
count: usize
) -> PrimitiveArray<T>
Creates a PrimitiveArray based on a constant value with count
elements
sourcepub fn take_iter<'a>(
&'a self,
indexes: impl Iterator<Item = Option<usize>> + 'a
) -> impl Iterator<Item = Option<<T as ArrowPrimitiveType>::Native>> + 'a
pub fn take_iter<'a>(
&'a self,
indexes: impl Iterator<Item = Option<usize>> + 'a
) -> impl Iterator<Item = Option<<T as ArrowPrimitiveType>::Native>> + 'a
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<<T as ArrowPrimitiveType>::Native>> + 'a
pub unsafe fn take_iter_unchecked<'a>(
&'a self,
indexes: impl Iterator<Item = Option<usize>> + 'a
) -> impl Iterator<Item = Option<<T as ArrowPrimitiveType>::Native>> + 'a
Returns an iterator that returns the values of array.value(i)
for an iterator with each element i
Safety
caller must ensure that the offsets in the iterator are less than the array len()
sourcepub fn reinterpret_cast<K>(&self) -> PrimitiveArray<K>where
K: ArrowPrimitiveType<Native = <T as ArrowPrimitiveType>::Native>,
pub fn reinterpret_cast<K>(&self) -> PrimitiveArray<K>where
K: ArrowPrimitiveType<Native = <T as ArrowPrimitiveType>::Native>,
Reinterprets this array’s contents as a different data type without copying
This can be used to efficiently convert between primitive arrays with the same underlying representation
Note: this will not modify the underlying values, and therefore may change
the semantic values of the array, e.g. 100 milliseconds in a TimestampNanosecondArray
will become 100 seconds in a TimestampSecondArray
.
For casts that preserve the semantic value, check out the [compute kernels]
let a = Int64Array::from_iter_values([1, 2, 3, 4]);
let b: TimestampNanosecondArray = a.reinterpret_cast();
sourcepub fn unary<F, O>(&self, op: F) -> PrimitiveArray<O>where
O: ArrowPrimitiveType,
F: Fn(<T as ArrowPrimitiveType>::Native) -> <O as ArrowPrimitiveType>::Native,
pub fn unary<F, O>(&self, op: F) -> PrimitiveArray<O>where
O: ArrowPrimitiveType,
F: Fn(<T as ArrowPrimitiveType>::Native) -> <O as ArrowPrimitiveType>::Native,
Applies an unary and infallible function to a primitive array. This is the fastest way to perform an operation on a primitive array when the benefits of a vectorized operation outweigh the cost of branching nulls and non-nulls.
Implementation
This will apply the function for all values, including those on null slots. This implies that the operation must be infallible for any value of the corresponding type or this function may panic.
Example
let array = Int32Array::from(vec![Some(5), Some(7), None]);
let c = array.unary(|x| x * 2 + 1);
assert_eq!(c, Int32Array::from(vec![Some(11), Some(15), None]));
sourcepub fn try_unary<F, O, E>(&self, op: F) -> Result<PrimitiveArray<O>, E>where
O: ArrowPrimitiveType,
F: Fn(<T as ArrowPrimitiveType>::Native) -> Result<<O as ArrowPrimitiveType>::Native, E>,
pub fn try_unary<F, O, E>(&self, op: F) -> Result<PrimitiveArray<O>, E>where
O: ArrowPrimitiveType,
F: Fn(<T as ArrowPrimitiveType>::Native) -> Result<<O as ArrowPrimitiveType>::Native, E>,
Applies a unary and fallible function to all valid values in a primitive array
This is unlike Self::unary
which will apply an infallible function to all rows
regardless of validity, in many cases this will be significantly faster and should
be preferred if op
is infallible.
Note: LLVM is currently unable to effectively vectorize fallible operations
sourceimpl<T> PrimitiveArray<T>where
T: ArrowTemporalType,
i64: From<<T as ArrowPrimitiveType>::Native>,
impl<T> PrimitiveArray<T>where
T: ArrowTemporalType,
i64: From<<T as ArrowPrimitiveType>::Native>,
sourcepub fn value_as_datetime(&self, i: usize) -> Option<NaiveDateTime>
pub fn value_as_datetime(&self, i: usize) -> Option<NaiveDateTime>
Returns value as a chrono NaiveDateTime
, handling time resolution
If a data type cannot be converted to NaiveDateTime
, a None
is returned.
A valid value is expected, thus the user should first check for validity.
sourcepub fn value_as_datetime_with_tz(
&self,
i: usize,
tz: FixedOffset
) -> Option<NaiveDateTime>
pub fn value_as_datetime_with_tz(
&self,
i: usize,
tz: FixedOffset
) -> Option<NaiveDateTime>
Returns value as a chrono NaiveDateTime
, handling time resolution with the provided tz
functionally it is same as value_as_datetime
, however it adds
the passed tz to the to-be-returned NaiveDateTime
sourcepub fn value_as_date(&self, i: usize) -> Option<NaiveDate>
pub fn value_as_date(&self, i: usize) -> Option<NaiveDate>
Returns value as a chrono NaiveDate
by using Self::datetime()
If a data type cannot be converted to NaiveDate
, a None
is returned
sourcepub fn value_as_time(&self, i: usize) -> Option<NaiveTime>
pub fn value_as_time(&self, i: usize) -> Option<NaiveTime>
Returns a value as a chrono NaiveTime
Date32
and Date64
return UTC midnight as they do not have time resolution
sourcepub fn value_as_duration(&self, i: usize) -> Option<Duration>
pub fn value_as_duration(&self, i: usize) -> Option<Duration>
Returns a value as a chrono Duration
If a data type cannot be converted to Duration
, a None
is returned
sourceimpl<'a, T> PrimitiveArray<T>where
T: ArrowPrimitiveType,
impl<'a, T> PrimitiveArray<T>where
T: ArrowPrimitiveType,
sourcepub fn iter(&'a self) -> ArrayIter<&'a PrimitiveArray<T>>ⓘNotable traits for ArrayIter<T>impl<T> Iterator for ArrayIter<T>where
T: ArrayAccessor, type Item = Option<<T as ArrayAccessor>::Item>;
pub fn iter(&'a self) -> ArrayIter<&'a PrimitiveArray<T>>ⓘNotable traits for ArrayIter<T>impl<T> Iterator for ArrayIter<T>where
T: ArrayAccessor, type Item = Option<<T as ArrayAccessor>::Item>;
T: ArrayAccessor, type Item = Option<<T as ArrayAccessor>::Item>;
constructs a new iterator
sourceimpl<T> PrimitiveArray<T>where
T: ArrowPrimitiveType,
impl<T> PrimitiveArray<T>where
T: ArrowPrimitiveType,
sourcepub unsafe fn from_trusted_len_iter<I, P>(iter: I) -> PrimitiveArray<T>where
P: Borrow<Option<<T as ArrowPrimitiveType>::Native>>,
I: IntoIterator<Item = P>,
pub unsafe fn from_trusted_len_iter<I, P>(iter: I) -> PrimitiveArray<T>where
P: Borrow<Option<<T as ArrowPrimitiveType>::Native>>,
I: IntoIterator<Item = P>,
Creates a PrimitiveArray
from an iterator of trusted length.
Safety
The iterator must be TrustedLen
.
I.e. that size_hint().1
correctly reports its length.
sourceimpl<T> PrimitiveArray<T>where
T: ArrowTimestampType,
impl<T> PrimitiveArray<T>where
T: ArrowTimestampType,
sourcepub fn from_vec(
data: Vec<i64, Global>,
timezone: Option<String>
) -> PrimitiveArray<T>
pub fn from_vec(
data: Vec<i64, Global>,
timezone: Option<String>
) -> PrimitiveArray<T>
Construct a timestamp array from a vec of i64 values and an optional timezone
sourcepub fn with_timezone(&self, timezone: String) -> PrimitiveArray<T>
pub fn with_timezone(&self, timezone: String) -> PrimitiveArray<T>
Construct a timestamp array with new timezone
sourceimpl<T> PrimitiveArray<T>where
T: ArrowTimestampType,
impl<T> PrimitiveArray<T>where
T: ArrowTimestampType,
sourcepub fn from_opt_vec(
data: Vec<Option<i64>, Global>,
timezone: Option<String>
) -> PrimitiveArray<T>
pub fn from_opt_vec(
data: Vec<Option<i64>, Global>,
timezone: Option<String>
) -> PrimitiveArray<T>
Construct a timestamp array from a vec of Option
Trait Implementations
sourceimpl<T> Array for PrimitiveArray<T>where
T: ArrowPrimitiveType,
impl<T> Array for PrimitiveArray<T>where
T: ArrowPrimitiveType,
sourcefn data_ref(&self) -> &ArrayData
fn data_ref(&self) -> &ArrayData
sourcefn slice(&self, offset: usize, length: usize) -> Arc<dyn Array + 'static>
fn slice(&self, offset: usize, length: usize) -> Arc<dyn Array + 'static>
sourcefn offset(&self) -> usize
fn offset(&self) -> usize
0
. Read moresourcefn is_null(&self, index: usize) -> bool
fn is_null(&self, index: usize) -> bool
index
is null.
When using this function on a slice, the index is relative to the slice. Read moresourcefn is_valid(&self, index: usize) -> bool
fn is_valid(&self, index: usize) -> bool
index
is not null.
When using this function on a slice, the index is relative to the slice. Read moresourcefn null_count(&self) -> usize
fn null_count(&self) -> usize
sourcefn get_buffer_memory_size(&self) -> usize
fn get_buffer_memory_size(&self) -> usize
sourcefn 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. Read moresourceimpl<'a, T> ArrayAccessor for &'a PrimitiveArray<T>where
T: ArrowPrimitiveType,
impl<'a, T> ArrayAccessor for &'a PrimitiveArray<T>where
T: ArrowPrimitiveType,
type Item = <T as ArrowPrimitiveType>::Native
sourcefn value(&self, index: usize) -> <&'a PrimitiveArray<T> as ArrayAccessor>::Item
fn value(&self, index: usize) -> <&'a PrimitiveArray<T> as ArrayAccessor>::Item
i
Read moresourceunsafe fn value_unchecked(
&self,
index: usize
) -> <&'a PrimitiveArray<T> as ArrayAccessor>::Item
unsafe fn value_unchecked(
&self,
index: usize
) -> <&'a PrimitiveArray<T> as ArrayAccessor>::Item
i
Read moresourceimpl<T> Debug for PrimitiveArray<T>where
T: ArrowPrimitiveType,
impl<T> Debug for PrimitiveArray<T>where
T: ArrowPrimitiveType,
sourceimpl<T> From<ArrayData> for PrimitiveArray<T>where
T: ArrowPrimitiveType,
impl<T> From<ArrayData> for PrimitiveArray<T>where
T: ArrowPrimitiveType,
Constructs a PrimitiveArray
from an array data reference.