22// SPDX-FileCopyrightText: Copyright the Vortex contributors
33
44use itertools:: Itertools ;
5- use vortex_dtype:: { DType , NativeDecimalType } ;
5+ use vortex_dtype:: Nullability :: NonNullable ;
6+ use vortex_dtype:: { DecimalDType , NativeDecimalType } ;
67use vortex_error:: VortexResult ;
78use vortex_mask:: Mask ;
8- use vortex_scalar:: { DecimalValue , Scalar , ScalarValue , match_each_decimal_value_type} ;
9+ use vortex_scalar:: { DecimalValue , Scalar , match_each_decimal_value_type} ;
910
1011use crate :: arrays:: { DecimalArray , DecimalVTable } ;
1112use crate :: compute:: { MinMaxKernel , MinMaxKernelAdapter , MinMaxResult } ;
@@ -27,36 +28,38 @@ where
2728 D : Into < DecimalValue > + NativeDecimalType ,
2829{
2930 Ok ( match array. validity_mask ( ) {
30- Mask :: AllTrue ( _) => compute_min_max ( array. buffer :: < D > ( ) . iter ( ) , array. dtype ( ) ) ,
31+ Mask :: AllTrue ( _) => compute_min_max ( array. buffer :: < D > ( ) . iter ( ) , array. decimal_dtype ( ) ) ,
3132 Mask :: AllFalse ( _) => None ,
3233 Mask :: Values ( v) => compute_min_max (
3334 array
3435 . buffer :: < D > ( )
3536 . iter ( )
3637 . zip ( v. bit_buffer ( ) . iter ( ) )
3738 . filter_map ( |( v, m) | m. then_some ( v) ) ,
38- array. dtype ( ) ,
39+ array. decimal_dtype ( ) ,
3940 ) ,
4041 } )
4142}
4243
43- fn compute_min_max < ' a , T > ( iter : impl Iterator < Item = & ' a T > , dtype : & DType ) -> Option < MinMaxResult >
44+ fn compute_min_max < ' a , T > (
45+ iter : impl Iterator < Item = & ' a T > ,
46+ decimal_dtype : DecimalDType ,
47+ ) -> Option < MinMaxResult >
4448where
4549 T : Into < DecimalValue > + NativeDecimalType + Ord + Copy + ' a ,
4650{
47- let non_nullable_dtype = dtype. as_nonnullable ( ) ;
4851 match iter. minmax_by ( |a, b| a. cmp ( b) ) {
4952 itertools:: MinMaxResult :: NoElements => None ,
5053 itertools:: MinMaxResult :: OneElement ( & x) => {
51- let scalar = Scalar :: new ( non_nullable_dtype , ScalarValue :: from ( x. into ( ) ) ) ;
54+ let scalar = Scalar :: decimal ( x. into ( ) , decimal_dtype , NonNullable ) ;
5255 Some ( MinMaxResult {
5356 min : scalar. clone ( ) ,
5457 max : scalar,
5558 } )
5659 }
5760 itertools:: MinMaxResult :: MinMax ( & min, & max) => Some ( MinMaxResult {
58- min : Scalar :: new ( non_nullable_dtype . clone ( ) , ScalarValue :: from ( min. into ( ) ) ) ,
59- max : Scalar :: new ( non_nullable_dtype , ScalarValue :: from ( max. into ( ) ) ) ,
61+ min : Scalar :: decimal ( min. into ( ) , decimal_dtype , NonNullable ) ,
62+ max : Scalar :: decimal ( max. into ( ) , decimal_dtype , NonNullable ) ,
6063 } ) ,
6164 }
6265}
0 commit comments