Airblader commented on a change in pull request #17186:
URL: https://github.com/apache/flink/pull/17186#discussion_r704102162



##########
File path: 
flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/api/Expressions.java
##########
@@ -562,6 +563,43 @@ public static ApiExpression withoutColumns(Object head, 
Object... tail) {
         return 
apiCallAtLeastOneArgument(BuiltInFunctionDefinitions.WITHOUT_COLUMNS, head, 
tail);
     }
 
+    /**
+     * Builds a JSON string from a list of key-value pairs.
+     *
+     * <p>{@param keyValues} is an even-numbered list of alternating key/value 
pairs. Note that keys
+     * must be non-{@code NULL} string literals, while values may be arbitrary 
expressions.
+     *
+     * <p>The {@link JsonOnNull onNull} behavior defines how to treat {@code 
NULL} values.
+     *
+     * <p>Note that this function only returns a JSON string, not an actual 
JSON type. Not all JSON
+     * can currently be represented in Flink's type system.
+     *
+     * <p>Examples:
+     *
+     * <pre>{@code
+     * // "{}"
+     * jsonObject(JsonOnNull.NULL)
+     * // "{\"K1\":\"V1\",\"K2\":\"V2\"}"
+     * jsonObject(JsonOnNull.NULL, "K1", "V1", "K2", "V2")
+     *
+     * // Expressions as values
+     * jsonObject(JsonOnNull.NULL, "orderNo", $("orderId"))
+     *
+     * // ON NULL
+     * jsonObject(JsonOnNull.NULL, "K1", nullOf(DataTypes.STRING()))   // 
"{\"K1\":null}"
+     * jsonObject(JsonOnNull.ABSENT, "K1", nullOf(DataTypes.STRING())) // "{}"
+     *
+     * // "{\"K1\":\"{\\\"K2\\\":\\\"V\\\"}\"}"
+     * jsonObject(JsonOnNull.NULL, "K1", jsonObject(JsonOnNull.NULL, "K2", 
"V"))
+     * }</pre>
+     */
+    public static ApiExpression jsonObject(JsonOnNull onNull, Object... 
keyValues) {

Review comment:
       Yes, that would be possible; but we'd basically be rolling our own map 
implementation / map utils. I don't think this function is big enough to 
warrant having APIs for that as well (and they're kind of un-Flink-y APIs).




-- 
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-unsubscr...@flink.apache.org

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


Reply via email to