vortex_onpair/compute/
cast.rs1use vortex_array::ArrayRef;
5use vortex_array::ArrayView;
6use vortex_array::IntoArray;
7use vortex_array::dtype::DType;
8use vortex_array::scalar_fn::fns::cast::CastReduce;
9use vortex_error::VortexResult;
10
11use crate::OnPair;
12use crate::OnPairArraySlotsExt;
13
14impl CastReduce for OnPair {
17 fn cast(array: ArrayView<'_, Self>, dtype: &DType) -> VortexResult<Option<ArrayRef>> {
18 if !array.dtype().eq_ignore_nullability(dtype) {
19 return Ok(None);
20 }
21 let validity = array.array().validity()?;
22 let Some(new_validity) =
23 validity.trivially_cast_nullability(dtype.nullability(), array.array().len())?
24 else {
25 return Ok(None);
26 };
27 Ok(Some(
28 unsafe {
29 OnPair::new_unchecked(
30 dtype.clone(),
31 array.dict_bytes_handle().clone(),
32 array.dict_offsets().clone(),
33 array.codes().clone(),
34 array.codes_offsets().clone(),
35 array.uncompressed_lengths().clone(),
36 new_validity,
37 array.bits(),
38 )
39 }
40 .into_array(),
41 ))
42 }
43}