You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by "snuyanzin (via GitHub)" <gi...@apache.org> on 2026/10/17 19:31:42 UTC

[PR] [FLINK-40463][table] Widen `JSON_VALUE` and `JSON_QUERY` `RETURNING` type support [flink]

snuyanzin opened a new pull request, #29506:
URL: https://github.com/apache/flink/pull/29506

   <!--
   *Thank you very much for contributing to Apache Flink - we are happy that you want to help us improve Flink. To help the community review your contribution in the best possible way, please go through the checklist below, which will get the contribution into a shape in which it can be best reviewed.*
   
   *Please understand that we do not do this to make contributions to Flink a hassle. In order to uphold a high standard of quality for code contributions, while at the same time managing a large number of contributions, we need contributors to prepare the contributions well, and give reviewers enough contextual information for the review. Please also understand that contributions that do not follow this guide will take longer to review and thus typically be picked up with lower priority by the community.*
   
   ## Contribution Checklist
   
     - Make sure that the pull request corresponds to a [JIRA issue](https://issues.apache.org/jira/projects/FLINK/issues). Exceptions are made for typos in JavaDoc or documentation files, which need no JIRA issue.
     
     - Name the pull request in the form "[FLINK-XXXX] [component] Title of the pull request", where *FLINK-XXXX* should be replaced by the actual issue number. Skip *component* if you are unsure about which is the best component.
     Typo fixes that have no associated JIRA issue should be named following this pattern: `[hotfix] [docs] Fix typo in event time introduction` or `[hotfix] [javadocs] Expand JavaDoc for PuncuatedWatermarkGenerator`.
   
     - Fill out the template below to describe the changes contributed by the pull request. That will give reviewers the context they need to do the review.
     
     - Make sure that the change passes the automated tests, i.e., `mvn clean verify` passes. You can set up Azure Pipelines CI to do that following [this guide](https://cwiki.apache.org/confluence/display/FLINK/Azure+Pipelines#AzurePipelines-Tutorial:SettingupAzurePipelinesforaforkoftheFlinkrepository).
   
     - Each pull request should address only one issue, not mix up code from multiple issues.
     
     - Each commit in the pull request has a meaningful commit message (including the JIRA id)
   
     - Once all items of the checklist are addressed, remove the above text and this checklist, leaving only the filled out template below.
   
   
   **(The sections below can be removed for hotfixes of typos)**
   -->
   
   ## What is the purpose of the change
   
   *(For example: This pull request makes task deployment go through the blob server, rather than through RPC. That way we avoid re-transferring them on each deployment (during recovery).)*
   
   
   ## Brief change log
   
   *(for example:)*
     - *The TaskInfo is stored in the blob store on job creation time as a persistent artifact*
     - *Deployments RPC transmits only the blob storage reference*
     - *TaskManagers retrieve the TaskInfo from the blob cache*
   
   
   ## Verifying this change
   
   Please make sure both new and modified tests in this PR follow [the conventions for tests defined in our code quality guide](https://flink.apache.org/how-to-contribute/code-style-and-quality-common/#7-testing).
   
   *(Please pick either of the following options)*
   
   This change is a trivial rework / code cleanup without any test coverage.
   
   *(or)*
   
   This change is already covered by existing tests, such as *(please describe tests)*.
   
   *(or)*
   
   This change added tests and can be verified as follows:
   
   *(example:)*
     - *Added integration tests for end-to-end deployment with large payloads (100MB)*
     - *Extended integration test for recovery after master (JobManager) failure*
     - *Added test that validates that TaskInfo is transferred only once across recoveries*
     - *Manually verified the change by running a 4 node cluster with 2 JobManagers and 4 TaskManagers, a stateful streaming program, and killing one JobManager and two TaskManagers during the execution, verifying that recovery happens correctly.*
   
   ## Does this pull request potentially affect one of the following parts:
   
     - Dependencies (does it add or upgrade a dependency): (yes / no)
     - The public API, i.e., is any changed class annotated with `@Public(Evolving)`: (yes / no)
     - The serializers: (yes / no / don't know)
     - The runtime per-record code paths (performance sensitive): (yes / no / don't know)
     - Anything that affects deployment or recovery: JobManager (and its components), Checkpointing, Kubernetes/Yarn, ZooKeeper: (yes / no / don't know)
     - The S3 file system connector: (yes / no / don't know)
   
   ## Documentation
   
     - Does this pull request introduce a new feature? (yes / no)
     - If yes, how is the feature documented? (not applicable / docs / JavaDocs / not documented)
   
   ---
   
   ##### Was generative AI tooling used to co-author this PR?
   
   <!--
   If generative AI tooling has been used in the process of authoring this PR, please
   change the checkbox below to `[X]` and replace the placeholder in the "Generated-by"
   line with the tool name and version. Otherwise remove the "Generated-by" line.
   See the ASF Generative Tooling Guidance for details:
   https://www.apache.org/legal/generative-tooling.html
   
   You are responsible for the quality and correctness of every change in this PR
   regardless of the tooling used. Low-effort AI-generated PRs will be closed. See
   AGENTS.md for the full guidance.
   -->
   
   - [ ] Yes (please specify the tool below)
   
   Generated-by: [Tool Name and Version]
   


-- 
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: issues-unsubscribe@flink.apache.org

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


Re: [PR] [FLINK-40463][table] Widen `JSON_VALUE` and `JSON_QUERY` `RETURNING` type support [flink]

Posted by "raminqaf (via GitHub)" <gi...@apache.org>.
raminqaf merged PR #29506:
URL: https://github.com/apache/flink/pull/29506


-- 
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: issues-unsubscribe@flink.apache.org

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


Re: [PR] [FLINK-40463][table] Widen `JSON_VALUE` and `JSON_QUERY` `RETURNING` type support [flink]

Posted by "snuyanzin (via GitHub)" <gi...@apache.org>.
snuyanzin commented on code in PR #29506:
URL: https://github.com/apache/flink/pull/29506#discussion_r4307472924


##########
docs/data/sql_functions.yml:
##########
@@ -1086,8 +1086,18 @@ json:
 
       * `VARCHAR` / `STRING`
       * `BOOLEAN`
+      * `TINYINT`
+      * `SMALLINT`
       * `INTEGER`
+      * `BIGINT`
+      * `FLOAT`
       * `DOUBLE`
+      * `DECIMAL`
+
+      JSON string values are coerced to the requested numeric or boolean type (for example `"42"`
+      to a number, or `"true"`/`"t"`/`"yes"`/`"y"`/`"1"` to `TRUE`), matching `CAST` semantics.

Review Comment:
   dropped 
   >"matching CAST semantics"



-- 
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: issues-unsubscribe@flink.apache.org

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


Re: [PR] [FLINK-40463][table] Widen `JSON_VALUE` and `JSON_QUERY` `RETURNING` type support [flink]

Posted by "snuyanzin (via GitHub)" <gi...@apache.org>.
snuyanzin commented on code in PR #29506:
URL: https://github.com/apache/flink/pull/29506#discussion_r4307447313


##########
flink-table/flink-table-runtime/src/main/java/org/apache/flink/table/data/binary/BinaryStringDataUtil.java:
##########
@@ -155,15 +155,15 @@ public static BinaryStringData[] splitByWholeSeparatorPreserveAllTokens(
     }
 
     /** Parse a {@link StringData} to boolean. */
-    public static boolean toBoolean(BinaryStringData str) throws TableException {
+    public static boolean toBoolean(BinaryStringData str) {
         BinaryStringData lowerCase = str.toLowerCase();
         if (TRUE_STRINGS.contains(lowerCase)) {
             return true;
         }
         if (FALSE_STRINGS.contains(lowerCase)) {
             return false;
         }
-        throw new TableException("Cannot parse '" + str + "' as BOOLEAN.");
+        throw new TableRuntimeException("Cannot cast '" + str + "' as BOOLEAN.");

Review Comment:
   if you look at javadoc 
   https://github.com/apache/flink/blob/298a860634773a9efc7997adaeb3ff8eaf0f960a/flink-table/flink-table-common/src/main/java/org/apache/flink/table/api/TableException.java#L24-L27
   
   it is not the right place for `TableException`



-- 
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: issues-unsubscribe@flink.apache.org

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


Re: [PR] [FLINK-40463][table] Widen `JSON_VALUE` and `JSON_QUERY` `RETURNING` type support [flink]

Posted by "snuyanzin (via GitHub)" <gi...@apache.org>.
snuyanzin commented on code in PR #29506:
URL: https://github.com/apache/flink/pull/29506#discussion_r4307441000


##########
flink-table/flink-table-runtime/src/main/java/org/apache/flink/table/data/binary/BinaryStringDataUtil.java:
##########
@@ -155,15 +155,15 @@ public static BinaryStringData[] splitByWholeSeparatorPreserveAllTokens(
     }
 
     /** Parse a {@link StringData} to boolean. */
-    public static boolean toBoolean(BinaryStringData str) throws TableException {
+    public static boolean toBoolean(BinaryStringData str) {
         BinaryStringData lowerCase = str.toLowerCase();
         if (TRUE_STRINGS.contains(lowerCase)) {
             return true;
         }
         if (FALSE_STRINGS.contains(lowerCase)) {
             return false;
         }
-        throw new TableException("Cannot parse '" + str + "' as BOOLEAN.");
+        throw new TableRuntimeException("Cannot cast '" + str + "' as BOOLEAN.");

Review Comment:
   yes it was indended



-- 
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: issues-unsubscribe@flink.apache.org

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


Re: [PR] [FLINK-40463][table] Widen `JSON_VALUE` and `JSON_QUERY` `RETURNING` type support [flink]

Posted by "snuyanzin (via GitHub)" <gi...@apache.org>.
snuyanzin commented on PR #29506:
URL: https://github.com/apache/flink/pull/29506#issuecomment-6239751398

   @raminqaf , @cjohnson-confluent , @MartijnVisser , @davidradl since you participated in https://github.com/apache/flink/pull/29063
   can you please take a look here which is continuing that PR


-- 
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: issues-unsubscribe@flink.apache.org

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


Re: [PR] [FLINK-40463][table] Widen `JSON_VALUE` and `JSON_QUERY` `RETURNING` type support [flink]

Posted by "flinkbot (via GitHub)" <gi...@apache.org>.
flinkbot commented on PR #29506:
URL: https://github.com/apache/flink/pull/29506#issuecomment-6239815972

   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "c4df2d0a52cc951d37a65f9b9d33a303e1d1c5af",
       "status" : "UNKNOWN",
       "url" : "TBD",
       "triggerID" : "c4df2d0a52cc951d37a65f9b9d33a303e1d1c5af",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * c4df2d0a52cc951d37a65f9b9d33a303e1d1c5af UNKNOWN
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run azure` re-run the last Azure build
   </details>


-- 
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: issues-unsubscribe@flink.apache.org

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


Re: [PR] [FLINK-40463][table] Widen `JSON_VALUE` and `JSON_QUERY` `RETURNING` type support [flink]

Posted by "snuyanzin (via GitHub)" <gi...@apache.org>.
snuyanzin commented on code in PR #29506:
URL: https://github.com/apache/flink/pull/29506#discussion_r4307454970


##########
flink-table/flink-table-runtime/src/main/java/org/apache/flink/table/data/binary/BinaryStringDataUtil.java:
##########
@@ -155,15 +155,15 @@ public static BinaryStringData[] splitByWholeSeparatorPreserveAllTokens(
     }
 
     /** Parse a {@link StringData} to boolean. */
-    public static boolean toBoolean(BinaryStringData str) throws TableException {
+    public static boolean toBoolean(BinaryStringData str) {
         BinaryStringData lowerCase = str.toLowerCase();
         if (TRUE_STRINGS.contains(lowerCase)) {
             return true;
         }
         if (FALSE_STRINGS.contains(lowerCase)) {
             return false;
         }
-        throw new TableException("Cannot parse '" + str + "' as BOOLEAN.");
+        throw new TableRuntimeException("Cannot cast '" + str + "' as BOOLEAN.");

Review Comment:
   `TableRuntimeException` is a way more suitable here 
   https://github.com/apache/flink/blob/298a860634773a9efc7997adaeb3ff8eaf0f960a/flink-table/flink-table-common/src/main/java/org/apache/flink/table/api/TableRuntimeException.java#L24-L27



-- 
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: issues-unsubscribe@flink.apache.org

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


Re: [PR] [FLINK-40463][table] Widen `JSON_VALUE` and `JSON_QUERY` `RETURNING` type support [flink]

Posted by "MartijnVisser (via GitHub)" <gi...@apache.org>.
MartijnVisser commented on code in PR #29506:
URL: https://github.com/apache/flink/pull/29506#discussion_r4307433863


##########
flink-table/flink-table-planner/src/main/scala/org/apache/flink/table/planner/codegen/calls/JsonValueCallGen.scala:
##########
@@ -66,43 +67,81 @@ class JsonValueCallGen extends CallGenerator {
 
     val parsed = JsonParseReuse.parseSharedInput(ctx, operands)
 
-    generateCallWithStmtIfArgsNotNull(ctx, returnType, operands, resultNullable = true) {
-      argTerms =>
-        {
-          val emptyBehavior = getBehavior(operands, SqlJsonEmptyOrError.EMPTY)
-          val errorBehavior = getBehavior(operands, SqlJsonEmptyOrError.ERROR)
+    val generated =
+      generateCallWithStmtIfArgsNotNull(ctx, returnType, operands, resultNullable = true) {
+        argTerms =>
+          {
+            val emptyBehavior = getBehavior(operands, SqlJsonEmptyOrError.EMPTY)
+            val errorBehavior = getBehavior(operands, SqlJsonEmptyOrError.ERROR)
 
-          val terms = Seq(
-            parsed.resultTerm,
-            s"${argTerms(1)}.toString()",
-            qualifyEnum(emptyBehavior._1),
-            emptyBehavior._2,
-            qualifyEnum(errorBehavior._1),
-            errorBehavior._2
-          )
+            val terms = Seq(
+              parsed.resultTerm,
+              s"${argTerms(1)}.toString()",
+              qualifyEnum(emptyBehavior._1),
+              emptyBehavior._2,
+              qualifyEnum(errorBehavior._1),
+              errorBehavior._2
+            )
 
-          val rawResultTerm = CodeGenUtils.newName(ctx, "rawResult")
-          val call = s"""
-                        |Object $rawResultTerm =
-                        |    ${qualifyMethod(BuiltInMethods.JSON_VALUE)}(${terms
-                         .mkString(", ")});
+            val rawResultTerm = CodeGenUtils.newName(ctx, "rawResult")
+            val baseCall = s"""
+                              |Object $rawResultTerm =
+                              |    ${qualifyMethod(BuiltInMethods.JSON_VALUE)}(${terms
+                               .mkString(", ")});
            """.stripMargin
 
-          val convertedResult = returnType.getTypeRoot match {
-            case LogicalTypeRoot.VARCHAR =>
-              s"$BINARY_STRING.fromString(java.lang.String.valueOf($rawResultTerm))"
-            case LogicalTypeRoot.BOOLEAN => s"(java.lang.Boolean) $rawResultTerm"
-            case LogicalTypeRoot.INTEGER => s"(java.lang.Integer) $rawResultTerm"
-            case LogicalTypeRoot.DOUBLE => s"((java.math.BigDecimal) $rawResultTerm).doubleValue()"
-            case _ =>
-              throw new CodeGenException(
-                s"Unsupported type '$returnType' "
-                  + "for RETURNING in JSON_VALUE().")
+            returnType.getTypeRoot match {
+              case LogicalTypeRoot.VARCHAR =>
+                val result =
+                  s"($rawResultTerm == null) ? null : " +
+                    s"($BINARY_STRING.fromString(java.lang.String.valueOf($rawResultTerm)))"
+                (baseCall, result)
+              case typeRoot if !SqlJsonUtils.isSupportedJsonReturningType(typeRoot) =>
+                throw new CodeGenException(
+                  s"Unsupported type '$returnType' for RETURNING in JSON_VALUE().")
+              case _ =>
+                val jsonUtils =
+                  classOf[SqlJsonUtils].getName
+                val typeRootEnum =
+                  s"${classOf[LogicalTypeRoot].getName}.${returnType.getTypeRoot.name()}"
+                val (precisionStr, scaleStr) = returnType.getTypeRoot match {
+                  case LogicalTypeRoot.DECIMAL =>
+                    val dt = returnType.asInstanceOf[DecimalType]
+                    (dt.getPrecision.toString, dt.getScale.toString)
+                  case _ => ("0", "0")
+                }
+                val errorBehaviorEnum =
+                  qualifyEnum(errorBehavior._1.asInstanceOf[JsonValueOnEmptyOrError])
+                val defaultExpr =
+                  if (errorBehavior._2 != null) errorBehavior._2 else "null"
+
+                val boxedType = CodeGenUtils.boxedTypeTermForType(returnType)
+                val convertedTerm = CodeGenUtils.newName(ctx, "converted")
+                val call = baseCall +
+                  s"""
+                     |$boxedType $convertedTerm = ($boxedType) $jsonUtils.convertJsonScalar(
+                     |    $rawResultTerm, $typeRootEnum,
+                     |    $precisionStr, $scaleStr,
+                     |    $errorBehaviorEnum, $defaultExpr);
+                 """.stripMargin
+                (call, s"$convertedTerm")
+            }
           }
+      }
 
-          val result = s"($rawResultTerm == null) ? null : ($convertedResult)"
-          (call, result)
-        }
+    if (isPrimitiveNullable(returnType)) {

Review Comment:
   The boxed result bug is also on 1.20 and 2.x (`=` on two `RETURNING INT` values of 1000 is FALSE). Can this be its own commit and ticket for the backports?



##########
flink-table/flink-table-runtime/src/main/java/org/apache/flink/table/data/binary/BinaryStringDataUtil.java:
##########
@@ -155,15 +155,15 @@ public static BinaryStringData[] splitByWholeSeparatorPreserveAllTokens(
     }
 
     /** Parse a {@link StringData} to boolean. */
-    public static boolean toBoolean(BinaryStringData str) throws TableException {
+    public static boolean toBoolean(BinaryStringData str) {
         BinaryStringData lowerCase = str.toLowerCase();
         if (TRUE_STRINGS.contains(lowerCase)) {
             return true;
         }
         if (FALSE_STRINGS.contains(lowerCase)) {
             return false;
         }
-        throw new TableException("Cannot parse '" + str + "' as BOOLEAN.");
+        throw new TableRuntimeException("Cannot cast '" + str + "' as BOOLEAN.");

Review Comment:
   I think this changes the exception and message of every `CAST(... AS BOOLEAN)` on a string, not only the JSON path. Is that intended?



##########
docs/data/sql_functions.yml:
##########
@@ -1086,8 +1086,18 @@ json:
 
       * `VARCHAR` / `STRING`
       * `BOOLEAN`
+      * `TINYINT`
+      * `SMALLINT`
       * `INTEGER`
+      * `BIGINT`
+      * `FLOAT`
       * `DOUBLE`
+      * `DECIMAL`
+
+      JSON string values are coerced to the requested numeric or boolean type (for example `"42"`
+      to a number, or `"true"`/`"t"`/`"yes"`/`"y"`/`"1"` to `TRUE`), matching `CAST` semantics.

Review Comment:
   `"1e2"` gives 100 for INTEGER and `" true "` gives TRUE, while `CAST` fails on both, and `"NaN"` is the other way around. I'd drop "matching `CAST` semantics" or align them.



-- 
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: issues-unsubscribe@flink.apache.org

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


Re: [PR] [FLINK-40463][table] Widen `JSON_VALUE` and `JSON_QUERY` `RETURNING` type support [flink]

Posted by "snuyanzin (via GitHub)" <gi...@apache.org>.
snuyanzin commented on code in PR #29506:
URL: https://github.com/apache/flink/pull/29506#discussion_r4307441000


##########
flink-table/flink-table-runtime/src/main/java/org/apache/flink/table/data/binary/BinaryStringDataUtil.java:
##########
@@ -155,15 +155,15 @@ public static BinaryStringData[] splitByWholeSeparatorPreserveAllTokens(
     }
 
     /** Parse a {@link StringData} to boolean. */
-    public static boolean toBoolean(BinaryStringData str) throws TableException {
+    public static boolean toBoolean(BinaryStringData str) {
         BinaryStringData lowerCase = str.toLowerCase();
         if (TRUE_STRINGS.contains(lowerCase)) {
             return true;
         }
         if (FALSE_STRINGS.contains(lowerCase)) {
             return false;
         }
-        throw new TableException("Cannot parse '" + str + "' as BOOLEAN.");
+        throw new TableRuntimeException("Cannot cast '" + str + "' as BOOLEAN.");

Review Comment:
   yes it was intended



-- 
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: issues-unsubscribe@flink.apache.org

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