File tree 2 files changed +21
-3
lines changed
2 files changed +21
-3
lines changed Original file line number Diff line number Diff line change @@ -167,8 +167,7 @@ where
167
167
let array: PrimitiveArray < T > =
168
168
if input_scale == output_scale && input_precision <= output_precision {
169
169
array. clone ( )
170
- } else if input_scale < output_scale {
171
- // the scale doesn't change, but precision may change and cause overflow
170
+ } else if input_scale <= output_scale {
172
171
convert_to_bigger_or_equal_scale_decimal :: < T , T > (
173
172
array,
174
173
input_scale,
Original file line number Diff line number Diff line change @@ -9958,7 +9958,26 @@ mod tests {
9958
9958
} ;
9959
9959
let result = cast_with_options ( & array, & output_type, & options) ;
9960
9960
assert_eq ! ( result. unwrap_err( ) . to_string( ) ,
9961
- "Invalid argument error: 123456790 is too large to store in a Decimal128 of precision 6. Max is 999999" ) ;
9961
+ "Invalid argument error: 123456789 is too large to store in a Decimal128 of precision 6. Max is 999999" ) ;
9962
+ }
9963
+
9964
+ #[ test]
9965
+ fn test_decimal_to_decimal_same_scale ( ) {
9966
+ let array = vec ! [ Some ( 520 ) ] ;
9967
+ let array = create_decimal_array ( array, 4 , 2 ) . unwrap ( ) ;
9968
+ let input_type = DataType :: Decimal128 ( 4 , 2 ) ;
9969
+ let output_type = DataType :: Decimal128 ( 3 , 2 ) ;
9970
+ assert ! ( can_cast_types( & input_type, & output_type) ) ;
9971
+
9972
+ let options = CastOptions {
9973
+ safe : false ,
9974
+ ..Default :: default ( )
9975
+ } ;
9976
+ let result = cast_with_options ( & array, & output_type, & options) ;
9977
+ assert_eq ! (
9978
+ result. unwrap( ) . as_primitive:: <Decimal128Type >( ) . value( 0 ) ,
9979
+ 520
9980
+ ) ;
9962
9981
}
9963
9982
9964
9983
#[ test]
You can’t perform that action at this time.
0 commit comments