diff --git a/src/common/src/array/arrow/arrow_iceberg.rs b/src/common/src/array/arrow/arrow_iceberg.rs index 25a03c8d7f6d..80c0a3dab166 100644 --- a/src/common/src/array/arrow/arrow_iceberg.rs +++ b/src/common/src/array/arrow/arrow_iceberg.rs @@ -140,12 +140,8 @@ impl ToArrow for IcebergArrowConvert { let scale = e.scale() as i8; let diff_scale = abs(max_scale - scale); let value = match scale { - _ if scale < max_scale => { - value.mul(10_i32.pow(diff_scale as u32) as i128) - } - _ if scale > max_scale => { - value.div(10_i32.pow(diff_scale as u32) as i128) - } + _ if scale < max_scale => value.mul(10_i128.pow(diff_scale as u32)), + _ if scale > max_scale => value.div(10_i128.pow(diff_scale as u32)), _ => value, }; Some(value) @@ -297,4 +293,30 @@ mod test { ) as ArrayRef; assert_eq!(&arrow_array, &expect_array); } + + #[test] + fn decimal_with_large_scale() { + let array = DecimalArray::from_iter([ + None, + Some(Decimal::NaN), + Some(Decimal::PositiveInf), + Some(Decimal::NegativeInf), + Some(Decimal::Normalized("123.4".parse().unwrap())), + Some(Decimal::Normalized("123.456".parse().unwrap())), + ]); + let ty = DataType::Decimal128(28, 10); + let arrow_array = IcebergArrowConvert.decimal_to_arrow(&ty, &array).unwrap(); + let expect_array = Arc::new( + Decimal128Array::from(vec![ + None, + None, + Some(9999999999999999999999999999), + Some(-9999999999999999999999999999), + Some(1234000000000), + Some(1234560000000), + ]) + .with_data_type(ty), + ) as ArrayRef; + assert_eq!(&arrow_array, &expect_array); + } }