Skip to content

Commit 1019f5b

Browse files
himadripalBlizzara
andauthored
fix: issue introduced in #6833 - less than equal check for scale in decimal conversion (#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 9327f47 commit 1019f5b

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

arrow-cast/src/cast/decimal.rs

Lines changed: 1 addition & 2 deletions
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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9980,7 +9980,26 @@ mod tests {
99809980
};
99819981
let result = cast_with_options(&array, &output_type, &options);
99829982
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+
);
998410003
}
998510004

998610005
#[test]

0 commit comments

Comments
 (0)