snuyanzin commented on code in PR #28688:
URL: https://github.com/apache/flink/pull/28688#discussion_r3619762403
##########
flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/functions/JsonFunctionsITCase.java:
##########
@@ -97,6 +98,110 @@ Stream<TestSetSpec> getTestSetSpecs() {
return testCases.stream();
}
+ private static TestSetSpec jsonLengthSpec() {
+ final String jsonValue = getJsonFromResource("/json/json-exists.json");
+
+ return TestSetSpec.forFunction(BuiltInFunctionDefinitions.JSON_LENGTH)
+ .onFieldsWithData(
+ jsonValue,
+ "{\"a\":1,\"b\":2}",
+ "[1,2,3]",
+ "\"abc\"",
+ "null",
+ "{",
+ ((String) null),
+ "$",
+ "{\"a\":[true, false, null]}",
+ "{}",
+ "[]")
+ .andDataTypes(
+ STRING(), STRING(), STRING(), STRING(), STRING(),
STRING(), STRING(),
+ STRING(), STRING(), STRING(), STRING())
+ // path exists but resolves to a JSON null literal -> scalar,
length 1
+ .testSqlResult("JSON_LENGTH(f8, '$.a[2]')", 1,
INT().nullable())
+ // missing paths on the same document -> NULL
+ .testSqlResult("JSON_LENGTH(f8, '$.a[9]')", null,
INT().nullable())
+ .testSqlResult("JSON_LENGTH(f8, '$.b')", null,
INT().nullable())
+
+ // SQL NULL input
+ .testSqlResult("JSON_LENGTH(f6)", null, INT().nullable())
+
+ // whole-document length from the existing resource:
+ .testSqlResult("JSON_LENGTH(f0)", 3, INT().nullable())
+
+ // basic shapes
+ .testSqlResult("JSON_LENGTH(f1)", 2, INT().nullable())
+ .testSqlResult("JSON_LENGTH(f2)", 3, INT().nullable())
+ .testSqlResult("JSON_LENGTH(f3)", 1, INT().nullable())
+
+ // empty containers -> 0
+ .testSqlResult("JSON_LENGTH(f9)", 0, INT().nullable())
+ .testSqlResult("JSON_LENGTH(f10)", 0, INT().nullable())
+ .testSqlResult("JSON_LENGTH(f9, '$')", 0, INT().nullable())
+ .testSqlResult("JSON_LENGTH(f10, '$')", 0, INT().nullable())
+ .testSqlResult("JSON_LENGTH(f4)", 1, INT().nullable())
+
+ // (valid) paths
+ .testSqlResult("JSON_LENGTH(f0, '$')", 3, INT().nullable())
+ .testSqlResult("JSON_LENGTH(f0, '$.type')", 1,
INT().nullable())
+ .testSqlResult("JSON_LENGTH(f0, '$.author')", 2,
INT().nullable())
+ .testSqlResult("JSON_LENGTH(f0, '$.author.address')", 2,
INT().nullable())
+ .testSqlResult("JSON_LENGTH(f0, '$.metadata.tags')", 3,
INT().nullable())
+ .testSqlResult("JSON_LENGTH(f0, '$.metadata.references')", 1,
INT().nullable())
+ .testSqlResult("JSON_LENGTH(f0, '$.metadata.references[0]')",
2, INT().nullable())
+ .testSqlResult("JSON_LENGTH(f0,
'$.metadata.references[0].url')", 1, INT().nullable())
+ // (invalid) path
+ .testSqlResult("JSON_LENGTH(f0, '$.missing')", null,
INT().nullable())
+ .testSqlResult("JSON_LENGTH(f7)", null, INT().nullable())
+
+ // invalid JSON -> NULL
+ .testSqlResult("JSON_LENGTH(f5)", null, INT().nullable())
+
+ // literal (NOT NULL) arguments must still yield a nullable
result,
Review Comment:
should it end with dot rather than comma?
--
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]