@@ -18,10 +18,12 @@ use crate::arrays::piecewise_sequence::execute_unit_multiplier_index_arrays;
1818use crate :: arrays:: piecewise_sequence:: validate_index_ranges;
1919use crate :: dtype:: IntegerPType ;
2020use crate :: dtype:: NativeDecimalType ;
21+ use crate :: dtype:: UnsignedPType ;
2122use crate :: executor:: ExecutionCtx ;
2223use crate :: match_each_decimal_value_type;
2324use crate :: match_each_integer_ptype;
2425use crate :: match_each_unsigned_integer_ptype;
26+ use crate :: validity:: Validity ;
2527
2628impl TakeExecute for Decimal {
2729 fn take (
@@ -63,24 +65,65 @@ fn take_piecewise_sequence(
6365 let Some ( ( starts, lengths) ) = execute_unit_multiplier_index_arrays ( indices, ctx) ? else {
6466 return Ok ( None ) ;
6567 } ;
68+ let validity = array. validity ( ) ?. take ( indices_ref) ?;
69+ let output_len = indices_ref. len ( ) ;
70+ let taken = take_piecewise_sequence_lengths ( array, & starts, & lengths, validity, output_len) ?;
71+ Ok ( Some ( taken) )
72+ }
73+
74+ fn take_piecewise_sequence_lengths (
75+ array : ArrayView < ' _ , Decimal > ,
76+ starts : & PrimitiveArray ,
77+ lengths : & PrimitiveArray ,
78+ validity : Validity ,
79+ output_len : usize ,
80+ ) -> VortexResult < ArrayRef > {
6681 match_each_decimal_value_type ! ( array. values_type( ) , |D | {
67- match_each_unsigned_integer_ptype!( starts. ptype( ) , |S | {
68- match_each_unsigned_integer_ptype!( lengths. ptype( ) , |L | {
69- let values = take_piecewise_to_buffer:: <S , L , D >(
70- starts. as_slice:: <S >( ) ,
71- lengths. as_slice:: <L >( ) ,
72- array. buffer:: <D >( ) . as_slice( ) ,
73- indices_ref. len( ) ,
74- ) ?;
75- let validity = array. validity( ) ?. take( indices_ref) ?;
76-
77- // SAFETY: contiguous gather preserves the decimal dtype and value representation.
78- Ok ( Some (
79- unsafe { DecimalArray :: new_unchecked( values, array. decimal_dtype( ) , validity) }
80- . into_array( ) ,
81- ) )
82- } )
83- } )
82+ take_piecewise_sequence_lengths_typed:: <D >( array, starts, lengths, validity, output_len)
83+ } )
84+ }
85+
86+ fn take_piecewise_sequence_lengths_typed < D > (
87+ array : ArrayView < ' _ , Decimal > ,
88+ starts : & PrimitiveArray ,
89+ lengths : & PrimitiveArray ,
90+ validity : Validity ,
91+ output_len : usize ,
92+ ) -> VortexResult < ArrayRef >
93+ where
94+ D : NativeDecimalType ,
95+ {
96+ match_each_unsigned_integer_ptype ! ( starts. ptype( ) , |S | {
97+ take_piecewise_sequence_lengths_start_typed:: <D , S >(
98+ array, starts, lengths, validity, output_len,
99+ )
100+ } )
101+ }
102+
103+ fn take_piecewise_sequence_lengths_start_typed < D , S > (
104+ array : ArrayView < ' _ , Decimal > ,
105+ starts : & PrimitiveArray ,
106+ lengths : & PrimitiveArray ,
107+ validity : Validity ,
108+ output_len : usize ,
109+ ) -> VortexResult < ArrayRef >
110+ where
111+ D : NativeDecimalType ,
112+ S : UnsignedPType ,
113+ {
114+ match_each_unsigned_integer_ptype ! ( lengths. ptype( ) , |L | {
115+ let values = take_piecewise_to_buffer:: <S , L , D >(
116+ starts. as_slice:: <S >( ) ,
117+ lengths. as_slice:: <L >( ) ,
118+ array. buffer:: <D >( ) . as_slice( ) ,
119+ output_len,
120+ ) ?;
121+
122+ // SAFETY: contiguous gather preserves the decimal dtype and value representation.
123+ Ok (
124+ unsafe { DecimalArray :: new_unchecked( values, array. decimal_dtype( ) , validity) }
125+ . into_array( ) ,
126+ )
84127 } )
85128}
86129
@@ -95,8 +138,8 @@ fn take_piecewise_to_buffer<S, L, T>(
95138 output_len : usize ,
96139) -> VortexResult < Buffer < T > >
97140where
98- S : crate :: dtype :: UnsignedPType ,
99- L : crate :: dtype :: UnsignedPType ,
141+ S : UnsignedPType ,
142+ L : UnsignedPType ,
100143 T : NativeDecimalType ,
101144{
102145 validate_index_ranges ( values. len ( ) , starts, lengths, output_len) ?;
0 commit comments