From 64bff89f2424784df861104e0a604cf158fe51e5 Mon Sep 17 00:00:00 2001 From: Gustavo de Morais Date: Thu, 30 Jan 2025 17:17:05 +0100 Subject: [PATCH] [FLINK-37175][docs] Complement documentation for json function --- docs/data/sql_functions.yml | 4 ++-- flink-python/pyflink/table/expressions.py | 3 ++- .../main/java/org/apache/flink/table/api/Expressions.java | 5 +++-- .../flink/table/planner/functions/JsonFunctionsITCase.java | 1 - 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/docs/data/sql_functions.yml b/docs/data/sql_functions.yml index 8a6ccafd0e8a7..99e5de30d9f07 100644 --- a/docs/data/sql_functions.yml +++ b/docs/data/sql_functions.yml @@ -1086,8 +1086,8 @@ json: This function can currently only be used within the `JSON_OBJECT` function. It allows passing pre-formatted JSON strings that will be inserted directly into the resulting JSON structure rather than being escaped as a string value. This allows storing nested JSON structures in a - JSON_OBJECT without processing them as strings. If the value is NULL or empty, the function - returns NULL. + JSON_OBJECT without processing them as strings, which is often useful when ingesting already + formatted json data. If the value is NULL or empty, the function returns NULL. ```sql -- {"K":{"K2":42}} diff --git a/flink-python/pyflink/table/expressions.py b/flink-python/pyflink/table/expressions.py index 19935458a0dff..3c531289248fb 100644 --- a/flink-python/pyflink/table/expressions.py +++ b/flink-python/pyflink/table/expressions.py @@ -778,7 +778,8 @@ def json(value) -> Expression: This function can currently only be used within the `JSON_OBJECT` function. It allows passing pre-formatted JSON strings that will be inserted directly into the resulting JSON structure rather than being escaped as a string value. This allows storing nested JSON structures in a - JSON_OBJECT without processing them as strings. If the value is NULL or empty, the function + JSON_OBJECT without processing them as strings, which is often useful when ingesting already + formatted json data. If the value is NULL or empty, the function returns NULL. Examples: diff --git a/flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/api/Expressions.java b/flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/api/Expressions.java index 87d7494030ea1..c6febab9d13c7 100644 --- a/flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/api/Expressions.java +++ b/flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/api/Expressions.java @@ -885,8 +885,9 @@ public static ApiExpression jsonObject(JsonOnNull onNull, Object... keyValues) { *

This function can currently only be used within the {@link #jsonObject(JsonOnNull, * Object...)} function. It allows passing pre-formatted JSON strings that will be inserted * directly into the resulting JSON structure rather than being escaped as a string value. This - * allows storing nested JSON structures in a JSON_OBJECT without processing them as strings. If - * the value is null or empty, the function returns {@code null}. + * allows storing nested JSON structures in a JSON_OBJECT without processing them as strings, + * which is often useful when ingesting already formatted json data. If the value is null or + * empty, the function returns {@code null}. * *

Examples: * 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 f7d85e2c44e5f..d4b3581f7cca4 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 @@ -693,7 +693,6 @@ private static List jsonStringSpec() { STRING().notNull())); } - // Test with alias?? using str$1 private static List jsonSpec() { return Arrays.asList( TestSetSpec.forFunction(BuiltInFunctionDefinitions.JSON_OBJECT)