alamb commented on code in PR #8196:
URL: https://github.com/apache/arrow-rs/pull/8196#discussion_r2291833636


##########
parquet-variant-compute/src/cast_to_variant.rs:
##########
@@ -544,8 +530,41 @@ pub fn cast_to_variant(input: &dyn Array) -> 
Result<VariantArray, ArrowError> {
     Ok(builder.build())
 }
 
-/// Generic function to process run-end encoded arrays
-fn process_run_end_encoded<R: RunEndIndexType>(
+/// Convert union arrays
+fn convert_union(
+    fields: &UnionFields,
+    input: &dyn Array,
+    builder: &mut VariantArrayBuilder,
+) -> Result<(), ArrowError> {
+    let union_array = input.as_union();
+
+    // Convert each child array to variant arrays
+    let mut child_variant_arrays = HashMap::new();
+    for (type_id, _) in fields.iter() {
+        let child_array = union_array.child(type_id);
+        let child_variant_array = cast_to_variant(child_array.as_ref())?;
+        child_variant_arrays.insert(type_id, child_variant_array);
+    }
+
+    // Process each element in the union array
+    for i in 0..union_array.len() {
+        let type_id = union_array.type_id(i);
+        let value_offset = union_array.value_offset(i);
+
+        if let Some(child_variant_array) = child_variant_arrays.get(&type_id) {
+            let value = child_variant_array.value(value_offset);
+            builder.append_variant(value);
+        } else {
+            // This should not happen in a valid union, but handle gracefully

Review Comment:
   👍 



##########
parquet-variant-compute/src/cast_to_variant.rs:
##########
@@ -544,8 +530,41 @@ pub fn cast_to_variant(input: &dyn Array) -> 
Result<VariantArray, ArrowError> {
     Ok(builder.build())
 }
 
-/// Generic function to process run-end encoded arrays
-fn process_run_end_encoded<R: RunEndIndexType>(
+/// Convert union arrays
+fn convert_union(
+    fields: &UnionFields,
+    input: &dyn Array,
+    builder: &mut VariantArrayBuilder,
+) -> Result<(), ArrowError> {
+    let union_array = input.as_union();
+
+    // Convert each child array to variant arrays
+    let mut child_variant_arrays = HashMap::new();
+    for (type_id, _) in fields.iter() {

Review Comment:
   I don't understand what you are suggesting



##########
parquet-variant-compute/src/cast_to_variant.rs:
##########
@@ -1620,6 +1667,93 @@ mod tests {
         assert_eq!(obj4.get("age"), None);
     }
 
+    #[test]
+    fn test_cast_to_variant_union_sparse() {

Review Comment:
   could we please add a test for a UnionArray where the child element is null? 
So that the output VariantArray has a null as well?



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