You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "liamzwbao (via GitHub)" <gi...@apache.org> on 2025/08/17 14:00:08 UTC

[PR] [Variant] Support `LargeString` and `StringView` in `batch_json_string_to_variant` [arrow-rs]

liamzwbao opened a new pull request, #8163:
URL: https://github.com/apache/arrow-rs/pull/8163

   # Which issue does this PR close?
   
   We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax.
   
   - Closes #8145.
   
   # Rationale for this change
   
   # What changes are included in this PR?
   
   Implement `LargeString` and `StringView` process in json_to_variant convertion.
   
   # Are these changes tested?
   
   Yes, added tests
   
   # Are there any user-facing changes?
   
   Yes, new string types are supported
   


-- 
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-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Variant] Support `LargeString` and `StringView` in `batch_json_string_to_variant` [arrow-rs]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb merged PR #8163:
URL: https://github.com/apache/arrow-rs/pull/8163


-- 
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-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Variant] Support `LargeString` and `StringView` in `batch_json_string_to_variant` [arrow-rs]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
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-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Variant] Support `LargeString` and `StringView` in `batch_json_string_to_variant` [arrow-rs]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #8163:
URL: https://github.com/apache/arrow-rs/pull/8163#issuecomment-3198212578

   Merging so we can resolve conflicts with
   - https://github.com/apache/arrow-rs/pull/8163
   - 


-- 
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-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org