alamb commented on code in PR #7627:
URL: https://github.com/apache/arrow-rs/pull/7627#discussion_r2143655781
##########
arrow-row/src/lib.rs:
##########
@@ -1863,6 +1887,64 @@ 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(),
+ );
+ 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();
+ }
+
+ #[test]
+ fn test_list_of_primitive_dictionary() {
+ let mut builder =
+ ListBuilder::<PrimitiveDictionaryBuilder<Int32Type,
Int32Type>>::default();
+ builder.values().append(2).unwrap();
+ builder.values().append(3).unwrap();
+ builder.values().append(0).unwrap();
+ builder.values().append_null();
+ builder.values().append(5).unwrap();
+ builder.values().append(3).unwrap();
+ builder.values().append(-1).unwrap();
+ builder.append(true);
+
+ let a = Arc::new(builder.finish()) as ArrayRef;
+ let data_type = a.data_type().clone();
+
+ let field = SortField::new(data_type.clone());
+ let converter = RowConverter::new(vec![field]).unwrap();
+ let rows = converter.convert_columns(&[Arc::clone(&a)]).unwrap();
+
+ let back = converter.convert_rows(&rows).unwrap();
+ assert_eq!(back.len(), 1);
+ let [a2] = back.try_into().unwrap();
+
+ // RowConverter flattens Dictionary
+ // a.ty: List(Dictionary(Int32, Int32)), a2.ty: List(Int32)
+ assert_ne!(&a.data_type(), &a2.data_type());
Review Comment:
this seems incorrect -- I would expect that I get the same kind and values
of array back from the RowConverter as went int
##########
arrow-row/src/lib.rs:
##########
@@ -1863,6 +1887,64 @@ 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(),
+ );
+ 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();
+ }
+
+ #[test]
+ fn test_list_of_primitive_dictionary() {
+ let mut builder =
+ ListBuilder::<PrimitiveDictionaryBuilder<Int32Type,
Int32Type>>::default();
+ builder.values().append(2).unwrap();
+ builder.values().append(3).unwrap();
+ builder.values().append(0).unwrap();
+ builder.values().append_null();
+ builder.values().append(5).unwrap();
+ builder.values().append(3).unwrap();
+ builder.values().append(-1).unwrap();
+ builder.append(true);
Review Comment:
Can you please update the test to include:
1. A null (`builder.append(false)`)
2. a second row with values
##########
arrow-row/src/lib.rs:
##########
@@ -1863,6 +1887,64 @@ 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(),
+ );
+ 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();
Review Comment:
Can you also add an assert that verifies the arrays made it through without
modification (e.g. `assert_eq!(s1, s2)`)?
--
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]