liamzwbao commented on code in PR #8101: URL: https://github.com/apache/arrow-rs/pull/8101#discussion_r2271740076
########## parquet-variant-compute/src/cast_to_variant.rs: ########## @@ -482,6 +568,302 @@ mod tests { ) } + #[test] + fn test_cast_to_variant_decimal32() { + run_test( + Arc::new( + Decimal32Array::from(vec![ + Some(i32::MIN), + Some(-max_unscaled_value!(32, DECIMAL32_MAX_PRECISION)), + None, + Some(-123), + Some(0), + Some(123), + Some(max_unscaled_value!(32, DECIMAL32_MAX_PRECISION)), + Some(i32::MAX), + ]) + .with_precision_and_scale(DECIMAL32_MAX_PRECISION, 3) + .unwrap(), + ), + vec![ + Some(Variant::Null), + Some( + VariantDecimal4::try_new(-max_unscaled_value!(32, DECIMAL32_MAX_PRECISION), 3) + .unwrap() + .into(), + ), + None, + Some(VariantDecimal4::try_new(-123, 3).unwrap().into()), + Some(VariantDecimal4::try_new(0, 3).unwrap().into()), + Some(VariantDecimal4::try_new(123, 3).unwrap().into()), + Some( + VariantDecimal4::try_new(max_unscaled_value!(32, DECIMAL32_MAX_PRECISION), 3) + .unwrap() + .into(), + ), + Some(Variant::Null), + ], + ) + } + + #[test] + fn test_cast_to_variant_decimal32_negative_scale() { + run_test( + Arc::new( + Decimal32Array::from(vec![ + Some(i32::MIN), + Some(-max_unscaled_value!(32, DECIMAL32_MAX_PRECISION)), + None, + Some(-123), + Some(0), + Some(123), + Some(max_unscaled_value!(32, DECIMAL32_MAX_PRECISION)), + Some(i32::MAX), + ]) + .with_precision_and_scale(DECIMAL32_MAX_PRECISION, -3) + .unwrap(), + ), + vec![ + Some(Variant::Null), + Some(Variant::Null), + None, + Some(VariantDecimal4::try_new(-123_000, 0).unwrap().into()), + Some(VariantDecimal4::try_new(0, 0).unwrap().into()), + Some(VariantDecimal4::try_new(123_000, 0).unwrap().into()), + Some(Variant::Null), + Some(Variant::Null), + ], + ) + } + + #[test] + fn test_cast_to_variant_decimal64() { + run_test( + Arc::new( + Decimal64Array::from(vec![ + Some(i64::MIN), + Some(-max_unscaled_value!(64, DECIMAL64_MAX_PRECISION)), + None, + Some(-123), + Some(0), + Some(123), + Some(max_unscaled_value!(64, DECIMAL64_MAX_PRECISION)), + Some(i64::MAX), + ]) + .with_precision_and_scale(DECIMAL64_MAX_PRECISION, 3) + .unwrap(), + ), + vec![ + Some(Variant::Null), + Some( + VariantDecimal8::try_new(-max_unscaled_value!(64, DECIMAL64_MAX_PRECISION), 3) + .unwrap() + .into(), + ), + None, + Some(VariantDecimal8::try_new(-123, 3).unwrap().into()), + Some(VariantDecimal8::try_new(0, 3).unwrap().into()), + Some(VariantDecimal8::try_new(123, 3).unwrap().into()), + Some( + VariantDecimal8::try_new(max_unscaled_value!(64, DECIMAL64_MAX_PRECISION), 3) + .unwrap() + .into(), + ), + Some(Variant::Null), + ], + ) + } + + #[test] + fn test_cast_to_variant_decimal64_negative_scale() { + run_test( + Arc::new( + Decimal64Array::from(vec![ + Some(i64::MIN), + Some(-max_unscaled_value!(64, DECIMAL64_MAX_PRECISION)), + None, + Some(-123), + Some(0), + Some(123), + Some(max_unscaled_value!(64, DECIMAL64_MAX_PRECISION)), + Some(i64::MAX), + ]) + .with_precision_and_scale(DECIMAL64_MAX_PRECISION, -3) + .unwrap(), + ), + vec![ + Some(Variant::Null), + Some(Variant::Null), + None, + Some(VariantDecimal8::try_new(-123_000, 0).unwrap().into()), + Some(VariantDecimal8::try_new(0, 0).unwrap().into()), + Some(VariantDecimal8::try_new(123_000, 0).unwrap().into()), + Some(Variant::Null), + Some(Variant::Null), + ], + ) + } + + #[test] + fn test_cast_to_variant_decimal128() { + run_test( + Arc::new( + Decimal128Array::from(vec![ + Some(i128::MIN), + Some(-max_unscaled_value!(128, DECIMAL128_MAX_PRECISION)), + None, + Some(-123), + Some(0), + Some(123), + Some(max_unscaled_value!(128, DECIMAL128_MAX_PRECISION)), + Some(i128::MAX), + ]) + .with_precision_and_scale(DECIMAL128_MAX_PRECISION, 3) + .unwrap(), + ), + vec![ + Some(Variant::Null), + Some( + VariantDecimal16::try_new( + -max_unscaled_value!(128, DECIMAL128_MAX_PRECISION), + 3, + ) + .unwrap() + .into(), + ), + None, + Some(VariantDecimal16::try_new(-123, 3).unwrap().into()), + Some(VariantDecimal16::try_new(0, 3).unwrap().into()), + Some(VariantDecimal16::try_new(123, 3).unwrap().into()), + Some( + VariantDecimal16::try_new( + max_unscaled_value!(128, DECIMAL128_MAX_PRECISION), + 3, + ) + .unwrap() + .into(), + ), + Some(Variant::Null), + ], + ) + } + + #[test] + fn test_cast_to_variant_decimal128_negative_scale() { + run_test( + Arc::new( + Decimal128Array::from(vec![ + Some(i128::MIN), + Some(-max_unscaled_value!(128, DECIMAL128_MAX_PRECISION)), Review Comment: I guess you meant the `Decimal256` tests. The reason I didn't use `DECIMAL256_MAX_PRECISION` is that `DECIMAL128_MAX_PRECISION` can already cause the overflow in the test cases. I have updated the test cases to include the min/max value that can be cast from `Decimal` to `VariantDecimal` so these should be clearer -- 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