Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 6 additions & 17 deletions encodings/alp/src/alp/decompress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

use std::mem::transmute;

use vortex_array::Canonical;
use vortex_array::ExecutionCtx;
use vortex_array::ToCanonical;
use vortex_array::arrays::PrimitiveArray;
Expand Down Expand Up @@ -71,21 +70,11 @@ pub fn execute_decompress(array: ALPArray, ctx: &mut ExecutionCtx) -> VortexResu
if let Some(ref patches) = patches
&& let Some(chunk_offsets) = patches.chunk_offsets()
{
let encoded = encoded.execute::<Canonical>(ctx)?.into_primitive();
let patches_chunk_offsets = chunk_offsets
.clone()
.execute::<Canonical>(ctx)?
.into_primitive();
let patches_indices = patches
.indices()
.clone()
.execute::<Canonical>(ctx)?
.into_primitive();
let patches_values = patches
.values()
.clone()
.execute::<Canonical>(ctx)?
.into_primitive();
// TODO(joe): have into parts.
let encoded = encoded.execute::<PrimitiveArray>(ctx)?;
let patches_chunk_offsets = chunk_offsets.clone().execute::<PrimitiveArray>(ctx)?;
let patches_indices = patches.indices().clone().execute::<PrimitiveArray>(ctx)?;
let patches_values = patches.values().clone().execute::<PrimitiveArray>(ctx)?;
Ok(decompress_chunked_core(
encoded,
exponents,
Expand All @@ -96,7 +85,7 @@ pub fn execute_decompress(array: ALPArray, ctx: &mut ExecutionCtx) -> VortexResu
dtype,
))
} else {
let encoded = encoded.execute::<Canonical>(ctx)?.into_primitive();
let encoded = encoded.execute::<PrimitiveArray>(ctx)?;
Ok(decompress_unchunked_core(encoded, exponents, None, dtype))
}
}
Expand Down
3 changes: 1 addition & 2 deletions vortex-array/src/arrow/executor/bool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use arrow_array::BooleanArray as ArrowBooleanArray;
use vortex_error::VortexResult;

use crate::ArrayRef;
use crate::Canonical;
use crate::ExecutionCtx;
use crate::arrays::BoolArray;
use crate::arrow::null_buffer::to_null_buffer;
Expand All @@ -25,6 +24,6 @@ pub(super) fn to_arrow_bool(
array: ArrayRef,
ctx: &mut ExecutionCtx,
) -> VortexResult<ArrowArrayRef> {
let bool_array = array.execute::<Canonical>(ctx)?.into_bool();
let bool_array = array.execute::<BoolArray>(ctx)?;
Ok(canonical_bool_to_arrow(&bool_array))
}
3 changes: 1 addition & 2 deletions vortex-array/src/arrow/executor/byte_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use vortex_dtype::arrow::FromArrowType;
use vortex_error::VortexResult;

use crate::ArrayRef;
use crate::Canonical;
use crate::ExecutionCtx;
use crate::arrays::VarBinViewArray;
use crate::arrow::null_buffer::to_null_buffer;
Expand Down Expand Up @@ -44,6 +43,6 @@ pub(super) fn to_arrow_byte_view<T: ByteViewType>(
// flexible since there's no prescribed nullability in Arrow types.
let array = array.cast(DType::from_arrow((&T::DATA_TYPE, Nullability::Nullable)))?;

let varbinview = array.execute::<Canonical>(ctx)?.into_varbinview();
let varbinview = array.execute::<VarBinViewArray>(ctx)?;
Ok(canonical_varbinview_to_arrow::<T>(&varbinview))
}
5 changes: 2 additions & 3 deletions vortex-array/src/arrow/executor/null.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use arrow_array::NullArray as ArrowNullArray;
use vortex_error::VortexResult;

use crate::ArrayRef;
use crate::Canonical;
use crate::ExecutionCtx;
use crate::arrays::NullArray;

Expand All @@ -21,6 +20,6 @@ pub(super) fn to_arrow_null(
array: ArrayRef,
ctx: &mut ExecutionCtx,
) -> VortexResult<ArrowArrayRef> {
let canonical = array.execute::<Canonical>(ctx)?.into_null();
Ok(canonical_null_to_arrow(&canonical))
let null_array = array.execute::<NullArray>(ctx)?;
Ok(canonical_null_to_arrow(&null_array))
}
3 changes: 1 addition & 2 deletions vortex-array/src/arrow/executor/primitive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ use vortex_dtype::Nullability;
use vortex_error::VortexResult;

use crate::ArrayRef;
use crate::Canonical;
use crate::ExecutionCtx;
use crate::arrays::PrimitiveArray;
use crate::arrow::null_buffer::to_null_buffer;
Expand All @@ -38,6 +37,6 @@ where
{
// We use nullable here so we can essentially ignore nullability during the cast.
let array = array.cast(DType::Primitive(T::Native::PTYPE, Nullability::Nullable))?;
let primitive = array.execute::<Canonical>(ctx)?.into_primitive();
let primitive = array.execute::<PrimitiveArray>(ctx)?;
Ok(canonical_primitive_to_arrow::<T>(primitive))
}
8 changes: 4 additions & 4 deletions vortex-array/src/arrow/executor/temporal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ use vortex_error::vortex_ensure;

use crate::Array;
use crate::ArrayRef;
use crate::Canonical;
use crate::ExecutionCtx;
use crate::arrays::ExtensionArray;
use crate::arrays::PrimitiveArray as VortexPrimitiveArray;
use crate::arrow::null_buffer::to_null_buffer;

pub(super) fn to_arrow_temporal(
Expand Down Expand Up @@ -122,12 +123,11 @@ where
{
debug_assert!(TemporalMetadata::try_from(array.dtype().as_extension()).is_ok());

let ext_array = array.execute::<Canonical>(ctx)?.into_extension();
let ext_array = array.execute::<ExtensionArray>(ctx)?;
let primitive = ext_array
.storage()
.clone()
.execute::<Canonical>(ctx)?
.into_primitive();
.execute::<VortexPrimitiveArray>(ctx)?;
vortex_ensure!(
primitive.ptype() == T::Native::PTYPE,
"Expected temporal array to produce vector of width {}, found {}",
Expand Down
5 changes: 3 additions & 2 deletions vortex-array/src/canonical_to_vector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ use crate::ArrayRef;
use crate::Canonical;
use crate::Executable;
use crate::ExecutionCtx;
use crate::arrays::PrimitiveArray;

impl Executable for Vector {
fn execute(array: ArrayRef, ctx: &mut ExecutionCtx) -> VortexResult<Self> {
Expand Down Expand Up @@ -119,8 +120,8 @@ impl Canonical {

let validity = validity.to_array(offsets.len()).execute::<Mask>(ctx)?;
let elements_vector = elements.execute::<Vector>(ctx)?;
let offsets = offsets.execute::<Canonical>(ctx)?.into_primitive();
let sizes = sizes.execute::<Canonical>(ctx)?.into_primitive();
let offsets = offsets.execute::<PrimitiveArray>(ctx)?;
let sizes = sizes.execute::<PrimitiveArray>(ctx)?;
let offsets_ptype = offsets.ptype();
let sizes_ptype = sizes.ptype();

Expand Down
128 changes: 128 additions & 0 deletions vortex-array/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,30 @@ use vortex_session::VortexSession;
use crate::Array;
use crate::ArrayRef;
use crate::Canonical;
use crate::arrays::BoolArray;
use crate::arrays::BoolVTable;
use crate::arrays::ConstantArray;
use crate::arrays::ConstantVTable;
use crate::arrays::DecimalArray;
use crate::arrays::DecimalVTable;
use crate::arrays::ExtensionArray;
use crate::arrays::ExtensionVTable;
use crate::arrays::FixedSizeListArray;
use crate::arrays::FixedSizeListVTable;
use crate::arrays::ListViewArray;
use crate::arrays::ListViewVTable;
use crate::arrays::NullArray;
use crate::arrays::NullVTable;
use crate::arrays::PrimitiveArray;
use crate::arrays::PrimitiveVTable;
use crate::arrays::StructArray;
use crate::arrays::StructVTable;
use crate::arrays::VarBinViewArray;
use crate::arrays::VarBinViewVTable;

/// Marker trait for types that can be executed.
///
/// If the `ArrayRef` cannot inhabit `Self` this will panic.
pub trait Executable: Sized {
fn execute(array: ArrayRef, ctx: &mut ExecutionCtx) -> VortexResult<Self>;
}
Expand Down Expand Up @@ -99,6 +119,114 @@ impl Executable for CanonicalOutput {
}
}

/// Execute the array to canonical form and unwrap as a [`PrimitiveArray`].
///
/// This will panic if the array's dtype is not primitive.
impl Executable for PrimitiveArray {
fn execute(array: ArrayRef, ctx: &mut ExecutionCtx) -> VortexResult<Self> {
match array.try_into::<PrimitiveVTable>() {
Ok(primitive) => Ok(primitive),
Err(array) => Ok(array.execute::<Canonical>(ctx)?.into_primitive()),
}
}
}

/// Execute the array to canonical form and unwrap as a [`BoolArray`].
///
/// This will panic if the array's dtype is not bool.
impl Executable for BoolArray {
fn execute(array: ArrayRef, ctx: &mut ExecutionCtx) -> VortexResult<Self> {
match array.try_into::<BoolVTable>() {
Ok(bool_array) => Ok(bool_array),
Err(array) => Ok(array.execute::<Canonical>(ctx)?.into_bool()),
}
}
}

/// Execute the array to canonical form and unwrap as a [`NullArray`].
///
/// This will panic if the array's dtype is not null.
impl Executable for NullArray {
fn execute(array: ArrayRef, ctx: &mut ExecutionCtx) -> VortexResult<Self> {
match array.try_into::<NullVTable>() {
Ok(null_array) => Ok(null_array),
Err(array) => Ok(array.execute::<Canonical>(ctx)?.into_null()),
}
}
}

/// Execute the array to canonical form and unwrap as a [`VarBinViewArray`].
///
/// This will panic if the array's dtype is not utf8 or binary.
impl Executable for VarBinViewArray {
fn execute(array: ArrayRef, ctx: &mut ExecutionCtx) -> VortexResult<Self> {
match array.try_into::<VarBinViewVTable>() {
Ok(varbinview) => Ok(varbinview),
Err(array) => Ok(array.execute::<Canonical>(ctx)?.into_varbinview()),
}
}
}

/// Execute the array to canonical form and unwrap as an [`ExtensionArray`].
///
/// This will panic if the array's dtype is not an extension type.
impl Executable for ExtensionArray {
fn execute(array: ArrayRef, ctx: &mut ExecutionCtx) -> VortexResult<Self> {
match array.try_into::<ExtensionVTable>() {
Ok(ext_array) => Ok(ext_array),
Err(array) => Ok(array.execute::<Canonical>(ctx)?.into_extension()),
}
}
}

/// Execute the array to canonical form and unwrap as a [`DecimalArray`].
///
/// This will panic if the array's dtype is not decimal.
impl Executable for DecimalArray {
fn execute(array: ArrayRef, ctx: &mut ExecutionCtx) -> VortexResult<Self> {
match array.try_into::<DecimalVTable>() {
Ok(decimal) => Ok(decimal),
Err(array) => Ok(array.execute::<Canonical>(ctx)?.into_decimal()),
}
}
}

/// Execute the array to canonical form and unwrap as a [`ListViewArray`].
///
/// This will panic if the array's dtype is not list.
impl Executable for ListViewArray {
fn execute(array: ArrayRef, ctx: &mut ExecutionCtx) -> VortexResult<Self> {
match array.try_into::<ListViewVTable>() {
Ok(list) => Ok(list),
Err(array) => Ok(array.execute::<Canonical>(ctx)?.into_listview()),
}
}
}

/// Execute the array to canonical form and unwrap as a [`FixedSizeListArray`].
///
/// This will panic if the array's dtype is not fixed size list.
impl Executable for FixedSizeListArray {
fn execute(array: ArrayRef, ctx: &mut ExecutionCtx) -> VortexResult<Self> {
match array.try_into::<FixedSizeListVTable>() {
Ok(fsl) => Ok(fsl),
Err(array) => Ok(array.execute::<Canonical>(ctx)?.into_fixed_size_list()),
}
}
}

/// Execute the array to canonical form and unwrap as a [`StructArray`].
///
/// This will panic if the array's dtype is not struct.
impl Executable for StructArray {
fn execute(array: ArrayRef, ctx: &mut ExecutionCtx) -> VortexResult<Self> {
match array.try_into::<StructVTable>() {
Ok(struct_array) => Ok(struct_array),
Err(array) => Ok(array.execute::<Canonical>(ctx)?.into_struct()),
}
}
}

/// Extension trait for creating an execution context from a session.
pub trait VortexSessionExecute {
/// Create a new execution context from this session.
Expand Down
Loading