Samyak2 commented on code in PR #7919:
URL: https://github.com/apache/arrow-rs/pull/7919#discussion_r2203142685


##########
parquet-variant-compute/src/utils.rs:
##########
@@ -0,0 +1,48 @@
+use arrow::{
+    array::{Array, ArrayRef, BinaryArray, StructArray},
+    error::Result,
+};
+use arrow_schema::{ArrowError, DataType};
+
+pub fn variant_from_struct_array(
+    input: &ArrayRef,
+) -> Result<(&StructArray, &BinaryArray, &BinaryArray)> {
+    let struct_array = input
+        .as_any()
+        .downcast_ref::<StructArray>()
+        .ok_or_else(|| ArrowError::CastError("Expected StructArray as 
input".into()))?;
+
+    // Validate field types
+    let data_type = struct_array.data_type();
+    match data_type {
+        DataType::Struct(inner_fields) => {
+            if inner_fields.len() != 2
+                || inner_fields[0].data_type() != &DataType::Binary
+                || inner_fields[1].data_type() != &DataType::Binary
+            {
+                return Err(ArrowError::CastError(
+                    "Expected struct with two binary fields".into(),
+                ));
+            }
+        }
+        _ => {
+            return Err(ArrowError::CastError(
+                "Expected StructArray with known fields".into(),
+            ))
+        }
+    }
+
+    let metadata_array = struct_array
+        .column(0)
+        .as_any()
+        .downcast_ref::<BinaryArray>()
+        .ok_or_else(|| ArrowError::CastError("Expected BinaryArray for 
'metadata'".into()))?;
+
+    let value_array = struct_array
+        .column(1)

Review Comment:
   Yep, you're right. I copied this code from `batch_variant_to_json_string`. 
Now that we have VariantArray, we don't need this anymore.



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