liamzwbao commented on code in PR #8552:
URL: https://github.com/apache/arrow-rs/pull/8552#discussion_r2407739486
##########
parquet-variant-compute/src/variant_get.rs:
##########
@@ -2679,4 +2687,371 @@ mod test {
Arc::new(struct_array)
}
+
+ macro_rules! max_unscaled_value {
+ (32, $precision:expr) => {
+ (u32::pow(10, $precision as u32) - 1) as i32
+ };
+ (64, $precision:expr) => {
+ (u64::pow(10, $precision as u32) - 1) as i64
+ };
+ (128, $precision:expr) => {
+ (u128::pow(10, $precision as u32) - 1) as i128
+ };
+ }
+
+ #[test]
+ fn get_decimal32_unshredded_var_scales_to_scale2() {
+ // Build unshredded variant values with different scales
+ let mut builder = crate::VariantArrayBuilder::new(4);
+ builder.append_variant(Variant::from(VariantDecimal4::try_new(1234,
2).unwrap())); // 12.34
+ builder.append_variant(Variant::from(VariantDecimal4::try_new(1234,
3).unwrap())); // 1.234
+ builder.append_variant(Variant::from(VariantDecimal4::try_new(1234,
0).unwrap())); // 1234
+ builder.append_null();
+ let variant_array: ArrayRef = ArrayRef::from(builder.build());
+
+ let field = Field::new("result", DataType::Decimal32(9, 2), true);
+ let options =
GetOptions::new().with_as_type(Some(FieldRef::from(field)));
+ let result = variant_get(&variant_array, options).unwrap();
+ let result = result.as_any().downcast_ref::<Decimal32Array>().unwrap();
+
+ assert_eq!(result.precision(), 9);
+ assert_eq!(result.scale(), 2);
+ assert_eq!(result.value(0), 1234);
+ assert_eq!(result.value(1), 123);
+ assert_eq!(result.value(2), 123400);
+ assert!(result.is_null(3));
+ }
+
+ #[test]
+ fn get_decimal32_unshredded_scale_down_rounding() {
+ let mut builder = crate::VariantArrayBuilder::new(2);
+ builder.append_variant(Variant::from(VariantDecimal4::try_new(1235,
3).unwrap()));
+ builder.append_variant(Variant::from(VariantDecimal4::try_new(1245,
3).unwrap()));
+ builder.append_variant(Variant::from(VariantDecimal4::try_new(-1235,
3).unwrap()));
+ builder.append_variant(Variant::from(VariantDecimal4::try_new(-1245,
3).unwrap()));
+ let variant_array: ArrayRef = ArrayRef::from(builder.build());
+
+ let field = Field::new("result", DataType::Decimal32(9, 2), true);
+ let options =
GetOptions::new().with_as_type(Some(FieldRef::from(field)));
+ let result = variant_get(&variant_array, options).unwrap();
+ let result = result.as_any().downcast_ref::<Decimal32Array>().unwrap();
+
+ assert_eq!(result.value(0), 124);
Review Comment:
Makes sense, added
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]