scovich commented on code in PR #7862:
URL: https://github.com/apache/arrow-rs/pull/7862#discussion_r2191119514


##########
parquet-variant-json/src/from_json.rs:
##########
@@ -0,0 +1,690 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+//! Module for parsing JSON strings as Variant
+
+use arrow_schema::ArrowError;
+use parquet_variant::{ListBuilder, ObjectBuilder, Variant, VariantBuilder, 
VariantBuilderExt};
+use serde_json::{Number, Value};
+
+/// Converts a JSON string to Variant using [`VariantBuilder`]. The resulting 
`value` and `metadata`
+/// buffers can be extracted using `builder.finish()`
+///
+/// # Arguments
+/// * `json` - The JSON string to parse as Variant.
+/// * `variant_builder` - Object of type `VariantBuilder` used to build the 
vatiant from the JSON
+///   string
+///
+/// # Returns
+///
+/// * `Ok(())` if successful
+/// * `Err` with error details if the conversion fails
+///
+/// ```rust
+/// # use parquet_variant::VariantBuilder;
+/// # use parquet_variant_json::{
+/// #   json_to_variant, variant_to_json_string, variant_to_json, 
variant_to_json_value
+/// # };
+///
+/// let mut variant_builder = VariantBuilder::new();
+/// let person_string = "{\"name\":\"Alice\", \"age\":30, ".to_string()
+/// + "\"email\":\"al...@example.com\", \"is_active\": true, \"score\": 95.7,"
+/// + "\"additional_info\": null}";
+/// json_to_variant(&person_string, &mut variant_builder)?;
+///
+/// let (metadata, value) = variant_builder.finish();
+///
+/// let variant = parquet_variant::Variant::try_new(&metadata, &value)?;
+///
+/// let json_result = variant_to_json_string(&variant)?;
+/// let json_value = variant_to_json_value(&variant)?;
+///
+/// let mut buffer = Vec::new();
+/// variant_to_json(&mut buffer, &variant)?;

Review Comment:
   Every engine needs the ability to convert variant values to strings, in 
order to display query results:
   ```sql
   SELECT v FROM t
   ```
   And the string form of a variant column is the output of 
`variant_to_json_string`.
   
   This is true regardless of which JSON library they might use (serde_json vs 
arrow-json vs. something else entirely), and also true even if they use no JSON 
library at all.
   
   In other words, 
   
   > we can always put to_json back if a need arises
   
   ... will happen the moment an engine actually tries to integrate with 
parquet-json and doesn't want to take on a serde-json dependency. The fact that 
this PR tries to isolate the serde-json dependency to its own sub-crate is a 
claim that such engines exist.
   
   > it is pretty confusing to have json functionality split across two crates
   
   JSON functionality (as in, parsing and manipulating JSON trees) is different 
from converting variant values to strings, even if it so happens that the 
string form is a JSON value literal?
   
   What if we drop `variant_to_json_string` from the public API, and just `impl 
Display for Variant` instead? Anything fancier would require a json library.



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