jeyhunkarimov commented on PR #24156:
URL: https://github.com/apache/flink/pull/24156#issuecomment-1938706008

   > > Is it mainly because of the definition of JSON_QUOTE that does not 
require its input to be valid JSON, and JSON_UNQOTE that require its input to 
be a valid JSON.
   > 
   > I'm not sure that this is the only reason
   > 
   > there is a more simple case, for instance `"key"` is a valid JSON and 
`json_quote` produces also a valid json `"\"key\""` however the combination 
also seems not working
   > 
   > ```sql
   > SELECT json_unquote(json_quote('"key"'));
   > ```
   > 
   > and continues producing `"\"key\""`
   
   Let me paste the definitions here:
   
   `json_quote`: Quotes a string as a JSON value by wrapping it with double 
quote characters, escaping interior quote and other characters, and returning 
the result as a utf8mb4 string. If the argument is NULL, the function returns 
NULL.
   
   j`son_unquote`: Unquotes JSON value and returns the result as a utf8mb4 
string. If the argument is NULL, returns NULL. If the value starts and ends 
with double quotes but is not a valid JSON string literal, the value is passed 
through unmodified.
   
   So, from this definition, `json_quote` does not enforce the input to be a 
valid json, but `json_unquote` does. 
   
   So, in your example, `json_quote('"key"')`  produces `"\"key\""` and 
`json_unqote("\"key\"")` will produce the same `("\"key\"")` since the input 
`("\"key\"")` is not a valid json. 
   
   Instead this works: `testSqlApi("JSON_UNQUOTE(JSON_QUOTE('[1,2,3]'))", 
"[1,2,3]")` since the input of the json_unqote is a valid json.
   
   These rules I derived from the definition I pasted above. Maybe I am missing 
something. 
   


-- 
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: issues-unsubscr...@flink.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to