steveloughran commented on code in PR #3415:
URL: https://github.com/apache/parquet-java/pull/3415#discussion_r2959013394


##########
parquet-variant/src/main/java/org/apache/parquet/variant/VariantBuilder.java:
##########
@@ -65,6 +73,152 @@ public VariantBuilder(Metadata metadata) {
     this.metadata = metadata;
   }
 
+  /**
+   * Parses a JSON string and returns the corresponding {@link Variant}.
+   *
+   * <p>Uses Jackson streaming parser for single-pass conversion
+   * with no intermediate tree. Number handling preserves precision:
+   * integers use the smallest fitting type, floating-point numbers
+   * prefer decimal encoding (no scientific notation) and fall back
+   * to double.
+   *
+   * <p>Ported from Apache Spark's {@code VariantBuilder.parseJson}.
+   *
+   * @param json the JSON string to parse
+   * @return the parsed Variant
+   * @throws IOException if the JSON is malformed or an I/O error occurs
+   */
+  public static Variant parseJson(String json) throws IOException {
+    try (JsonParser parser = JSON_FACTORY.createParser(json)) {

Review Comment:
   can be quite slow



##########
parquet-variant/src/test/java/org/apache/parquet/variant/TestVariantParseJson.java:
##########
@@ -0,0 +1,307 @@
+/*
+ * 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.
+ */
+package org.apache.parquet.variant;
+
+import com.fasterxml.jackson.core.JsonFactory;
+import com.fasterxml.jackson.core.JsonParser;
+import java.io.IOException;
+import java.math.BigDecimal;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class TestVariantParseJson {

Review Comment:
   1. nested object parsing?
   2. what about invalid json?
   * empty file
   * not a json file
   * incomplete
   * large json with many values



##########
NOTICE:
##########
@@ -73,3 +73,14 @@ notice:
 | See the License for the specific language governing permissions and
 | limitations under the License.
 
+--------------------------------------------------------------------------------
+
+This project includes code from Apache Spark with the following copyright
+notice:
+
+  Apache Spark

Review Comment:
   do cross-ASF projects need this credit? What I do think is good is ensure 
the original authors get credit in the final commit message



##########
parquet-variant/src/main/java/org/apache/parquet/variant/VariantBuilder.java:
##########
@@ -30,6 +36,8 @@
  */
 public class VariantBuilder {
 
+  private static final JsonFactory JSON_FACTORY = new JsonFactory();

Review Comment:
   factory should be built with some constraints so that giving it a malicious 
json file should be rejected rather than trigger OOM problems, etc. From the 
javadocs.
   
   ```
   JsonFactory f = JsonFactory.builder()
       .streamReadConstraints(
           StreamReadConstraints.builder()
               .maxNestingDepth(500)
               .maxStringLength(10_000_000)
               .maxDocumentLength(5_000_000)
               .build()
       )
       .build();
   ```
   



##########
parquet-variant/src/main/java/org/apache/parquet/variant/VariantBuilder.java:
##########
@@ -65,6 +73,152 @@ public VariantBuilder(Metadata metadata) {
     this.metadata = metadata;
   }
 
+  /**
+   * Parses a JSON string and returns the corresponding {@link Variant}.
+   *
+   * <p>Uses Jackson streaming parser for single-pass conversion
+   * with no intermediate tree. Number handling preserves precision:
+   * integers use the smallest fitting type, floating-point numbers
+   * prefer decimal encoding (no scientific notation) and fall back
+   * to double.
+   *
+   * <p>Ported from Apache Spark's {@code VariantBuilder.parseJson}.
+   *
+   * @param json the JSON string to parse
+   * @return the parsed Variant
+   * @throws IOException if the JSON is malformed or an I/O error occurs
+   */
+  public static Variant parseJson(String json) throws IOException {

Review Comment:
   I was to suggest making CharSequence for feeding in from other places 
(string fields within avro, ...) but it looks like jackson 2 doesn't support 
that itself.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to