#[repr(C, align(64))]pub enum TemporalArray {
Datetime32(Arc<DatetimeArray<i32>>),
Datetime64(Arc<DatetimeArray<i64>>),
Null,
}Expand description
Temporal Array
Unified datetime array container
§Purpose
Exists to unify datetime operations, simplify API’s and streamline user ergonomics.
§Usage:
- It is accessible from
Arrayusing.dt(), and provides typed variant access via for e.g.,.dt32(), so one can drill down to the required granularity viamyarr.dt().dt32() - This streamlines function implementations (at least for the
NumericArraycase where this pattern is the most useful), and, despite the additionalenumlayer, matching lanes in many real-world scenarios. This is because one can for e.g., unify a function signature withimpl Into<TemporalArray>, and all of the subtypes, plusArrayandTemporalArray, all qualify. - Additionally, you can then use one
Temporalimplementation on the enum dispatch arm for allTemporalvariants, or, in many cases, for the entire datetime arm when they are the same.
§Handling Times, Durations, etc.
We use one Physical type to hold all datetime variants,
i.e., the Apache Arrow types DATE32, TIME32, DURATION etc.,
and the Logical type is stored on the Field as metadata, given they
otherwise have the same underlying data representation. To treat
them differently in API usage, you can use the TimeUnit and IntervalUnit,
along with the ArrowType that is stored on the Field in Minarrow,
and match on these for any desired behaviour. The Field is packaged together
with Array (which then drill-down accesses TemporalArray on the fly, or
in dispatch routing scenarios).
§Typecasting behaviour
- If the enum already holds the given type (which should be known at compile-time),
then using accessors like
.dt32()is zero-cost, as it transfers ownership. - If you want to keep the original, of course use
.clone()beforehand. - If you use an accessor to a different base type, e.g.,
.dt64()when it’s a.dt32()already in the enum, it will convert it. Therefore, be mindful of performance when this occurs.
Variants§
Implementations§
Source§impl TemporalArray
impl TemporalArray
Sourcepub fn append_array(&mut self, other: &Self)
pub fn append_array(&mut self, other: &Self)
Appends all values (and null mask if present) from other into self.
Panics if the two arrays are of different variants or incompatible types.
This function uses copy-on-write semantics for arrays wrapped in Arc.
If self is the only owner of its data, appends are performed in place without copying.
If the array data is shared (Arc reference count > 1), the data is first cloned
(so the mutation does not affect other owners), and the append is then performed on the unique copy.
This ensures that calling append_array never mutates data referenced elsewhere,
but also avoids unnecessary cloning when the data is uniquely owned.
Sourcepub fn insert_rows(
&mut self,
index: usize,
other: &Self,
) -> Result<(), MinarrowError>
pub fn insert_rows( &mut self, index: usize, other: &Self, ) -> Result<(), MinarrowError>
Inserts all values (and null mask if present) from other into self at the specified index.
This is an O(n) operation.
Returns an error if the two arrays are of different variants or incompatible types, or if the index is out of bounds.
This function uses copy-on-write semantics for arrays wrapped in Arc.
Sourcepub fn split(self, index: usize) -> Result<(Self, Self), MinarrowError>
pub fn split(self, index: usize) -> Result<(Self, Self), MinarrowError>
Splits the TemporalArray at the specified index, consuming self and returning two arrays.
Sourcepub fn dt32(self) -> Result<DatetimeArray<i32>, MinarrowError>
pub fn dt32(self) -> Result<DatetimeArray<i32>, MinarrowError>
Returns an Arc<DatetimeArray
Sourcepub fn dt64(self) -> Result<DatetimeArray<i64>, MinarrowError>
pub fn dt64(self) -> Result<DatetimeArray<i64>, MinarrowError>
Returns an Arc<DatetimeArray
Trait Implementations§
Source§impl ByteSize for TemporalArray
Available on crate feature datetime only.ByteSize for TemporalArray enum (when datetime feature is enabled)
impl ByteSize for TemporalArray
datetime only.ByteSize for TemporalArray enum (when datetime feature is enabled)
Source§impl Clone for TemporalArray
impl Clone for TemporalArray
Source§fn clone(&self) -> TemporalArray
fn clone(&self) -> TemporalArray
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Concatenate for TemporalArray
impl Concatenate for TemporalArray
Source§impl Debug for TemporalArray
impl Debug for TemporalArray
Source§impl Default for TemporalArray
impl Default for TemporalArray
Source§fn default() -> TemporalArray
fn default() -> TemporalArray
Source§impl Display for TemporalArray
impl Display for TemporalArray
Source§impl From<TemporalArray> for TemporalArrayV
impl From<TemporalArray> for TemporalArrayV
Source§fn from(array: TemporalArray) -> Self
fn from(array: TemporalArray) -> Self
Source§impl PartialEq for TemporalArray
impl PartialEq for TemporalArray
Source§impl Shape for TemporalArray
impl Shape for TemporalArray
impl StructuralPartialEq for TemporalArray
Auto Trait Implementations§
impl Freeze for TemporalArray
impl RefUnwindSafe for TemporalArray
impl Send for TemporalArray
impl Sync for TemporalArray
impl Unpin for TemporalArray
impl UnwindSafe for TemporalArray
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<T> CustomValue for T
impl<T> CustomValue for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§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 moreSource§impl<T> Key for Twhere
T: Clone,
impl<T> Key for Twhere
T: Clone,
Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToCompactString for Twhere
T: Display,
impl<T> ToCompactString for Twhere
T: Display,
Source§fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
ToCompactString::to_compact_string() Read moreSource§fn to_compact_string(&self) -> CompactString
fn to_compact_string(&self) -> CompactString
CompactString. Read moreSource§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.