11// SPDX-License-Identifier: Apache-2.0
22// SPDX-FileCopyrightText: Copyright the Vortex contributors
33
4+ use std:: sync:: Arc ;
5+
46use vortex_array:: ArrayRef ;
57use vortex_array:: Canonical ;
68use vortex_array:: IntoArray ;
79use vortex_array:: ToCanonical ;
810use vortex_array:: arrays:: BoolArray ;
911use vortex_array:: arrays:: ConstantArray ;
1012use vortex_array:: arrays:: DecimalArray ;
13+ use vortex_array:: arrays:: ExtensionArray ;
1114use vortex_array:: arrays:: PrimitiveArray ;
1215use vortex_array:: arrays:: VarBinViewArray ;
1316use vortex_array:: compute:: fill_null;
@@ -16,13 +19,13 @@ use vortex_array::vtable::ValidityHelper;
1619use vortex_buffer:: Buffer ;
1720use vortex_buffer:: BufferMut ;
1821use vortex_dtype:: DType ;
22+ use vortex_dtype:: ExtDType ;
1923use vortex_dtype:: Nullability ;
2024use vortex_dtype:: match_each_decimal_value_type;
2125use vortex_dtype:: match_each_native_ptype;
2226use vortex_error:: VortexExpect ;
2327use vortex_error:: VortexResult ;
2428use vortex_scalar:: Scalar ;
25-
2629/// Apply fill_null on the canonical form of the array to get a consistent baseline.
2730/// This implementation manually fills null values for each canonical type
2831/// without using the fill_null method, to serve as an independent baseline for testing.
@@ -40,13 +43,33 @@ pub fn fill_null_canonical_array(
4043 Canonical :: VarBinView ( array) => {
4144 fill_varbinview_array ( & array, fill_value, result_nullability)
4245 }
43- Canonical :: Struct ( _ )
44- | Canonical :: List ( _)
45- | Canonical :: FixedSizeList ( _ )
46- | Canonical :: Extension ( _ ) => fill_null ( canonical . as_ref ( ) , fill_value ) ? ,
46+ Canonical :: Extension ( array ) => fill_extension_array ( & array , fill_value ) ,
47+ Canonical :: Struct ( _ ) | Canonical :: List ( _) | Canonical :: FixedSizeList ( _ ) => {
48+ fill_null ( canonical . as_ref ( ) , fill_value ) ?
49+ }
4750 } )
4851}
4952
53+ fn fill_extension_array ( array : & ExtensionArray , fill_value : & Scalar ) -> ArrayRef {
54+ let filled_storage = fill_null_canonical_array (
55+ array. storage ( ) . to_canonical ( ) ,
56+ & fill_value. as_extension ( ) . storage ( ) ,
57+ )
58+ . vortex_expect ( "fill_null should succeed in canonical form" ) ;
59+
60+ if filled_storage. dtype ( ) . nullability ( ) == array. ext_dtype ( ) . storage_dtype ( ) . nullability ( ) {
61+ ExtensionArray :: new ( array. ext_dtype ( ) . clone ( ) , filled_storage) . into_array ( )
62+ } else {
63+ let new_ext_dtype = Arc :: new ( ExtDType :: new (
64+ array. ext_dtype ( ) . id ( ) . clone ( ) ,
65+ Arc :: new ( filled_storage. dtype ( ) . clone ( ) ) ,
66+ array. ext_dtype ( ) . metadata ( ) . cloned ( ) ,
67+ ) ) ;
68+
69+ ExtensionArray :: new ( new_ext_dtype, filled_storage) . into_array ( )
70+ }
71+ }
72+
5073fn fill_bool_array (
5174 array : & BoolArray ,
5275 fill_value : & Scalar ,
0 commit comments