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


##########
flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/functions/JsonFunctionsITCase.java:
##########
@@ -201,6 +201,13 @@ private static TestSetSpec jsonLengthSpec() {
                 .testSqlResult("JSON_LENGTH(f0, '$.metadata.tags[*]')", null, 
INT().nullable())
                 .testSqlResult("JSON_LENGTH(f0, '$.metadata.tags')", 3, 
INT().nullable())
 
+                // JSON_EXISTS sees a multi-match wildcard as present while 
JSON_LENGTH returns NULL
+                .testSqlResult(
+                        "JSON_EXISTS(f0, 'lax $.metadata.tags[*]') "
+                                + "AND JSON_LENGTH(f0, '$.metadata.tags[*]') 
IS NULL",

Review Comment:
   Simplify test as here 
https://github.com/apache/flink/pull/28688/changes/eb2c40daa07a0b998dad9b098b04758aefb99826#r3614478354



##########
docs/data/sql_functions.yml:
##########
@@ -1264,25 +1264,9 @@ json:
         -- JSON_EXISTS separates an absent path from a present one
         SELECT JSON_EXISTS(json_doc, '$.items[*]'), JSON_LENGTH(json_doc, 
'$.items[*]');
       
-        -- To count multiple wildcard matches, wrap them into an array first
-        SELECT JSON_LENGTH(JSON_QUERY(json_doc, '$.items[*]' WITH ARRAY 
WRAPPER));
-      
-      
-        eg.
-        consider this JSON_LENGTH query JSON_LENGTH('{"1": "hello", "2": "BAD 
SYNTAX ->"', '$.2'), 
-        this string will return NULL, however as a user, to understand why we 
must use the parameter,
-        "IS JSON" and function "JSON_EXISTS()".
-      
-        In order to understand why JSON_LENGTH gave a NULL output you can look 
at the following example:
-          
-          -- '{"1": "hello", "2": "BAD SYNTAX ->"' IS JSON 
-          This will return FALSE if we have a malformed JSON input.
-      
-          -- JSON_EXISTS('{"1": "hello", "2": "BAD SYNTAX ->"', '$.2')
-          This will return FALSE if the path given is an invalid path in our 
given JSON string or 
-          invalid JSON, so you must do "IS JSON" first to get a definative 
answer. However if this 
-          returns TRUE and the JSON input is validated already, it means that 
the path describes
-          two or more paths (ie. using the wildcard operator), which 
JSON_LENGTH doesnt support.
+        -- JSON_EXISTS separates a multi-match path from a present one 
+           (returns True if multimatch is present given f0 is a valid json 
string otherwise returns False)
+        SELECT JSON_EXISTS(f0, 'lax $.metadata.tags[*]') AND JSON_LENGTH(f0, 
'$.metadata.tags[*]') IS NULL;

Review Comment:
   Why do you think this is worth being in the docs? I think we can just remove 
it. As I mentioned, I think we're giving the multi-match wildcard case more 
effort than it deserves. It's a very rare case and users should write the 
wildcard in a way that it matches paths individually, so I don't think we need 
to give specific instructions to this on the docs



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