Skip to content

Commit e070c4a

Browse files
himadripalBlizzara
authored andcommitted
fix: issue introduced in apache#6833 - less than equal check for scale in decimal conversion (apache#7070)
* fix <= check for scale in decimal conversion * Update arrow-cast/src/cast/mod.rs name change Co-authored-by: Arttu <[email protected]> * remove incorrect comment --------- Co-authored-by: Arttu <[email protected]>
1 parent bbcc71b commit e070c4a

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

arrow-cast/src/cast/decimal.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,7 @@ where
167167
let array: PrimitiveArray<T> =
168168
if input_scale == output_scale && input_precision <= output_precision {
169169
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 {
172171
convert_to_bigger_or_equal_scale_decimal::<T, T>(
173172
array,
174173
input_scale,

arrow-cast/src/cast/mod.rs

+20-1
Original file line numberDiff line numberDiff line change
@@ -9958,7 +9958,26 @@ mod tests {
99589958
};
99599959
let result = cast_with_options(&array, &output_type, &options);
99609960
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+
);
99629981
}
99639982

99649983
#[test]

0 commit comments

Comments
 (0)