wuchong commented on a change in pull request #11188: [FLINK-16202][sql]
Support JSON_QUERY for blink planner
URL: https://github.com/apache/flink/pull/11188#discussion_r385535655
##########
File path:
flink-table/flink-table-planner-blink/src/test/scala/org/apache/flink/table/planner/expressions/ScalarFunctionsTest.scala
##########
@@ -4195,4 +4195,53 @@ class ScalarFunctionsTest extends ScalarTypesTestBase {
"f55=f57",
"true")
}
+
+ //-------------------------------------------------------------------
+ // JSON functions
+ //-------------------------------------------------------------------
+ @Test
+ def testJsonQuery(): Unit = {
+ // lax test
+ testSqlApi("json_query('{\"foo\":100}', 'lax $' null on empty)",
"{\"foo\":100}")
+ testSqlApi("json_query('{\"foo\":100}', 'lax $' error on empty)",
"{\"foo\":100}")
+ testSqlApi("json_query('{\"foo\":100}', 'lax $' empty array on empty)",
"{\"foo\":100}");
+ testSqlApi("json_query('{\"foo\":100}', 'lax $' empty object on empty)",
"{\"foo\":100}");
+ testSqlApi("json_query('{\"foo\":100}', 'lax $.foo' null on empty)",
"null");
+ testSqlApi("json_query('{\"foo\":100}', 'lax $.foo' empty array on
empty)", "[]");
+ testSqlApi("json_query('{\"foo\":100}', 'lax $.foo' empty object on
empty)", "{}");
+
+ // path error test
+ testSqlApi("json_query('{\"foo\":100}', 'invalid $.foo' null on error)",
"null");
+ testSqlApi("json_query('{\"foo\":100}', 'invalid $.foo' empty array on
error)", "[]");
+ testSqlApi("json_query('{\"foo\":100}', 'invalid $.foo' empty object on
error)", "{}");
+
+ // strict test
+ testSqlApi("json_query('{\"foo\":100}', 'strict $' null on empty)",
"{\"foo\":100}");
+ testSqlApi("json_query('{\"foo\":100}', 'strict $' error on empty)",
"{\"foo\":100}");
+ testSqlApi("json_query('{\"foo\":100}', 'strict $' empty array on error)",
"{\"foo\":100}");
+ testSqlApi("json_query('{\"foo\":100}', 'strict $' empty object on
error)", "{\"foo\":100}");
+
+ testSqlApi("json_query('{\"foo\":100}', 'strict $.foo1' null on error)",
"null");
+ testSqlApi("json_query('{\"foo\":100}', 'strict $.foo1' empty array on
error)", "[]");
+ testSqlApi("json_query('{\"foo\":100}', 'strict $.foo1' empty object on
error)", "{}");
+ testSqlApi("json_query('{\"foo\":100}', 'strict $.foo' null on error)",
"null");
+ testSqlApi("json_query('{\"foo\":100}', 'strict $.foo' empty array on
error)", "[]");
+ testSqlApi("json_query('{\"foo\":100}', 'strict $.foo' empty object on
error)", "{}");
+
+ // array wrapper test
+ testSqlApi("json_query('{\"foo\":100}', 'strict $.foo' without wrapper)",
"null");
+ testSqlApi("json_query('{\"foo\":100}', 'strict $.foo' without array
wrapper)", "null");
+ testSqlApi("json_query('{\"foo\":100}', 'strict $.foo' with wrapper)",
"[100]");
+ testSqlApi("json_query('{\"foo\":100}', 'strict $.foo' with unconditional
wrapper)", "[100]");
+ testSqlApi("json_query('{\"foo\":100}', 'strict $.foo' with conditional
wrapper)", "[100]");
+ testSqlApi("json_query('{\"foo\":[100]}', 'strict $.foo' without
wrapper)", "[100]");
+ testSqlApi("json_query('{\"foo\":[100]}', 'strict $.foo' without array
wrapper)", "[100]");
+ testSqlApi("json_query('{\"foo\":[100]}', 'strict $.foo' with wrapper)",
"[[100]]");
+ testSqlApi("json_query('{\"foo\":[100]}', 'strict $.foo' with
unconditional wrapper)",
+ "[[100]]");
+ testSqlApi("json_query('{\"foo\":[100]}', 'strict $.foo' with conditional
wrapper)", "[100]");
+
+ // nulls
+ testSqlApi("json_query(cast(null as varchar), 'lax $')", "null")
Review comment:
Please also add some tests on a column reference? Currently, all the testing
data is char.
Please also test on non-string columns.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services