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
40 changes: 39 additions & 1 deletion encodings/alp/src/alp/compute/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use vortex_array::IntoArray;
use vortex_array::compute::CastKernel;
use vortex_array::compute::CastKernelAdapter;
use vortex_array::compute::cast;
use vortex_array::patches::Patches;
use vortex_array::register_kernel;
use vortex_dtype::DType;
use vortex_error::VortexResult;
Expand All @@ -27,13 +28,30 @@ impl CastKernel for ALPVTable {
.with_nullability(dtype.nullability()),
)?;

let new_patches = array
.patches()
.map(|p| {
if p.values().dtype() == dtype {
Ok(p.clone())
} else {
Patches::new(
p.array_len(),
p.offset(),
p.indices().clone(),
cast(p.values(), dtype)?,
p.chunk_offsets().clone(),
)
}
})
.transpose()?;

// SAFETY: casting nullability doesn't alter the invariants
unsafe {
Ok(Some(
ALPArray::new_unchecked(
new_encoded,
array.exponents(),
array.patches().cloned(),
new_patches,
dtype.clone(),
)
.into_array(),
Expand Down Expand Up @@ -65,6 +83,26 @@ mod tests {

use crate::alp_encode;

#[test]
fn issue_5766_test_cast_alp_with_patches_to_nullable() -> VortexResult<()> {
let values = buffer![1.234f32, f32::NAN, 2.345, f32::INFINITY, 3.456].into_array();
let alp = alp_encode(&values.to_primitive(), None)?;

assert!(
alp.patches().is_some(),
"Test requires ALP array with patches"
);

let nullable_dtype = DType::Primitive(PType::F32, Nullability::Nullable);
let casted = cast(alp.as_ref(), &nullable_dtype)?;

let expected = cast(&values, &nullable_dtype)?;

assert_arrays_eq!(casted.to_canonical()?.into_primitive(), expected);

Ok(())
}

#[test]
fn test_cast_alp_f32_to_f64() -> VortexResult<()> {
let values = buffer![1.5f32, 2.5, 3.5, 4.5].into_array();
Expand Down
6 changes: 6 additions & 0 deletions fuzz/claude.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<!-- SPDX-License-Identifier: Apache-2.0 -->
<!--SPDX-FileCopyrightText: Copyright the Vortex contributors -->

# Running the fuzzer

When running in local envs use `cargo fuzz -s none ...`
1 change: 1 addition & 0 deletions vortex-array/src/arrays/constant/vtable/validity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use crate::vtable::ValidityVTable;

impl ValidityVTable<ConstantVTable> for ConstantVTable {
fn validity(array: &ConstantArray) -> VortexResult<Validity> {
debug_assert!(array.dtype().is_nullable());
Ok(if array.scalar().is_null() {
Validity::AllInvalid
} else {
Expand Down
Loading