From 391fb06a102b2fc8a4a7aa0e83fabd10965feaea Mon Sep 17 00:00:00 2001 From: Ramin Gharib Date: Mon, 7 Sep 2026 11:37:13 +0200 Subject: [PATCH] [hotfix][table] Fix tryParseJson() docs to say NULL instead of throws an error FLINK-40545 copy-pasted the parseJson() wording into tryParseJson(), so the allowDuplicateKeys=false branch claimed the TRY variant throws an error. TRY_PARSE_JSON catches all parse errors, including duplicate-key errors, and returns NULL instead of throwing, so the Java Javadoc, Python docstring, and sql_functions.yml description are corrected to match. Also trims a trailing-whitespace line in sql_functions.yml picked up in the same block. --- docs/data/sql_functions.yml | 2 +- flink-python/pyflink/table/expression.py | 4 ++-- .../org/apache/flink/table/api/internal/BaseExpressions.java | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/data/sql_functions.yml b/docs/data/sql_functions.yml index 8dc465da407a3..d25223c5f20ae 100644 --- a/docs/data/sql_functions.yml +++ b/docs/data/sql_functions.yml @@ -1352,7 +1352,7 @@ variant: - sql: TRY_PARSE_JSON(json_string[, allow_duplicate_keys]) table: STRING.tryParseJson([allowDuplicateKeys]) description: | - Try to parse a JSON string into a Variant if possible. If the JSON string is invalid, return + Try to parse a JSON string into a Variant if possible. If the JSON string is invalid, return NULL. To throw an error instead of returning NULL, use the `PARSE_JSON` function. If there are duplicate keys in the input JSON string, when `allowDuplicateKeys` is true, the diff --git a/flink-python/pyflink/table/expression.py b/flink-python/pyflink/table/expression.py index be21605124a3a..5212de11f862c 100644 --- a/flink-python/pyflink/table/expression.py +++ b/flink-python/pyflink/table/expression.py @@ -2303,8 +2303,8 @@ def try_parse_json(self, allow_duplicate_keys=None) -> 'Expression': None is returned. To throw an error instead, use :func:`~Expression.parse_json`. If there are duplicate keys in the input, allow_duplicate_keys controls whether the - parser keeps the last occurrence of each duplicated key (True) or throws an error - (False). The default value of allow_duplicate_keys is False. + parser keeps the last occurrence of each duplicated key (True) or returns + None (False). The default value of allow_duplicate_keys is False. """ if allow_duplicate_keys is None: return _unary_op("tryParseJson")(self) diff --git a/flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/api/internal/BaseExpressions.java b/flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/api/internal/BaseExpressions.java index 536105ea6bce6..3aa6923461e56 100644 --- a/flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/api/internal/BaseExpressions.java +++ b/flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/api/internal/BaseExpressions.java @@ -1411,8 +1411,8 @@ public OutType tryParseJson() { * #parseJson(boolean)}. * *

If there are duplicate keys in the input, {@code allowDuplicateKeys} controls whether the - * parser keeps the last occurrence of each duplicated key ({@code true}) or throws an error - * ({@code false}). + * parser keeps the last occurrence of each duplicated key ({@code true}) or returns {@code + * NULL} ({@code false}). */ public OutType tryParseJson(boolean allowDuplicateKeys) { return toApiSpecificExpression(