@@ -34,11 +34,16 @@ impl MaskKernel for ALP {
3434 ) -> VortexResult < Option < ArrayRef > > {
3535 let vortex_mask = Validity :: Array ( mask. not ( ) ?) . execute_mask ( array. len ( ) , ctx) ?;
3636 let masked_encoded = array. encoded ( ) . clone ( ) . mask ( mask. clone ( ) ) ?;
37+ let masked_dtype = array
38+ . dtype ( )
39+ . with_nullability ( masked_encoded. dtype ( ) . nullability ( ) ) ;
3740 let masked_patches = array
3841 . patches ( )
3942 . map ( |p| p. mask ( & vortex_mask, ctx) )
4043 . transpose ( ) ?
41- . flatten ( ) ;
44+ . flatten ( )
45+ . map ( |patches| patches. cast_values ( & masked_dtype) )
46+ . transpose ( ) ?;
4247 Ok ( Some (
4348 ALP :: new ( masked_encoded, array. exponents ( ) , masked_patches) . into_array ( ) ,
4449 ) )
@@ -49,9 +54,14 @@ impl MaskKernel for ALP {
4954mod test {
5055 use rstest:: rstest;
5156 use vortex_array:: IntoArray ;
57+ use vortex_array:: LEGACY_SESSION ;
5258 use vortex_array:: ToCanonical ;
59+ use vortex_array:: VortexSessionExecute ;
60+ use vortex_array:: arrays:: BoolArray ;
5361 use vortex_array:: arrays:: PrimitiveArray ;
5462 use vortex_array:: compute:: conformance:: mask:: test_mask_conformance;
63+ use vortex_array:: dtype:: Nullability ;
64+ use vortex_array:: scalar_fn:: fns:: mask:: MaskKernel ;
5565 use vortex_buffer:: buffer;
5666
5767 use crate :: alp_encode;
@@ -82,4 +92,23 @@ mod test {
8292 assert ! ( alp. patches( ) . is_some( ) , "expected patches" ) ;
8393 test_mask_conformance ( & alp. into_array ( ) ) ;
8494 }
95+
96+ #[ test]
97+ fn test_mask_alp_with_patches_casts_surviving_patch_values_to_nullable ( ) {
98+ let values = PrimitiveArray :: from_iter ( [ 1.234f32 , f32:: NAN , 2.345 , f32:: INFINITY , 3.456 ] ) ;
99+ let alp = alp_encode ( & values, None ) . unwrap ( ) ;
100+ assert ! ( alp. patches( ) . is_some( ) , "expected patches" ) ;
101+
102+ let keep_mask = BoolArray :: from_iter ( [ false , true , true , true , true ] ) . into_array ( ) ;
103+ let mut ctx = LEGACY_SESSION . create_execution_ctx ( ) ;
104+ let masked = <crate :: ALP as MaskKernel >:: mask ( alp. as_view ( ) , & keep_mask, & mut ctx)
105+ . unwrap ( )
106+ . unwrap ( ) ;
107+
108+ let masked_alp = masked. as_opt :: < crate :: ALP > ( ) . unwrap ( ) ;
109+ let masked_patches = masked_alp. patches ( ) . unwrap ( ) ;
110+
111+ assert_eq ! ( masked. dtype( ) . nullability( ) , Nullability :: Nullable ) ;
112+ assert_eq ! ( masked_patches. dtype( ) . nullability( ) , Nullability :: Nullable ) ;
113+ }
85114}
0 commit comments