gustavodemorais commented on code in PR #28688:
URL: https://github.com/apache/flink/pull/28688#discussion_r3615289810
##########
flink-table/flink-table-runtime/src/main/java/org/apache/flink/table/runtime/functions/SqlJsonUtils.java:
##########
@@ -374,6 +376,78 @@ private static Object errorResultForJsonQuery(
}
}
+ /** Accepts a pre-parsed context from {@link #jsonParse}. */
+ public static Integer jsonLength(final JsonValueContext parsedInput) {
+ if (parsedInput.hasException()) {
+ return null;
+ }
+ // Whole document: a top-level JSON null literal counts as a scalar
(length 1).
+ return jsonLengthValue(parsedInput.obj);
+ }
+
+ /** Accepts a pre-parsed context from {@link #jsonParse}. */
+ public static Integer jsonLength(final JsonValueContext parsedInput, final
String pathSpec) {
+ if (parsedInput.hasException()) {
+ // invalid input JSON
+ return null;
+ }
+ final Matcher matcher = JSON_PATH_BASE.matcher(pathSpec);
+ if (matcher.matches()) {
+ throw new TableRuntimeException(
+ "JSON_LENGTH does not support lax/strict path modes. "
+ + "Please refer to the documentation for the
supported path format.");
Review Comment:
Let's make this error message a bit more useful
```suggestion
throw new TableRuntimeException(
String.format(
"JSON_LENGTH does not support the 'lax'/'strict' path mode
prefix (got: '%s'). "
+ "Use a plain path such as '$.a.b'. To check path
existence or handle "
+ "invalid input, use JSON_EXISTS or IS JSON.",
pathSpec));
```
--
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]