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
10 changes: 1 addition & 9 deletions encodings/alp/src/alp/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ use vortex_array::vtable::ArrayId;
use vortex_array::vtable::ArrayVTable;
use vortex_array::vtable::ArrayVTableExt;
use vortex_array::vtable::BaseArrayVTable;
use vortex_array::vtable::CanonicalVTable;
use vortex_array::vtable::NotSupported;
use vortex_array::vtable::VTable;
use vortex_array::vtable::ValidityChild;
Expand All @@ -46,7 +45,6 @@ use vortex_error::vortex_err;

use crate::ALPFloat;
use crate::alp::Exponents;
use crate::alp::decompress::decompress_into_array;
use crate::alp::decompress::execute_decompress;

vtable!(ALP);
Expand All @@ -57,7 +55,6 @@ impl VTable for ALPVTable {
type Metadata = ProstMetadata<ALPMetadata>;

type ArrayVTable = Self;
type CanonicalVTable = Self;
type OperationsVTable = Self;
type ValidityVTable = ValidityVTableFromChild;
type VisitorVTable = Self;
Expand Down Expand Up @@ -456,12 +453,6 @@ impl BaseArrayVTable<ALPVTable> for ALPVTable {
}
}

impl CanonicalVTable<ALPVTable> for ALPVTable {
fn canonicalize(array: &ALPArray) -> VortexResult<Canonical> {
Ok(Canonical::Primitive(decompress_into_array(array.clone())))
}
}

impl VisitorVTable<ALPVTable> for ALPVTable {
fn visit_buffers(_array: &ALPArray, _visitor: &mut dyn ArrayBufferVisitor) {}

Expand Down Expand Up @@ -490,6 +481,7 @@ mod tests {

use super::*;
use crate::alp_encode;
use crate::decompress_into_array;

static SESSION: LazyLock<VortexSession> =
LazyLock::new(|| VortexSession::empty().with::<ArraySession>());
Expand Down
73 changes: 35 additions & 38 deletions encodings/alp/src/alp_rd/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use vortex_array::ArrayHash;
use vortex_array::ArrayRef;
use vortex_array::Canonical;
use vortex_array::DeserializeMetadata;
use vortex_array::ExecutionCtx;
use vortex_array::IntoArray;
use vortex_array::Precision;
use vortex_array::ProstMetadata;
Expand All @@ -31,7 +32,6 @@ use vortex_array::vtable::ArrayId;
use vortex_array::vtable::ArrayVTable;
use vortex_array::vtable::ArrayVTableExt;
use vortex_array::vtable::BaseArrayVTable;
use vortex_array::vtable::CanonicalVTable;
use vortex_array::vtable::NotSupported;
use vortex_array::vtable::VTable;
use vortex_array::vtable::ValidityChild;
Expand Down Expand Up @@ -72,7 +72,6 @@ impl VTable for ALPRDVTable {
type Metadata = ProstMetadata<ALPRDMetadata>;

type ArrayVTable = Self;
type CanonicalVTable = Self;
type OperationsVTable = Self;
type ValidityVTable = ValidityVTableFromChild;
type VisitorVTable = Self;
Expand Down Expand Up @@ -245,6 +244,40 @@ impl VTable for ALPRDVTable {

Ok(())
}

fn execute(array: &Self::Array, _ctx: &mut ExecutionCtx) -> VortexResult<Canonical> {
let left_parts = array.left_parts().to_primitive();
let right_parts = array.right_parts().to_primitive();

// Decode the left_parts using our builtin dictionary.
let left_parts_dict = array.left_parts_dictionary();

let decoded_array = if array.is_f32() {
PrimitiveArray::new(
alp_rd_decode::<f32>(
left_parts.into_buffer::<u16>(),
left_parts_dict,
array.right_bit_width,
right_parts.into_buffer_mut::<u32>(),
array.left_parts_patches(),
),
Validity::copy_from_array(array.as_ref()),
)
} else {
PrimitiveArray::new(
alp_rd_decode::<f64>(
left_parts.into_buffer::<u16>(),
left_parts_dict,
array.right_bit_width,
right_parts.into_buffer_mut::<u64>(),
array.left_parts_patches(),
),
Validity::copy_from_array(array.as_ref()),
)
};

Ok(Canonical::Primitive(decoded_array))
}
}

#[derive(Clone, Debug)]
Expand Down Expand Up @@ -427,42 +460,6 @@ impl BaseArrayVTable<ALPRDVTable> for ALPRDVTable {
}
}

impl CanonicalVTable<ALPRDVTable> for ALPRDVTable {
fn canonicalize(array: &ALPRDArray) -> VortexResult<Canonical> {
let left_parts = array.left_parts().to_primitive();
let right_parts = array.right_parts().to_primitive();

// Decode the left_parts using our builtin dictionary.
let left_parts_dict = array.left_parts_dictionary();

let decoded_array = if array.is_f32() {
PrimitiveArray::new(
alp_rd_decode::<f32>(
left_parts.into_buffer::<u16>(),
left_parts_dict,
array.right_bit_width,
right_parts.into_buffer_mut::<u32>(),
array.left_parts_patches(),
),
Validity::copy_from_array(array.as_ref()),
)
} else {
PrimitiveArray::new(
alp_rd_decode::<f64>(
left_parts.into_buffer::<u16>(),
left_parts_dict,
array.right_bit_width,
right_parts.into_buffer_mut::<u64>(),
array.left_parts_patches(),
),
Validity::copy_from_array(array.as_ref()),
)
};

Ok(Canonical::Primitive(decoded_array))
}
}

impl VisitorVTable<ALPRDVTable> for ALPRDVTable {
fn visit_buffers(_array: &ALPRDArray, _visitor: &mut dyn ArrayBufferVisitor) {}

Expand Down
23 changes: 10 additions & 13 deletions encodings/bytebool/src/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use vortex_array::ArrayHash;
use vortex_array::ArrayRef;
use vortex_array::Canonical;
use vortex_array::EmptyMetadata;
use vortex_array::ExecutionCtx;
use vortex_array::IntoArray;
use vortex_array::Precision;
use vortex_array::arrays::BoolArray;
Expand All @@ -25,7 +26,6 @@ use vortex_array::vtable::ArrayId;
use vortex_array::vtable::ArrayVTable;
use vortex_array::vtable::ArrayVTableExt;
use vortex_array::vtable::BaseArrayVTable;
use vortex_array::vtable::CanonicalVTable;
use vortex_array::vtable::NotSupported;
use vortex_array::vtable::OperationsVTable;
use vortex_array::vtable::VTable;
Expand All @@ -50,7 +50,6 @@ impl VTable for ByteBoolVTable {
type Metadata = EmptyMetadata;

type ArrayVTable = Self;
type CanonicalVTable = Self;
type OperationsVTable = Self;
type ValidityVTable = ValidityVTableFromValidityHelper;
type VisitorVTable = Self;
Expand Down Expand Up @@ -126,6 +125,15 @@ impl VTable for ByteBoolVTable {
.into_array(),
))
}

fn execute(array: &Self::Array, _ctx: &mut ExecutionCtx) -> VortexResult<Canonical> {
let boolean_buffer = BitBuffer::from(array.as_slice());
let validity = array.validity().clone();
Ok(Canonical::Bool(BoolArray::from_bit_buffer(
boolean_buffer,
validity,
)))
}
}

#[derive(Clone, Debug)]
Expand Down Expand Up @@ -213,17 +221,6 @@ impl BaseArrayVTable<ByteBoolVTable> for ByteBoolVTable {
}
}

impl CanonicalVTable<ByteBoolVTable> for ByteBoolVTable {
fn canonicalize(array: &ByteBoolArray) -> VortexResult<Canonical> {
let boolean_buffer = BitBuffer::from(array.as_slice());
let validity = array.validity().clone();
Ok(Canonical::Bool(BoolArray::from_bit_buffer(
boolean_buffer,
validity,
)))
}
}

impl OperationsVTable<ByteBoolVTable> for ByteBoolVTable {
fn scalar_at(array: &ByteBoolArray, index: usize) -> Scalar {
Scalar::bool(array.buffer()[index] == 1, array.dtype().nullability())
Expand Down
8 changes: 7 additions & 1 deletion encodings/datetime-parts/src/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ use vortex_array::ArrayChildVisitor;
use vortex_array::ArrayEq;
use vortex_array::ArrayHash;
use vortex_array::ArrayRef;
use vortex_array::Canonical;
use vortex_array::DeserializeMetadata;
use vortex_array::ExecutionCtx;
use vortex_array::IntoArray;
use vortex_array::Precision;
use vortex_array::ProstMetadata;
Expand Down Expand Up @@ -39,6 +41,7 @@ use vortex_error::vortex_bail;
use vortex_error::vortex_ensure;
use vortex_error::vortex_err;

use crate::canonical::decode_to_temporal;
use crate::compute::rules::PARENT_RULES;

vtable!(DateTimeParts);
Expand Down Expand Up @@ -79,7 +82,6 @@ impl VTable for DateTimePartsVTable {
type Metadata = ProstMetadata<DateTimePartsMetadata>;

type ArrayVTable = Self;
type CanonicalVTable = Self;
type OperationsVTable = Self;
type ValidityVTable = ValidityVTableFromChild;
type VisitorVTable = Self;
Expand Down Expand Up @@ -160,6 +162,10 @@ impl VTable for DateTimePartsVTable {
Ok(())
}

fn execute(array: &Self::Array, _ctx: &mut ExecutionCtx) -> VortexResult<Canonical> {
Ok(Canonical::Extension(decode_to_temporal(array).into()))
}

fn reduce_parent(
array: &Self::Array,
parent: &ArrayRef,
Expand Down
10 changes: 0 additions & 10 deletions encodings/datetime-parts/src/canonical.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,22 @@
// SPDX-FileCopyrightText: Copyright the Vortex contributors

use num_traits::AsPrimitive;
use vortex_array::Canonical;
use vortex_array::IntoArray;
use vortex_array::ToCanonical;
use vortex_array::arrays::PrimitiveArray;
use vortex_array::arrays::TemporalArray;
use vortex_array::compute::cast;
use vortex_array::validity::Validity;
use vortex_array::vtable::CanonicalVTable;
use vortex_buffer::BufferMut;
use vortex_dtype::DType;
use vortex_dtype::PType;
use vortex_dtype::datetime::TemporalMetadata;
use vortex_dtype::datetime::TimeUnit;
use vortex_dtype::match_each_integer_ptype;
use vortex_error::VortexExpect as _;
use vortex_error::VortexResult;
use vortex_error::vortex_panic;

use crate::DateTimePartsArray;
use crate::DateTimePartsVTable;

impl CanonicalVTable<DateTimePartsVTable> for DateTimePartsVTable {
fn canonicalize(array: &DateTimePartsArray) -> VortexResult<Canonical> {
Ok(Canonical::Extension(decode_to_temporal(array).into()))
}
}

/// Decode an [Array] into a [TemporalArray].
///
Expand Down
44 changes: 23 additions & 21 deletions encodings/decimal-byte-parts/src/decimal_byte_parts/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use vortex_array::ArrayEq;
use vortex_array::ArrayHash;
use vortex_array::ArrayRef;
use vortex_array::Canonical;
use vortex_array::ExecutionCtx;
use vortex_array::IntoArray;
use vortex_array::Precision;
use vortex_array::ProstMetadata;
Expand All @@ -30,7 +31,6 @@ use vortex_array::vtable::ArrayId;
use vortex_array::vtable::ArrayVTable;
use vortex_array::vtable::ArrayVTableExt;
use vortex_array::vtable::BaseArrayVTable;
use vortex_array::vtable::CanonicalVTable;
use vortex_array::vtable::NotSupported;
use vortex_array::vtable::OperationsVTable;
use vortex_array::vtable::VTable;
Expand Down Expand Up @@ -67,7 +67,6 @@ impl VTable for DecimalBytePartsVTable {
type Metadata = ProstMetadata<DecimalBytesPartsMetadata>;

type ArrayVTable = Self;
type CanonicalVTable = Self;
type OperationsVTable = Self;
type ValidityVTable = ValidityVTableFromChild;
type VisitorVTable = Self;
Expand Down Expand Up @@ -145,6 +144,10 @@ impl VTable for DecimalBytePartsVTable {
.into_array()
}))
}

fn execute(array: &Self::Array, _ctx: &mut ExecutionCtx) -> VortexResult<Canonical> {
to_canonical_decimal(array)
}
}

/// This array encodes decimals as between 1-4 columns of primitive typed children.
Expand Down Expand Up @@ -233,25 +236,24 @@ impl BaseArrayVTable<DecimalBytePartsVTable> for DecimalBytePartsVTable {
}
}

impl CanonicalVTable<DecimalBytePartsVTable> for DecimalBytePartsVTable {
fn canonicalize(array: &DecimalBytePartsArray) -> VortexResult<Canonical> {
// TODO(joe): support parts len != 1
let prim = array.msp.to_primitive();
// Depending on the decimal type and the min/max of the primitive array we can choose
// the correct buffer size

Ok(match_each_signed_integer_ptype!(prim.ptype(), |P| {
// SAFETY: The primitive array's buffer is already validated with correct type.
// The decimal dtype matches the array's dtype, and validity is preserved.
Canonical::Decimal(unsafe {
DecimalArray::new_unchecked(
prim.to_buffer::<P>(),
*array.decimal_dtype(),
prim.validity().clone(),
)
})
}))
}
/// Converts a DecimalBytePartsArray to its canonical DecimalArray representation.
fn to_canonical_decimal(array: &DecimalBytePartsArray) -> VortexResult<Canonical> {
// TODO(joe): support parts len != 1
let prim = array.msp.to_primitive();
// Depending on the decimal type and the min/max of the primitive array we can choose
// the correct buffer size

Ok(match_each_signed_integer_ptype!(prim.ptype(), |P| {
// SAFETY: The primitive array's buffer is already validated with correct type.
// The decimal dtype matches the array's dtype, and validity is preserved.
Canonical::Decimal(unsafe {
DecimalArray::new_unchecked(
prim.to_buffer::<P>(),
*array.decimal_dtype(),
prim.validity().clone(),
)
})
}))
}

impl OperationsVTable<DecimalBytePartsVTable> for DecimalBytePartsVTable {
Expand Down
36 changes: 0 additions & 36 deletions encodings/fastlanes/src/bitpacking/vtable/canonical.rs

This file was deleted.

Loading
Loading