snuyanzin commented on code in PR #29483:
URL: https://github.com/apache/flink/pull/29483#discussion_r4293131659


##########
flink-table/flink-table-planner/src/main/java/org/apache/flink/table/planner/codegen/JsonCodeGenUtils.java:
##########
@@ -22,16 +22,220 @@
 import org.apache.flink.table.planner.codegen.calls.JsonParseReuse;
 import org.apache.flink.table.runtime.functions.SqlJsonUtils;
 import org.apache.flink.table.types.logical.LogicalType;
+import org.apache.flink.types.variant.Variant;
 
 import java.lang.reflect.Method;
 
+import scala.Option;
 import scala.collection.Seq;
 
 /** Utilities for the code generation of JSON functions. */
 public final class JsonCodeGenUtils {
 
+    private static final int PARSED_VALUE_INDEX = Integer.MIN_VALUE;
+    private static final int PARSED_ERROR_INDEX = Integer.MIN_VALUE + 1;
+
     private JsonCodeGenUtils() {}
 
+    /**
+     * Generates {@code PARSE_JSON(str[, allowDuplicateKeys])} ({@code isTry 
== false}) or {@code
+     * TRY_PARSE_JSON(...)} ({@code isTry == true}).
+     *
+     * <p>The input is parsed at most once per record for a given (input, 
allowDuplicateKeys) pair
+     * and shared across all such calls; {@code PARSE_JSON} rethrows a parse 
error while {@code
+     * TRY_PARSE_JSON} returns NULL.
+     *
+     * <p>For {@code PARSE_JSON(str)} the generated code looks like:
+     *
+     * <pre>{@code
+     * // reusable members shared by every call on the same (input, allowDup):
+     * Variant variantParsed$0;
+     * Throwable variantParseError$0;
+     * StringData variantParseInput$0;
+     * java.lang.Boolean variantParseDup$0;
+     *
+     * private Variant parseVariant$0(StringData in, java.lang.Boolean 
allowDup) {
+     *   if (in != variantParseInput$0 || !java.util.Objects.equals(allowDup, 
variantParseDup$0)) {

Review Comment:
   probably makes sense, done



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

Reply via email to