sdf-jkl commented on code in PR #9663:
URL: https://github.com/apache/arrow-rs/pull/9663#discussion_r3046743655
##########
parquet-variant-compute/src/shred_variant.rs:
##########
@@ -1608,6 +1608,67 @@ mod tests {
#[test]
fn test_array_shredding_as_fixed_size_list() {
+ let input = build_variant_array(vec![
+ VariantRow::List(vec![VariantValue::from(1i64),
VariantValue::from(2i64)]),
+ VariantRow::Value(VariantValue::from("This should not be
shredded")),
+ VariantRow::List(vec![VariantValue::from(3i64),
VariantValue::from(4i64)]),
+ ]);
+
+ let list_schema =
+ DataType::FixedSizeList(Arc::new(Field::new("item",
DataType::Int64, true)), 2);
+ let result = shred_variant(&input, &list_schema).unwrap();
+ assert_eq!(result.len(), 3);
+
+ // The first row should be shredded, so the `value` field should be
null and the
+ // `typed_value` field should contain the list
+ assert!(result.is_valid(0));
+ assert!(result.value_field().unwrap().is_null(0));
+ assert!(result.typed_value_field().unwrap().is_valid(0));
+
+ // The second row should not be shredded because the provided schema
for shredding did not
+ // match. Hence, the `value` field should contain the raw value and
the `typed_value` field
+ // should be null.
+ assert!(result.is_valid(1));
+ assert!(result.value_field().unwrap().is_valid(1));
+ assert!(result.typed_value_field().unwrap().is_null(1));
+
+ // The third row should be shredded, so the `value` field should be
null and the
+ // `typed_value` field should contain the list
+ assert!(result.is_valid(2));
+ assert!(result.value_field().unwrap().is_null(2));
+ assert!(result.typed_value_field().unwrap().is_valid(2));
+
+ let typed_value = result.typed_value_field().unwrap();
+ let fixed_size_list = typed_value
+ .as_any()
+ .downcast_ref::<FixedSizeListArray>()
+ .expect("Expected FixedSizeListArray");
+
+ // Verify that typed value is `FixedSizeList`.
+ assert_eq!(fixed_size_list.len(), 3);
+ assert_eq!(fixed_size_list.value_length(), 2);
+
+ // Verify that the first entry in the `FixedSizeList` contains the
expected value.
+ let val0 = fixed_size_list.value(0);
+ let val0_struct = val0.as_any().downcast_ref::<StructArray>().unwrap();
+ let val0_typed = val0_struct.column_by_name("typed_value").unwrap();
+ let val0_ints =
val0_typed.as_any().downcast_ref::<Int64Array>().unwrap();
+ assert_eq!(val0_ints.values(), &[1i64, 2i64]);
+
+ // Verify that second entry in the `FixedSizeList` cannot be shredded
hence the value is
+ // invalid.
+ assert!(fixed_size_list.is_null(1));
+
+ // Verify that the third entry in the `FixedSizeList` contains the
expected value.
+ let val2 = fixed_size_list.value(2);
+ let val2_struct = val2.as_any().downcast_ref::<StructArray>().unwrap();
+ let val2_typed = val2_struct.column_by_name("typed_value").unwrap();
+ let val2_ints =
val2_typed.as_any().downcast_ref::<Int64Array>().unwrap();
+ assert_eq!(val2_ints.values(), &[3i64, 4i64]);
+ }
+
+ #[test]
+ fn test_array_shredding_as_fixed_size_list_wrong_size() {
Review Comment:
This test should follow the same cast logic as `variant_to_arrow`. Safe cast
-> `Null`, not `Err`.
We'd need to wire in the change to
`VariantToShreddedArrayVariantRowBuilder::append_value` `Variant::List` match
arm.
--
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]