gabotechs commented on code in PR #7627:
URL: https://github.com/apache/arrow-rs/pull/7627#discussion_r2272891050


##########
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:
   🤔 I think technically they do are the same values, they just happen to be 
encoded differently (Dictionary encoded VS raw).
   
   Probably this test should be asserting that the data remains the same on 
both ends regardless of the encoding.



-- 
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

Reply via email to