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


##########
parquet-variant-compute/src/from_json.rs:
##########
@@ -19,40 +19,57 @@
 //! STRUCT<metadata: BINARY, value: BINARY>
 
 use crate::{VariantArray, VariantArrayBuilder};
-use arrow::array::{Array, ArrayRef, StringArray};
+use arrow::array::{Array, ArrayRef, LargeStringArray, StringArray, 
StringViewArray};
 use arrow_schema::ArrowError;
 use parquet_variant_json::json_to_variant;
 
+/// Macro to convert string array to variant array
+macro_rules! string_array_to_variant {
+    ($input:expr, $array:expr, $builder:expr) => {{
+        for i in 0..$input.len() {
+            if $input.is_null(i) {
+                $builder.append_null();
+            } else {
+                let mut vb = $builder.variant_builder();
+                json_to_variant($array.value(i), &mut vb)?;
+                vb.finish()
+            }
+        }
+    }};
+}
+
 /// Parse a batch of JSON strings into a batch of Variants represented as
 /// STRUCT<metadata: BINARY, value: BINARY> where nulls are preserved. The 
JSON strings in the input
 /// must be valid.
+///
+/// Supports the following string array types:
+/// - [`StringArray`]
+/// - [`LargeStringArray`]
+/// - [`StringViewArray`]
 pub fn batch_json_string_to_variant(input: &ArrayRef) -> Result<VariantArray, 
ArrowError> {
-    let input_string_array = match 
input.as_any().downcast_ref::<StringArray>() {
-        Some(string_array) => Ok(string_array),
-        None => Err(ArrowError::CastError(
-            "Expected reference to StringArray as input".into(),
-        )),
-    }?;
-
-    let mut variant_array_builder = 
VariantArrayBuilder::new(input_string_array.len());
-    for i in 0..input.len() {
-        if input.is_null(i) {
-            // The subfields are expected to be non-nullable according to the 
parquet variant spec.
-            variant_array_builder.append_null();
-        } else {
-            let mut vb = variant_array_builder.variant_builder();
-            // parse JSON directly to the variant builder
-            json_to_variant(input_string_array.value(i), &mut vb)?;
-            vb.finish()
-        }
+    let mut variant_array_builder = VariantArrayBuilder::new(input.len());
+
+    // Try each string array type in sequence

Review Comment:
   👍 



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