liukun4515 commented on a change in pull request #1603: URL: https://github.com/apache/arrow-datafusion/pull/1603#discussion_r786701728
########## File path: datafusion/src/physical_plan/expressions/cast.rs ########## @@ -269,6 +269,168 @@ mod tests { }}; } + fn create_decimal_array( + array: &[i128], + precision: usize, + scale: usize, + ) -> Result<DecimalArray> { + let mut decimal_builder = DecimalBuilder::new(array.len(), precision, scale); + for value in array { + decimal_builder.append_value(*value)? + } + decimal_builder.append_null()?; + Ok(decimal_builder.finish()) + } + + #[test] + fn test_cast_decimal_to_decimal() -> Result<()> { + let array: Vec<i128> = vec![1234, 2222, 3, 4000, 5000]; + let decimal_array = create_decimal_array(&array, 10, 3)?; + generic_decimal_to_other_test_cast!( + decimal_array, + DataType::Decimal(10, 3), + DecimalArray, + DataType::Decimal(20, 6), + vec![ + Some(1234_000_i128), + Some(2222_000_i128), + Some(3_000_i128), + Some(4000_000_i128), + Some(5000_000_i128), + None, + ], + DEFAULT_DATAFUSION_CAST_OPTIONS + ); + + let decimal_array = create_decimal_array(&array, 10, 3)?; + generic_decimal_to_other_test_cast!( + decimal_array, + DataType::Decimal(10, 3), + DecimalArray, + DataType::Decimal(10, 2), + vec![ + Some(123_i128), + Some(222_i128), + Some(0_i128), + Some(400_i128), + Some(500_i128), + None, + ], + DEFAULT_DATAFUSION_CAST_OPTIONS + ); + + Ok(()) + } + + #[test] + fn test_cast_decimal_to_numeric() -> Result<()> { Review comment: move test to here -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: github-unsubscr...@arrow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org