ding-young commented on code in PR #7627: URL: https://github.com/apache/arrow-rs/pull/7627#discussion_r2284090879
########## arrow-row/src/lib.rs: ########## @@ -2148,6 +2172,166 @@ mod tests { back[0].to_data().validate_full().unwrap(); } + #[test] + fn test_dictionary_in_struct() { + let ty = DataType::Struct( + vec![Field::new_dictionary( + "foo", + DataType::Int32, + DataType::Int32, + false, + )] + .into(), + ); + // Test Case 1. empty array + let s = arrow_array::new_empty_array(&ty); + + let sort_fields = vec![SortField::new(s.data_type().clone())]; + let converter = RowConverter::new(sort_fields).unwrap(); + let r = converter.convert_columns(&[Arc::clone(&s)]).unwrap(); + + let back = converter.convert_rows(&r).unwrap(); + let [s2] = back.try_into().unwrap(); + + // RowConverter flattens Dictionary + // s.ty = Struct(foo Dictionary(Int32, Int32)), s2.ty = Struct(foo Int32) + assert_ne!(&s.data_type(), &s2.data_type()); + s2.to_data().validate_full().unwrap(); + assert_eq!(s.len(), s2.len()); + + // Test Case 2. None empty array + let builder = PrimitiveDictionaryBuilder::<Int32Type, Int32Type>::new(); + let mut struct_builder = StructBuilder::new( + vec![Field::new_dictionary( + "foo", + DataType::Int32, + DataType::Int32, + false, + )], + vec![Box::new(builder)], + ); + let dict_builder = struct_builder + .field_builder::<PrimitiveDictionaryBuilder<Int32Type, Int32Type>>(0) Review Comment: I changed the dictionary type to `Dictionary(Int32, Utf8)` to improve readability. Let me know if anything in the test is still confusing or hard to follow. -- 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