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 @@ -9980,7 +9980,26 @@ mod tests {
9980
9980
} ;
9981
9981
let result = cast_with_options ( & array, & output_type, & options) ;
9982
9982
assert_eq ! ( result. unwrap_err( ) . to_string( ) ,
9983
- "Invalid argument error: 123456790 is too large to store in a Decimal128 of precision 6. Max is 999999" ) ;
9983
+ "Invalid argument error: 123456789 is too large to store in a Decimal128 of precision 6. Max is 999999" ) ;
9984
+ }
9985
+
9986
+ #[ test]
9987
+ fn test_decimal_to_decimal_same_scale ( ) {
9988
+ let array = vec ! [ Some ( 520 ) ] ;
9989
+ let array = create_decimal_array ( array, 4 , 2 ) . unwrap ( ) ;
9990
+ let input_type = DataType :: Decimal128 ( 4 , 2 ) ;
9991
+ let output_type = DataType :: Decimal128 ( 3 , 2 ) ;
9992
+ assert ! ( can_cast_types( & input_type, & output_type) ) ;
9993
+
9994
+ let options = CastOptions {
9995
+ safe : false ,
9996
+ ..Default :: default ( )
9997
+ } ;
9998
+ let result = cast_with_options ( & array, & output_type, & options) ;
9999
+ assert_eq ! (
10000
+ result. unwrap( ) . as_primitive:: <Decimal128Type >( ) . value( 0 ) ,
10001
+ 520
10002
+ ) ;
9984
10003
}
9985
10004
9986
10005
#[ test]
You can’t perform that action at this time.
0 commit comments