@@ -6,7 +6,6 @@ use vortex_array::ArrayView;
66use vortex_array:: IntoArray ;
77use vortex_array:: builtins:: ArrayBuiltins ;
88use vortex_array:: dtype:: DType ;
9- use vortex_array:: patches:: Patches ;
109use vortex_array:: scalar_fn:: fns:: cast:: CastReduce ;
1110use vortex_error:: VortexResult ;
1211
@@ -17,41 +16,29 @@ use crate::alp::ALP;
1716impl CastReduce for ALP {
1817 fn cast ( array : ArrayView < ' _ , Self > , dtype : & DType ) -> VortexResult < Option < ArrayRef > > {
1918 // Check if this is just a nullability change
20- if array. dtype ( ) . eq_ignore_nullability ( dtype) {
21- // For nullability-only changes, we can avoid decoding
22- // Cast the encoded array (integers) to handle nullability
23- let new_encoded = array. encoded ( ) . cast (
24- array
25- . encoded ( )
26- . dtype ( )
27- . with_nullability ( dtype. nullability ( ) ) ,
28- ) ?;
29-
30- let new_patches = array
31- . patches ( )
32- . map ( |p| {
33- if p. values ( ) . dtype ( ) == dtype {
34- Ok ( p)
35- } else {
36- Patches :: new (
37- p. array_len ( ) ,
38- p. offset ( ) ,
39- p. indices ( ) . clone ( ) ,
40- p. values ( ) . cast ( dtype. clone ( ) ) ?,
41- p. chunk_offsets ( ) . clone ( ) ,
42- )
43- }
44- } )
45- . transpose ( ) ?;
46-
47- // SAFETY: casting nullability doesn't alter the invariants
48- unsafe {
49- Ok ( Some (
50- ALP :: new_unchecked ( new_encoded, array. exponents ( ) , new_patches) . into_array ( ) ,
51- ) )
52- }
53- } else {
54- Ok ( None )
19+ if !array. dtype ( ) . eq_ignore_nullability ( dtype) {
20+ return Ok ( None ) ;
21+ }
22+
23+ // For nullability-only changes, we can avoid decoding
24+ // Cast the encoded array (integers) to handle nullability
25+ let new_encoded = array. encoded ( ) . cast (
26+ array
27+ . encoded ( )
28+ . dtype ( )
29+ . with_nullability ( dtype. nullability ( ) ) ,
30+ ) ?;
31+
32+ let new_patches = array
33+ . patches ( )
34+ . map ( |p| p. map_values ( |v| v. cast ( dtype. clone ( ) ) ) )
35+ . transpose ( ) ?;
36+
37+ // SAFETY: casting nullability doesn't alter the invariants
38+ unsafe {
39+ Ok ( Some (
40+ ALP :: new_unchecked ( new_encoded, array. exponents ( ) , new_patches) . into_array ( ) ,
41+ ) )
5542 }
5643 }
5744}
0 commit comments