Skip to content

Commit

Permalink
[FLINK-34111] Add missing function definitions, fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
anupamaggarwal committed Jun 20, 2024
1 parent 3903d24 commit 48b570f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
19 changes: 19 additions & 0 deletions flink-python/pyflink/table/expression.py
Original file line number Diff line number Diff line change
Expand Up @@ -1956,6 +1956,25 @@ def json_query(self, path: str, wrapping_behavior=JsonQueryWrapper.WITHOUT_ARRAY
on_empty._to_j_json_query_on_error_or_empty(),
on_error._to_j_json_query_on_error_or_empty())

def json_quote(self) -> 'Expression':
"""
Quotes a string as a JSON value by wrapping it with double quote characters,
escaping interior quote and special characters
('"', '\', '/', 'b', 'f', 'n', 'r', 't'), and returning
the result as a string. If the argument is NULL, the function returns NULL.
"""
return _unary_op("jsonQuote")(self)

def json_unquote(self) -> 'Expression':
"""
Unquotes JSON value, escapes spacial characters
('"', '\', '/', 'b', 'f', 'n', 'r', 't', 'u' hex hex hex hex) and
returns the result as a 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)


# add the docs
_make_math_log_doc()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ class ScalarFunctionsTest extends ScalarTypesTestBase {
testSqlApi("JSON_UNQUOTE('\"[\\t\\u0032]\"')", "[\t2]")
testSqlApi(
"JSON_UNQUOTE('\"This is a \\t test \\n with special characters: \\b \\f \\r \\u0041\"')",
"This is a \\t test \\n with special characters: \\b \\f \\r A"
"This is a \t test \n with special characters: \b \f \r A"
)
testSqlApi("json_unquote(json_quote('\"key\"'))", "\"key\"")
testSqlApi("json_unquote(json_quote('\"[]\"'))", "\"[]\"")
Expand Down

0 comments on commit 48b570f

Please sign in to comment.