Airblader commented on a change in pull request #16776:
URL: https://github.com/apache/flink/pull/16776#discussion_r688547801
##########
File path:
flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/api/internal/BaseExpressions.java
##########
@@ -1323,4 +1327,211 @@ public OutType jsonExists(String path,
JsonExistsOnError onError) {
public OutType jsonExists(String path) {
return toApiSpecificExpression(unresolvedCall(JSON_EXISTS, toExpr(),
valueLiteral(path)));
}
+
+ /**
+ * Extracts a scalar from a JSON string.
+ *
+ * <p>This method searches a JSON string for a given path expression and
returns the value if
+ * the value at that path is scalar. Non-scalar values cannot be returned.
By default, the value
+ * is returned as {@link DataTypes#STRING()}. Using {@param returningType}
a different type can
+ * be chosen, with the following types being supported:
+ *
+ * <ul>
+ * <li>{@link LogicalTypeRoot#VARCHAR}
+ * <li>{@link LogicalTypeRoot#BOOLEAN}
+ * <li>{@link LogicalTypeRoot#INTEGER}
+ * <li>{@link LogicalTypeRoot#DOUBLE}
+ * </ul>
+ *
+ * <p>For empty path expressions or errors a behavior can be defined to
either return {@code
+ * null}, raise an error or return a defined default value instead.
+ *
+ * <p>Examples:
+ *
+ * <pre>{@code
+ * // STRING: "true"
+ * lit("{\"a\": true}").jsonValue("$.a")
+ *
+ * // BOOLEAN: true
+ * lit("{\"a\": true}").jsonValue("$.a", DataTypes.BOOLEAN())
+ *
+ * // BOOLEAN: "false"
+ * lit("{\"a\": true}").jsonValue("lax $.b",
+ * JsonValueOnEmptyOrError.DEFAULT, false,
JsonValueOnEmptyOrError.NULL, null)
Review comment:
That's true, but I think it's worth having the extra constant here just
to make it easier for users to align Table API with SQL.
##########
File path:
flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/api/internal/BaseExpressions.java
##########
@@ -1323,4 +1327,211 @@ public OutType jsonExists(String path,
JsonExistsOnError onError) {
public OutType jsonExists(String path) {
return toApiSpecificExpression(unresolvedCall(JSON_EXISTS, toExpr(),
valueLiteral(path)));
}
+
+ /**
+ * Extracts a scalar from a JSON string.
+ *
+ * <p>This method searches a JSON string for a given path expression and
returns the value if
+ * the value at that path is scalar. Non-scalar values cannot be returned.
By default, the value
+ * is returned as {@link DataTypes#STRING()}. Using {@param returningType}
a different type can
+ * be chosen, with the following types being supported:
+ *
+ * <ul>
+ * <li>{@link LogicalTypeRoot#VARCHAR}
+ * <li>{@link LogicalTypeRoot#BOOLEAN}
+ * <li>{@link LogicalTypeRoot#INTEGER}
+ * <li>{@link LogicalTypeRoot#DOUBLE}
+ * </ul>
+ *
+ * <p>For empty path expressions or errors a behavior can be defined to
either return {@code
+ * null}, raise an error or return a defined default value instead.
+ *
+ * <p>Examples:
+ *
+ * <pre>{@code
+ * // STRING: "true"
+ * lit("{\"a\": true}").jsonValue("$.a")
+ *
+ * // BOOLEAN: true
+ * lit("{\"a\": true}").jsonValue("$.a", DataTypes.BOOLEAN())
+ *
+ * // BOOLEAN: "false"
+ * lit("{\"a\": true}").jsonValue("lax $.b",
+ * JsonValueOnEmptyOrError.DEFAULT, false,
JsonValueOnEmptyOrError.NULL, null)
Review comment:
That's true, but I think it's worth having the extra constant here just
to make it easier for users to align Table API with SQL. It really doesn't cost
us anything.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]