snuyanzin commented on code in PR #24156:
URL: https://github.com/apache/flink/pull/24156#discussion_r1486024115
##########
docs/data/sql_functions.yml:
##########
@@ -377,6 +377,12 @@ string:
- sql: SUBSTR(string, integer1[, integer2])
table: STRING.substr(INTEGER1[, INTEGER2])
description: Returns a substring of string starting from position integer1
with length integer2 (to the end by default).
+ - sql: JSON_QUOTE(string)
+ table: STRING.JsonQuote()
+ description: 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.
Review Comment:
What is `other characters` here? If I understand correctly it was somehow
based on MySQL's definition.
The main issue with MySQL's version is that it makes users confused. An
example: a couple of iterations in the past we realised that MySQL doesn't pay
enough attention to all characters mentioned as characters for escape in json
spec e.g. `/`. Thus I have no idea how a user just after reading MySQL
definition should realise that MySQL doesn't follow the expected way (from spec
point of view) and instead it folows its own way.
So I would suggest to explicitely refer to JSON spec to highlight what
symbols are going to be escaped
##########
flink-python/docs/reference/pyflink.table/expressions.rst:
##########
@@ -195,6 +195,8 @@ string functions
Expression.reverse
Expression.split_index
Expression.str_to_map
+ Expression.json_quote
+ Expression.json_unquote
Review Comment:
Shouldn't we put these functions here and in all other python related files
together with other json functions?
##########
docs/data/sql_functions.yml:
##########
@@ -377,6 +377,12 @@ string:
- sql: SUBSTR(string, integer1[, integer2])
table: STRING.substr(INTEGER1[, INTEGER2])
description: Returns a substring of string starting from position integer1
with length integer2 (to the end by default).
+ - sql: JSON_QUOTE(string)
+ table: STRING.JsonQuote()
+ description: 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.
+ - sql: JSON_UNQUOTE(string)
+ table: STRING.JsonUnquote()
+ description: 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.
Review Comment:
IMHO That's looks like a questionable behaviour I would suggest to discuss
it first in jira.
It could be quite obvious to see whether it ws unquoted or or just passed
through as unmodified however it could be very tricky for complex strings
Thoughts out loud: By the was we already have `IS JSON`, couldn't we reuse
it
##########
flink-python/pyflink/table/expression.py:
##########
@@ -1201,6 +1203,22 @@ def regexp_extract(self,
else:
return _ternary_op("regexpExtract")(self, regex, extract_index)
+ def json_quote(self) -> 'Expression':
+ """
+ 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.
+ """
+ return _unary_op("jsonQuote")(self)
+
+ def json_unquote(self) -> 'Expression':
+ """
+ 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, an error occurs.
+ """
+ return _unary_op("jsonUnquote")(self)
+
Review Comment:
Same issue as mentioned for documentation
--
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]