This is an automated email from the ASF dual-hosted git repository. snuyanzin pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/flink.git
commit c43754cdc4f7f70b64f79bc64b42b03b0359fc70 Author: Ramin Gharib <[email protected]> AuthorDate: Thu Jul 23 12:59:58 2026 +0200 [FLINK-40217][table] Add `PARSE_JSON` and `TRY_PARSE_JSON` IT cases Cover the end-to-end SQL wiring for PARSE_JSON and TRY_PARSE_JSON: a JSON_STRING round trip, NULL handling, and the out-of-range number behavior. An overflowing number such as 1e400 makes PARSE_JSON fail with a TableRuntimeException, while TRY_PARSE_JSON returns NULL. The parsing semantics themselves stay covered by BinaryVariantInternalBuilderTest. This closes #28808. --- .../planner/functions/JsonFunctionsITCase.java | 40 ++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/functions/JsonFunctionsITCase.java b/flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/functions/JsonFunctionsITCase.java index 40defdf485d..fb18458fec6 100644 --- a/flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/functions/JsonFunctionsITCase.java +++ b/flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/functions/JsonFunctionsITCase.java @@ -87,6 +87,7 @@ class JsonFunctionsITCase extends BuiltInFunctionTestBase { testCases.addAll(isJsonSpec()); testCases.addAll(jsonQuerySpec()); testCases.addAll(jsonStringSpec()); + testCases.addAll(parseJsonSpec()); testCases.addAll(jsonObjectSpec()); testCases.addAll(jsonSpec()); testCases.addAll(jsonArraySpec()); @@ -760,6 +761,45 @@ class JsonFunctionsITCase extends BuiltInFunctionTestBase { STRING().notNull())); } + private static List<TestSetSpec> parseJsonSpec() { + // The bulk of parsing behavior is covered by BinaryVariantInternalBuilderTest. + return List.of( + TestSetSpec.forFunction(BuiltInFunctionDefinitions.PARSE_JSON) + .onFieldsWithData("{\"a\":1,\"b\":[2,3]}", "1e400") + .andDataTypes(STRING().notNull(), STRING().notNull()) + .testResult( + jsonString(call("PARSE_JSON", $("f0"))), + "JSON_STRING(PARSE_JSON(f0))", + "{\"a\":1,\"b\":[2,3]}", + STRING().notNull()) + .testResult( + jsonString(call("PARSE_JSON", nullOf(STRING()))), + "JSON_STRING(PARSE_JSON(CAST(NULL AS STRING)))", + null, + STRING().nullable()) + .testSqlRuntimeError( + "PARSE_JSON(f1)", + TableRuntimeException.class, + "Failed to parse json string") + .testTableApiRuntimeError( + call("PARSE_JSON", $("f1")), + TableRuntimeException.class, + "Failed to parse json string"), + TestSetSpec.forFunction(BuiltInFunctionDefinitions.TRY_PARSE_JSON) + .onFieldsWithData("{\"a\":1}", "1e400") + .andDataTypes(STRING().notNull(), STRING().notNull()) + .testResult( + jsonString(call("TRY_PARSE_JSON", $("f0"))), + "JSON_STRING(TRY_PARSE_JSON(f0))", + "{\"a\":1}", + STRING()) + .testResult( + jsonString(call("TRY_PARSE_JSON", $("f1"))), + "JSON_STRING(TRY_PARSE_JSON(f1))", + null, + STRING())); + } + private static List<TestSetSpec> jsonSpec() { return List.of( TestSetSpec.forFunction(BuiltInFunctionDefinitions.JSON_OBJECT)
