pub trait LogicalType {
type Typed: Clone;
type Value<'a>
where Self: 'a;
type Owned;
const NULLABLE: bool = false;
// Required methods
fn downcast(array: &dyn Array) -> Result<Self::Typed, ColumnError>;
fn is_null(typed: &Self::Typed, index: usize) -> bool;
fn value(typed: &Self::Typed, index: usize) -> Self::Value<'_>;
fn to_owned_value(value: Self::Value<'_>) -> Self::Owned;
}Expand description
A logical column type, e.g. Utf8, Option<i64>, or List<Utf8>.
Option<L> means the values at this nesting level may be null.
The primitive Rust types implement it directly, and Option<L> adds
nullability at any nesting level:
use quiver::Column;
let numbers = Column::<i64>::from_values([1, 2, 3]);
assert_eq!(numbers.value(0), 1);
assert_eq!(numbers.as_slice(), &[1, 2, 3]); // bulk, zero-copy (not for `bool`)
let maybe = Column::<Option<i64>>::from_values([Some(1), None]);
assert_eq!(maybe.value(1), None);Provided Associated Constants§
Required Associated Types§
Sourcetype Typed: Clone
type Typed: Clone
The fully-downcast, validated representation of one column of this datatype. Cheap to clone (arrow arrays are reference-counted).
Required Methods§
Sourcefn downcast(array: &dyn Array) -> Result<Self::Typed, ColumnError>
fn downcast(array: &dyn Array) -> Result<Self::Typed, ColumnError>
Validates that array has an acceptable datatype, then recursively
downcasts it — checking the nulls of all children along the way.
This is the single validation+downcast hook, called once per column at the
boundary (Column::try_new). It must reject any
array whose datatype this logical type does not accept (returning
ColumnError::WrongDatatype), including datatype parameters not
encoded in the concrete arrow array’s Rust type — a
FixedSizeBinary / FixedSizeList
size, a Timestamp timezone, etc. The leaf type check
comes from the concrete-array downcast; nested element types are
validated by recursing into the children’s downcast.
Multi-encoding types like AnyList inspect
array.data_type() and dispatch to the matching encoding.
Nulls at the level of array itself are the responsibility of the caller
(the parent datatype, or Column::try_new at the
top level), because only the caller knows if this level is wrapped in an
Option.
§Errors
Errors on a datatype mismatch, or on unexpected nulls in children.
Sourcefn value(typed: &Self::Typed, index: usize) -> Self::Value<'_>
fn value(typed: &Self::Typed, index: usize) -> Self::Value<'_>
The value at index.
Contract: index is in bounds, and the value is non-null unless Self is an Option.
Sourcefn to_owned_value(value: Self::Value<'_>) -> Self::Owned
fn to_owned_value(value: Self::Value<'_>) -> Self::Owned
Converts a borrowed element value into an owned one,
e.g. &str → String.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementations on Foreign Types§
Source§impl LogicalType for bool
impl LogicalType for bool
type Typed = BooleanArray
type Value<'a> = bool
type Owned = bool
fn downcast( array: &dyn Array, ) -> Result<<bool as LogicalType>::Typed, ColumnError>
fn is_null(typed: &<bool as LogicalType>::Typed, index: usize) -> bool
fn value( typed: &<bool as LogicalType>::Typed, index: usize, ) -> <bool as LogicalType>::Value<'_>
fn to_owned_value( value: <bool as LogicalType>::Value<'_>, ) -> <bool as LogicalType>::Owned
Source§impl LogicalType for f32
impl LogicalType for f32
type Typed = PrimitiveArray<Float32Type>
type Value<'a> = f32
type Owned = f32
fn downcast( array: &dyn Array, ) -> Result<<f32 as LogicalType>::Typed, ColumnError>
fn is_null(typed: &<f32 as LogicalType>::Typed, index: usize) -> bool
fn value( typed: &<f32 as LogicalType>::Typed, index: usize, ) -> <f32 as LogicalType>::Value<'_>
fn to_owned_value( value: <f32 as LogicalType>::Value<'_>, ) -> <f32 as LogicalType>::Owned
Source§impl LogicalType for f64
impl LogicalType for f64
type Typed = PrimitiveArray<Float64Type>
type Value<'a> = f64
type Owned = f64
fn downcast( array: &dyn Array, ) -> Result<<f64 as LogicalType>::Typed, ColumnError>
fn is_null(typed: &<f64 as LogicalType>::Typed, index: usize) -> bool
fn value( typed: &<f64 as LogicalType>::Typed, index: usize, ) -> <f64 as LogicalType>::Value<'_>
fn to_owned_value( value: <f64 as LogicalType>::Value<'_>, ) -> <f64 as LogicalType>::Owned
Source§impl LogicalType for i8
impl LogicalType for i8
type Typed = PrimitiveArray<Int8Type>
type Value<'a> = i8
type Owned = i8
fn downcast( array: &dyn Array, ) -> Result<<i8 as LogicalType>::Typed, ColumnError>
fn is_null(typed: &<i8 as LogicalType>::Typed, index: usize) -> bool
fn value( typed: &<i8 as LogicalType>::Typed, index: usize, ) -> <i8 as LogicalType>::Value<'_>
fn to_owned_value( value: <i8 as LogicalType>::Value<'_>, ) -> <i8 as LogicalType>::Owned
Source§impl LogicalType for i16
impl LogicalType for i16
type Typed = PrimitiveArray<Int16Type>
type Value<'a> = i16
type Owned = i16
fn downcast( array: &dyn Array, ) -> Result<<i16 as LogicalType>::Typed, ColumnError>
fn is_null(typed: &<i16 as LogicalType>::Typed, index: usize) -> bool
fn value( typed: &<i16 as LogicalType>::Typed, index: usize, ) -> <i16 as LogicalType>::Value<'_>
fn to_owned_value( value: <i16 as LogicalType>::Value<'_>, ) -> <i16 as LogicalType>::Owned
Source§impl LogicalType for i32
impl LogicalType for i32
type Typed = PrimitiveArray<Int32Type>
type Value<'a> = i32
type Owned = i32
fn downcast( array: &dyn Array, ) -> Result<<i32 as LogicalType>::Typed, ColumnError>
fn is_null(typed: &<i32 as LogicalType>::Typed, index: usize) -> bool
fn value( typed: &<i32 as LogicalType>::Typed, index: usize, ) -> <i32 as LogicalType>::Value<'_>
fn to_owned_value( value: <i32 as LogicalType>::Value<'_>, ) -> <i32 as LogicalType>::Owned
Source§impl LogicalType for i64
impl LogicalType for i64
type Typed = PrimitiveArray<Int64Type>
type Value<'a> = i64
type Owned = i64
fn downcast( array: &dyn Array, ) -> Result<<i64 as LogicalType>::Typed, ColumnError>
fn is_null(typed: &<i64 as LogicalType>::Typed, index: usize) -> bool
fn value( typed: &<i64 as LogicalType>::Typed, index: usize, ) -> <i64 as LogicalType>::Value<'_>
fn to_owned_value( value: <i64 as LogicalType>::Value<'_>, ) -> <i64 as LogicalType>::Owned
Source§impl LogicalType for u8
impl LogicalType for u8
type Typed = PrimitiveArray<UInt8Type>
type Value<'a> = u8
type Owned = u8
fn downcast( array: &dyn Array, ) -> Result<<u8 as LogicalType>::Typed, ColumnError>
fn is_null(typed: &<u8 as LogicalType>::Typed, index: usize) -> bool
fn value( typed: &<u8 as LogicalType>::Typed, index: usize, ) -> <u8 as LogicalType>::Value<'_>
fn to_owned_value( value: <u8 as LogicalType>::Value<'_>, ) -> <u8 as LogicalType>::Owned
Source§impl LogicalType for u16
impl LogicalType for u16
type Typed = PrimitiveArray<UInt16Type>
type Value<'a> = u16
type Owned = u16
fn downcast( array: &dyn Array, ) -> Result<<u16 as LogicalType>::Typed, ColumnError>
fn is_null(typed: &<u16 as LogicalType>::Typed, index: usize) -> bool
fn value( typed: &<u16 as LogicalType>::Typed, index: usize, ) -> <u16 as LogicalType>::Value<'_>
fn to_owned_value( value: <u16 as LogicalType>::Value<'_>, ) -> <u16 as LogicalType>::Owned
Source§impl LogicalType for u32
impl LogicalType for u32
type Typed = PrimitiveArray<UInt32Type>
type Value<'a> = u32
type Owned = u32
fn downcast( array: &dyn Array, ) -> Result<<u32 as LogicalType>::Typed, ColumnError>
fn is_null(typed: &<u32 as LogicalType>::Typed, index: usize) -> bool
fn value( typed: &<u32 as LogicalType>::Typed, index: usize, ) -> <u32 as LogicalType>::Value<'_>
fn to_owned_value( value: <u32 as LogicalType>::Value<'_>, ) -> <u32 as LogicalType>::Owned
Source§impl LogicalType for u64
impl LogicalType for u64
type Typed = PrimitiveArray<UInt64Type>
type Value<'a> = u64
type Owned = u64
fn downcast( array: &dyn Array, ) -> Result<<u64 as LogicalType>::Typed, ColumnError>
fn is_null(typed: &<u64 as LogicalType>::Typed, index: usize) -> bool
fn value( typed: &<u64 as LogicalType>::Typed, index: usize, ) -> <u64 as LogicalType>::Value<'_>
fn to_owned_value( value: <u64 as LogicalType>::Value<'_>, ) -> <u64 as LogicalType>::Owned
Source§impl<L> LogicalType for Option<L>where
L: LogicalType,
Option<L>: the values at this level may be null.
impl<L> LogicalType for Option<L>where
L: LogicalType,
Option<L>: the values at this level may be null.