Skip to content
Merged
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
27 changes: 26 additions & 1 deletion vortex-array/src/arrays/extension/compute/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ impl CastReduce for Extension {
dtype: &DType,
) -> vortex_error::VortexResult<Option<ArrayRef>> {
if !array.dtype().eq_ignore_nullability(dtype) {
return Ok(None);
// Target is not the same extension type.
// Delegate to the storage array's cast.
return Ok(Some(array.storage_array().cast(dtype.clone())?));
}

let DType::Extension(ext_dtype) = dtype else {
Expand Down Expand Up @@ -51,9 +53,12 @@ mod tests {
use super::*;
use crate::IntoArray;
use crate::arrays::PrimitiveArray;
use crate::assert_arrays_eq;
use crate::builtins::ArrayBuiltins;
use crate::compute::conformance::cast::test_cast_conformance;
use crate::dtype::DType;
use crate::dtype::Nullability;
use crate::dtype::PType;
use crate::extension::datetime::TimeUnit;
use crate::extension::datetime::Timestamp;

Expand Down Expand Up @@ -108,6 +113,26 @@ mod tests {
);
}

#[test]
fn cast_timestamp_to_i64() -> vortex_error::VortexResult<()> {
let ext_dtype = Timestamp::new_with_tz(
TimeUnit::Nanoseconds,
Some("UTC".into()),
Nullability::NonNullable,
)
.erased();
let storage = buffer![1i64, 2, 3].into_array();
let arr = ExtensionArray::new(ext_dtype, storage).into_array();

let result = arr.cast(DType::Primitive(PType::I64, Nullability::NonNullable))?;
assert_eq!(
result.dtype(),
&DType::Primitive(PType::I64, Nullability::NonNullable)
);
assert_arrays_eq!(result, buffer![1i64, 2, 3].into_array());
Ok(())
}

#[rstest]
#[case(create_timestamp_array(TimeUnit::Milliseconds, false))]
#[case(create_timestamp_array(TimeUnit::Microseconds, true))]
Expand Down
Loading