Skip to content
Closed
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
4 changes: 2 additions & 2 deletions encodings/alp/public-api.lock
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ pub fn vortex_alp::ALP::compare(lhs: vortex_array::array::view::ArrayView<'_, Se

impl vortex_array::scalar_fn::fns::cast::kernel::CastReduce for vortex_alp::ALP

pub fn vortex_alp::ALP::cast(array: vortex_array::array::view::ArrayView<'_, Self>, dtype: &vortex_array::dtype::DType) -> vortex_error::VortexResult<core::option::Option<vortex_array::array::erased::ArrayRef>>
pub fn vortex_alp::ALP::cast(array: vortex_array::array::view::ArrayView<'_, Self>, dtype: &vortex_array::dtype::DType, options: &vortex_array::scalar_fn::fns::cast::CastOptions) -> vortex_error::VortexResult<core::option::Option<vortex_array::array::erased::ArrayRef>>

impl vortex_array::scalar_fn::fns::mask::kernel::MaskKernel for vortex_alp::ALP

Expand Down Expand Up @@ -208,7 +208,7 @@ pub fn vortex_alp::ALPRD::slice(array: vortex_array::array::view::ArrayView<'_,

impl vortex_array::scalar_fn::fns::cast::kernel::CastReduce for vortex_alp::ALPRD

pub fn vortex_alp::ALPRD::cast(array: vortex_array::array::view::ArrayView<'_, Self>, dtype: &vortex_array::dtype::DType) -> vortex_error::VortexResult<core::option::Option<vortex_array::array::erased::ArrayRef>>
pub fn vortex_alp::ALPRD::cast(array: vortex_array::array::view::ArrayView<'_, Self>, dtype: &vortex_array::dtype::DType, options: &vortex_array::scalar_fn::fns::cast::CastOptions) -> vortex_error::VortexResult<core::option::Option<vortex_array::array::erased::ArrayRef>>

impl vortex_array::scalar_fn::fns::mask::kernel::MaskReduce for vortex_alp::ALPRD

Expand Down
12 changes: 9 additions & 3 deletions encodings/alp/src/alp/compute/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use vortex_array::IntoArray;
use vortex_array::builtins::ArrayBuiltins;
use vortex_array::dtype::DType;
use vortex_array::patches::Patches;
use vortex_array::scalar_fn::fns::cast::CastOptions;
use vortex_array::scalar_fn::fns::cast::CastReduce;
use vortex_error::VortexResult;

Expand All @@ -15,16 +16,21 @@ use crate::ALPArraySlotsExt;
use crate::alp::ALP;

impl CastReduce for ALP {
fn cast(array: ArrayView<'_, Self>, dtype: &DType) -> VortexResult<Option<ArrayRef>> {
fn cast(
array: ArrayView<'_, Self>,
dtype: &DType,
options: &CastOptions,
) -> VortexResult<Option<ArrayRef>> {
// Check if this is just a nullability change
if array.dtype().eq_ignore_nullability(dtype) {
// For nullability-only changes, we can avoid decoding
// Cast the encoded array (integers) to handle nullability
let new_encoded = array.encoded().cast(
let new_encoded = array.encoded().cast_opts(
array
.encoded()
.dtype()
.with_nullability(dtype.nullability()),
*options,
)?;

let new_patches = array
Expand All @@ -37,7 +43,7 @@ impl CastReduce for ALP {
p.array_len(),
p.offset(),
p.indices().clone(),
p.values().cast(dtype.clone())?,
p.values().cast_opts(dtype.clone(), *options)?,
p.chunk_offsets().clone(),
)
}
Expand Down
10 changes: 8 additions & 2 deletions encodings/alp/src/alp_rd/compute/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,32 @@ use vortex_array::ArrayView;
use vortex_array::IntoArray;
use vortex_array::builtins::ArrayBuiltins;
use vortex_array::dtype::DType;
use vortex_array::scalar_fn::fns::cast::CastOptions;
use vortex_array::scalar_fn::fns::cast::CastReduce;
use vortex_error::VortexResult;

use crate::ALPRDArrayExt;
use crate::alp_rd::ALPRD;

impl CastReduce for ALPRD {
fn cast(array: ArrayView<'_, Self>, dtype: &DType) -> VortexResult<Option<ArrayRef>> {
fn cast(
array: ArrayView<'_, Self>,
dtype: &DType,
options: &CastOptions,
) -> VortexResult<Option<ArrayRef>> {
// ALPRDArray stores floating-point values, so only cast between float types
// or if just changing nullability

// Check if this is just a nullability change
if array.dtype().eq_ignore_nullability(dtype) {
// For nullability-only changes, we need to cast the left_parts array
// since it carries the validity information
let new_left_parts = array.left_parts().cast(
let new_left_parts = array.left_parts().cast_opts(
array
.left_parts()
.dtype()
.with_nullability(dtype.nullability()),
*options,
)?;

return Ok(Some(
Expand Down
2 changes: 1 addition & 1 deletion encodings/bytebool/public-api.lock
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ pub fn vortex_bytebool::ByteBool::slice(array: vortex_array::array::view::ArrayV

impl vortex_array::scalar_fn::fns::cast::kernel::CastReduce for vortex_bytebool::ByteBool

pub fn vortex_bytebool::ByteBool::cast(array: vortex_array::array::view::ArrayView<'_, Self>, dtype: &vortex_array::dtype::DType) -> vortex_error::VortexResult<core::option::Option<vortex_array::array::erased::ArrayRef>>
pub fn vortex_bytebool::ByteBool::cast(array: vortex_array::array::view::ArrayView<'_, Self>, dtype: &vortex_array::dtype::DType, _options: &vortex_array::scalar_fn::fns::cast::CastOptions) -> vortex_error::VortexResult<core::option::Option<vortex_array::array::erased::ArrayRef>>

impl vortex_array::scalar_fn::fns::mask::kernel::MaskReduce for vortex_bytebool::ByteBool

Expand Down
7 changes: 6 additions & 1 deletion encodings/bytebool/src/compute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use vortex_array::arrays::dict::TakeExecute;
use vortex_array::buffer::BufferHandle;
use vortex_array::dtype::DType;
use vortex_array::match_each_integer_ptype;
use vortex_array::scalar_fn::fns::cast::CastOptions;
use vortex_array::scalar_fn::fns::cast::CastReduce;
use vortex_array::scalar_fn::fns::mask::MaskReduce;
use vortex_array::validity::Validity;
Expand All @@ -20,7 +21,11 @@ use vortex_error::VortexResult;
use super::ByteBool;

impl CastReduce for ByteBool {
fn cast(array: ArrayView<'_, Self>, dtype: &DType) -> VortexResult<Option<ArrayRef>> {
fn cast(
array: ArrayView<'_, Self>,
dtype: &DType,
_options: &CastOptions,
) -> VortexResult<Option<ArrayRef>> {
// ByteBool is essentially a bool array stored as bytes
// The main difference from BoolArray is the storage format
// For casting, we can decode to canonical (BoolArray) and let it handle the cast
Expand Down
2 changes: 1 addition & 1 deletion encodings/datetime-parts/public-api.lock
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ pub fn vortex_datetime_parts::DateTimeParts::compare(lhs: vortex_array::array::v

impl vortex_array::scalar_fn::fns::cast::kernel::CastReduce for vortex_datetime_parts::DateTimeParts

pub fn vortex_datetime_parts::DateTimeParts::cast(array: vortex_array::array::view::ArrayView<'_, Self>, dtype: &vortex_array::dtype::DType) -> vortex_error::VortexResult<core::option::Option<vortex_array::array::erased::ArrayRef>>
pub fn vortex_datetime_parts::DateTimeParts::cast(array: vortex_array::array::view::ArrayView<'_, Self>, dtype: &vortex_array::dtype::DType, options: &vortex_array::scalar_fn::fns::cast::CastOptions) -> vortex_error::VortexResult<core::option::Option<vortex_array::array::erased::ArrayRef>>

impl vortex_array::scalar_fn::fns::mask::kernel::MaskReduce for vortex_datetime_parts::DateTimeParts

Expand Down
14 changes: 10 additions & 4 deletions encodings/datetime-parts/src/compute/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,29 @@ use vortex_array::ArrayView;
use vortex_array::IntoArray;
use vortex_array::builtins::ArrayBuiltins;
use vortex_array::dtype::DType;
use vortex_array::scalar_fn::fns::cast::CastOptions;
use vortex_array::scalar_fn::fns::cast::CastReduce;
use vortex_error::VortexResult;

use crate::DateTimeParts;
use crate::array::DateTimePartsArrayExt;
impl CastReduce for DateTimeParts {
fn cast(array: ArrayView<'_, Self>, dtype: &DType) -> VortexResult<Option<ArrayRef>> {
fn cast(
array: ArrayView<'_, Self>,
dtype: &DType,
options: &CastOptions,
) -> VortexResult<Option<ArrayRef>> {
if !array.dtype().eq_ignore_nullability(dtype) {
return Ok(None);
};

Ok(Some(
DateTimeParts::try_new(
dtype.clone(),
array
.days()
.cast(array.days().dtype().with_nullability(dtype.nullability()))?,
array.days().cast_opts(
array.days().dtype().with_nullability(dtype.nullability()),
*options,
)?,
array.seconds().clone(),
array.subseconds().clone(),
)?
Expand Down
2 changes: 1 addition & 1 deletion encodings/decimal-byte-parts/public-api.lock
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ pub fn vortex_decimal_byte_parts::DecimalByteParts::compare(lhs: vortex_array::a

impl vortex_array::scalar_fn::fns::cast::kernel::CastReduce for vortex_decimal_byte_parts::DecimalByteParts

pub fn vortex_decimal_byte_parts::DecimalByteParts::cast(array: vortex_array::array::view::ArrayView<'_, Self>, dtype: &vortex_array::dtype::DType) -> vortex_error::VortexResult<core::option::Option<vortex_array::array::erased::ArrayRef>>
pub fn vortex_decimal_byte_parts::DecimalByteParts::cast(array: vortex_array::array::view::ArrayView<'_, Self>, dtype: &vortex_array::dtype::DType, options: &vortex_array::scalar_fn::fns::cast::CastOptions) -> vortex_error::VortexResult<core::option::Option<vortex_array::array::erased::ArrayRef>>

impl vortex_array::scalar_fn::fns::mask::kernel::MaskReduce for vortex_decimal_byte_parts::DecimalByteParts

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,19 @@ use vortex_array::ArrayView;
use vortex_array::IntoArray;
use vortex_array::builtins::ArrayBuiltins;
use vortex_array::dtype::DType;
use vortex_array::scalar_fn::fns::cast::CastOptions;
use vortex_array::scalar_fn::fns::cast::CastReduce;
use vortex_error::VortexExpect;
use vortex_error::VortexResult;

use crate::DecimalByteParts;
use crate::decimal_byte_parts::DecimalBytePartsArrayExt;
impl CastReduce for DecimalByteParts {
fn cast(array: ArrayView<'_, Self>, dtype: &DType) -> VortexResult<Option<ArrayRef>> {
fn cast(
array: ArrayView<'_, Self>,
dtype: &DType,
options: &CastOptions,
) -> VortexResult<Option<ArrayRef>> {
// DecimalBytePartsArray can only have Decimal dtype, so we only handle decimal-to-decimal casts
let DType::Decimal(target_decimal, target_nullability) = dtype else {
// Cannot cast decimal to non-decimal types - delegate to canonical form
Expand All @@ -29,9 +34,10 @@ impl CastReduce for DecimalByteParts {
&& array.dtype().nullability() != *target_nullability
{
// Cast the msp array to handle nullability change
let new_msp = array
.msp()
.cast(array.msp().dtype().with_nullability(*target_nullability))?;
let new_msp = array.msp().cast_opts(
array.msp().dtype().with_nullability(*target_nullability),
*options,
)?;

return Ok(Some(
DecimalByteParts::try_new(new_msp, *target_decimal)?.into_array(),
Expand Down
8 changes: 4 additions & 4 deletions encodings/fastlanes/public-api.lock
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ pub fn vortex_fastlanes::BitPacked::slice(array: vortex_array::array::view::Arra

impl vortex_array::scalar_fn::fns::cast::kernel::CastReduce for vortex_fastlanes::BitPacked

pub fn vortex_fastlanes::BitPacked::cast(array: vortex_array::array::view::ArrayView<'_, Self>, dtype: &vortex_array::dtype::DType) -> vortex_error::VortexResult<core::option::Option<vortex_array::array::erased::ArrayRef>>
pub fn vortex_fastlanes::BitPacked::cast(array: vortex_array::array::view::ArrayView<'_, Self>, dtype: &vortex_array::dtype::DType, options: &vortex_array::scalar_fn::fns::cast::CastOptions) -> vortex_error::VortexResult<core::option::Option<vortex_array::array::erased::ArrayRef>>

pub struct vortex_fastlanes::BitPackedData

Expand Down Expand Up @@ -332,7 +332,7 @@ pub fn vortex_fastlanes::Delta::slice(array: vortex_array::array::view::ArrayVie

impl vortex_array::scalar_fn::fns::cast::kernel::CastReduce for vortex_fastlanes::Delta

pub fn vortex_fastlanes::Delta::cast(array: vortex_array::array::view::ArrayView<'_, Self>, dtype: &vortex_array::dtype::DType) -> vortex_error::VortexResult<core::option::Option<vortex_array::array::erased::ArrayRef>>
pub fn vortex_fastlanes::Delta::cast(array: vortex_array::array::view::ArrayView<'_, Self>, dtype: &vortex_array::dtype::DType, options: &vortex_array::scalar_fn::fns::cast::CastOptions) -> vortex_error::VortexResult<core::option::Option<vortex_array::array::erased::ArrayRef>>

pub struct vortex_fastlanes::DeltaData

Expand Down Expand Up @@ -432,7 +432,7 @@ pub fn vortex_fastlanes::FoR::compare(lhs: vortex_array::array::view::ArrayView<

impl vortex_array::scalar_fn::fns::cast::kernel::CastReduce for vortex_fastlanes::FoR

pub fn vortex_fastlanes::FoR::cast(array: vortex_array::array::view::ArrayView<'_, Self>, dtype: &vortex_array::dtype::DType) -> vortex_error::VortexResult<core::option::Option<vortex_array::array::erased::ArrayRef>>
pub fn vortex_fastlanes::FoR::cast(array: vortex_array::array::view::ArrayView<'_, Self>, dtype: &vortex_array::dtype::DType, options: &vortex_array::scalar_fn::fns::cast::CastOptions) -> vortex_error::VortexResult<core::option::Option<vortex_array::array::erased::ArrayRef>>

pub struct vortex_fastlanes::FoRData

Expand Down Expand Up @@ -526,7 +526,7 @@ pub fn vortex_fastlanes::RLE::slice(array: vortex_array::array::view::ArrayView<

impl vortex_array::scalar_fn::fns::cast::kernel::CastReduce for vortex_fastlanes::RLE

pub fn vortex_fastlanes::RLE::cast(array: vortex_array::array::view::ArrayView<'_, Self>, dtype: &vortex_array::dtype::DType) -> vortex_error::VortexResult<core::option::Option<vortex_array::array::erased::ArrayRef>>
pub fn vortex_fastlanes::RLE::cast(array: vortex_array::array::view::ArrayView<'_, Self>, dtype: &vortex_array::dtype::DType, options: &vortex_array::scalar_fn::fns::cast::CastOptions) -> vortex_error::VortexResult<core::option::Option<vortex_array::array::erased::ArrayRef>>

pub struct vortex_fastlanes::RLEData

Expand Down
9 changes: 7 additions & 2 deletions encodings/fastlanes/src/bitpacking/compute/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,18 @@ use vortex_array::IntoArray;
use vortex_array::builtins::ArrayBuiltins;
use vortex_array::dtype::DType;
use vortex_array::patches::Patches;
use vortex_array::scalar_fn::fns::cast::CastOptions;
use vortex_array::scalar_fn::fns::cast::CastReduce;
use vortex_error::VortexResult;

use crate::bitpacking::BitPacked;
use crate::bitpacking::array::BitPackedArrayExt;
impl CastReduce for BitPacked {
fn cast(array: ArrayView<'_, Self>, dtype: &DType) -> VortexResult<Option<ArrayRef>> {
fn cast(
array: ArrayView<'_, Self>,
dtype: &DType,
options: &CastOptions,
) -> VortexResult<Option<ArrayRef>> {
if array.dtype().eq_ignore_nullability(dtype) {
let new_validity = array
.validity()?
Expand All @@ -26,7 +31,7 @@ impl CastReduce for BitPacked {
array
.patches()
.map(|patches| {
let new_values = patches.values().cast(dtype.clone())?;
let new_values = patches.values().cast_opts(dtype.clone(), *options)?;
Patches::new(
patches.array_len(),
patches.offset(),
Expand Down
13 changes: 10 additions & 3 deletions encodings/fastlanes/src/delta/compute/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,19 @@ use vortex_array::IntoArray;
use vortex_array::builtins::ArrayBuiltins;
use vortex_array::dtype::DType;
use vortex_array::dtype::Nullability::NonNullable;
use vortex_array::scalar_fn::fns::cast::CastOptions;
use vortex_array::scalar_fn::fns::cast::CastReduce;
use vortex_error::VortexResult;
use vortex_error::vortex_panic;

use crate::delta::Delta;
use crate::delta::array::DeltaArrayExt;
impl CastReduce for Delta {
fn cast(array: ArrayView<'_, Self>, dtype: &DType) -> VortexResult<Option<ArrayRef>> {
fn cast(
array: ArrayView<'_, Self>,
dtype: &DType,
options: &CastOptions,
) -> VortexResult<Option<ArrayRef>> {
// Delta encoding stores differences between consecutive values, which requires
// unsigned integers to avoid overflow issues. Signed integers could produce
// negative deltas that wouldn't fit in the unsigned delta representation.
Expand All @@ -33,8 +38,10 @@ impl CastReduce for Delta {
}

// Cast both bases and deltas to the target type
let casted_bases = array.bases().cast(dtype.with_nullability(NonNullable))?;
let casted_deltas = array.deltas().cast(dtype.clone())?;
let casted_bases = array
.bases()
.cast_opts(dtype.with_nullability(NonNullable), *options)?;
let casted_deltas = array.deltas().cast_opts(dtype.clone(), *options)?;

// Create a new DeltaArray with the casted components, preserving offset and logical length
Ok(Some(
Expand Down
9 changes: 7 additions & 2 deletions encodings/fastlanes/src/for/compute/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,25 @@ use vortex_array::ArrayView;
use vortex_array::IntoArray;
use vortex_array::builtins::ArrayBuiltins;
use vortex_array::dtype::DType;
use vortex_array::scalar_fn::fns::cast::CastOptions;
use vortex_array::scalar_fn::fns::cast::CastReduce;
use vortex_error::VortexResult;

use crate::r#for::FoR;
use crate::r#for::array::FoRArrayExt;
impl CastReduce for FoR {
fn cast(array: ArrayView<'_, Self>, dtype: &DType) -> VortexResult<Option<ArrayRef>> {
fn cast(
array: ArrayView<'_, Self>,
dtype: &DType,
options: &CastOptions,
) -> VortexResult<Option<ArrayRef>> {
// FoR only supports integer types
if !dtype.is_int() {
return Ok(None);
}

// For type changes between integers, cast the components
let casted_child = array.encoded().cast(dtype.clone())?;
let casted_child = array.encoded().cast_opts(dtype.clone(), *options)?;
let casted_reference = array.reference_scalar().cast(dtype)?;

Ok(Some(
Expand Down
22 changes: 14 additions & 8 deletions encodings/fastlanes/src/rle/compute/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,30 @@ use vortex_array::IntoArray;
use vortex_array::builtins::ArrayBuiltins;
use vortex_array::dtype::DType;
use vortex_array::dtype::Nullability;
use vortex_array::scalar_fn::fns::cast::CastOptions;
use vortex_array::scalar_fn::fns::cast::CastReduce;
use vortex_error::VortexResult;

use crate::rle::RLE;
use crate::rle::RLEArrayExt;
impl CastReduce for RLE {
fn cast(array: ArrayView<'_, Self>, dtype: &DType) -> VortexResult<Option<ArrayRef>> {
fn cast(
array: ArrayView<'_, Self>,
dtype: &DType,
options: &CastOptions,
) -> VortexResult<Option<ArrayRef>> {
// Cast RLE values.
let casted_values = array
.values()
.cast(DType::Primitive(dtype.as_ptype(), Nullability::NonNullable))?;
let casted_values = array.values().cast_opts(
DType::Primitive(dtype.as_ptype(), Nullability::NonNullable),
*options,
)?;

// Cast RLE indices such that validity matches the target dtype.
let casted_indices = if array.indices().dtype().nullability() != dtype.nullability() {
array.indices().cast(DType::Primitive(
array.indices().dtype().as_ptype(),
dtype.nullability(),
))?
array.indices().cast_opts(
DType::Primitive(array.indices().dtype().as_ptype(), dtype.nullability()),
*options,
)?
} else {
array.indices().clone()
};
Expand Down
2 changes: 1 addition & 1 deletion encodings/fsst/public-api.lock
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ pub fn vortex_fsst::FSST::compare(lhs: vortex_array::array::view::ArrayView<'_,

impl vortex_array::scalar_fn::fns::cast::kernel::CastReduce for vortex_fsst::FSST

pub fn vortex_fsst::FSST::cast(array: vortex_array::array::view::ArrayView<'_, Self>, dtype: &vortex_array::dtype::DType) -> vortex_error::VortexResult<core::option::Option<vortex_array::array::erased::ArrayRef>>
pub fn vortex_fsst::FSST::cast(array: vortex_array::array::view::ArrayView<'_, Self>, dtype: &vortex_array::dtype::DType, options: &vortex_array::scalar_fn::fns::cast::CastOptions) -> vortex_error::VortexResult<core::option::Option<vortex_array::array::erased::ArrayRef>>

impl vortex_array::scalar_fn::fns::like::kernel::LikeKernel for vortex_fsst::FSST

Expand Down
Loading
Loading