snuyanzin commented on code in PR #28688:
URL: https://github.com/apache/flink/pull/28688#discussion_r3721934522


##########
flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/functions/JsonFunctionsITCase.java:
##########
@@ -98,6 +99,128 @@ 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())
+
+                // whole document is a JSON null literal: the root path 
matches it as a scalar,
+                // anything else does not exist
+                .testSqlResult("JSON_LENGTH(f4, '$')", 1, INT().nullable())
+                .testSqlResult("JSON_LENGTH(f4, '$.a')", null, 
INT().nullable())
+                .testSqlResult("JSON_LENGTH(f4, '$[0]')", null, 
INT().nullable())

Review Comment:
   here and below
   can we replace `testSqlResult` with `testResult`
   
   the reason is that `testSqlResult` tests only SQL while `testResult` tests 
all possible apis (SQL, table api, ...)



-- 
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]

Reply via email to