11use arrow_buffer:: ArrowNativeType ;
22use vortex_array:: accessor:: ArrayAccessor ;
3- use vortex_array:: arrays:: { BoolArray , PrimitiveArray , StructArray , VarBinViewArray } ;
3+ use vortex_array:: arrays:: { BoolArray , DecimalArray , PrimitiveArray , StructArray , VarBinViewArray } ;
44use vortex_array:: builders:: { ArrayBuilderExt , builder_with_capacity} ;
55use vortex_array:: validity:: Validity ;
66use vortex_array:: { Array , ArrayRef , IntoArray , ToCanonical } ;
77use vortex_buffer:: Buffer ;
8- use vortex_dtype:: { DType , NativePType , match_each_native_ptype} ;
8+ use vortex_dtype:: { DType , DecimalDType , NativePType , match_each_native_ptype} ;
99use vortex_error:: VortexResult ;
10+ use vortex_scalar:: { NativeDecimalType , match_each_decimal_value_type} ;
1011
1112pub fn take_canonical_array ( array : & dyn Array , indices : & [ usize ] ) -> VortexResult < ArrayRef > {
1213 let validity = if array. dtype ( ) . is_nullable ( ) {
@@ -32,6 +33,13 @@ pub fn take_canonical_array(array: &dyn Array, indices: &[usize]) -> VortexResul
3233 Ok ( take_primitive:: <P >( primitive_array, validity, indices) )
3334 } )
3435 }
36+ DType :: Decimal ( d, _) => {
37+ let decimal_array = array. to_decimal ( ) ?;
38+
39+ match_each_decimal_value_type ! ( decimal_array. values_type( ) , |D | {
40+ Ok ( take_decimal:: <D >( decimal_array, d, validity, indices) )
41+ } )
42+ }
3543 DType :: Utf8 ( _) | DType :: Binary ( _) => {
3644 let utf8 = array. to_varbinview ( ) ?;
3745 let values =
@@ -65,7 +73,9 @@ pub fn take_canonical_array(array: &dyn Array, indices: &[usize]) -> VortexResul
6573 }
6674 Ok ( builder. finish ( ) )
6775 }
68- d => unreachable ! ( "DType {d} not supported for fuzzing" ) ,
76+ d @ ( DType :: Null | DType :: Extension ( _) ) => {
77+ unreachable ! ( "DType {d} not supported for fuzzing" )
78+ }
6979 }
7080}
7181
@@ -84,3 +94,22 @@ fn take_primitive<T: NativePType + ArrowNativeType>(
8494 )
8595 . into_array ( )
8696}
97+
98+ fn take_decimal < D : NativeDecimalType > (
99+ array : DecimalArray ,
100+ decimal_type : & DecimalDType ,
101+ validity : Validity ,
102+ indices : & [ usize ] ,
103+ ) -> ArrayRef {
104+ let buf = array. buffer :: < D > ( ) ;
105+ let vec_values = buf. as_slice ( ) ;
106+ DecimalArray :: new (
107+ indices
108+ . iter ( )
109+ . map ( |i| vec_values[ * i] )
110+ . collect :: < Buffer < D > > ( ) ,
111+ * decimal_type,
112+ validity,
113+ )
114+ . into_array ( )
115+ }
0 commit comments