You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by GitBox <gi...@apache.org> on 2020/04/04 05:24:26 UTC

[GitHub] [flink] XuQianJin-Stars commented on a change in pull request #11186: [FLINK-16200][sql] Support JSON_EXISTS for blink planner

XuQianJin-Stars commented on a change in pull request #11186: [FLINK-16200][sql] Support JSON_EXISTS for blink planner
URL: https://github.com/apache/flink/pull/11186#discussion_r403428053
 
 

 ##########
 File path: flink-table/flink-table-planner-blink/src/test/scala/org/apache/flink/table/planner/expressions/JsonFunctionsTest.scala
 ##########
 @@ -125,4 +127,53 @@ class JsonFunctionsTest extends ExpressionTestBase {
     }
   }
 
+  @Test
+  def testJsonExists(): Unit = {
+    testSqlApi("json_exists('{\"foo\":\"bar\"}', "
+      + "'strict $.foo' false on error)", "true")
+    testSqlApi("json_exists('{\"foo\":\"bar\"}', "
+      + "'strict $.foo' true on error)", "true")
+    testSqlApi("json_exists('{\"foo\":\"bar\"}', "
+      + "'strict $.foo' unknown on error)", "true")
+    testSqlApi("json_exists('{\"foo\":\"bar\"}', "
+      + "'lax $.foo' false on error)", "true")
+    testSqlApi("json_exists('{\"foo\":\"bar\"}', "
+      + "'lax $.foo' true on error)", "true")
+    testSqlApi("json_exists('{\"foo\":\"bar\"}', "
+      + "'lax $.foo' unknown on error)", "true")
+    testSqlApi("json_exists('{}', "
+      + "'invalid $.foo' false on error)", "false")
+    testSqlApi("json_exists('{}', "
+      + "'invalid $.foo' true on error)", "true")
+    testSqlApi("json_exists('{}', "
+      + "'invalid $.foo' unknown on error)", "null")
+    testSqlApi("json_exists(cast('{\"foo\":\"bar\"}' as varchar), "
+      + "'strict $.foo1')", "false")
+
+    // not exists
+    testSqlApi("json_exists('{\"foo\":\"bar\"}', "
+      + "'strict $.foo1' false on error)", "false")
+    testSqlApi("json_exists('{\"foo\":\"bar\"}', "
+      + "'strict $.foo1' true on error)", "true")
+    testSqlApi("json_exists('{\"foo\":\"bar\"}', "
+      + "'strict $.foo1' unknown on error)", "null")
+    testSqlApi("json_exists('{\"foo\":\"bar\"}', "
+      + "'lax $.foo1' true on error)", "false")
+    testSqlApi("json_exists('{\"foo\":\"bar\"}', "
+      + "'lax $.foo1' false on error)", "false")
+    testSqlApi("json_exists('{\"foo\":\"bar\"}', "
+      + "'lax $.foo1' error on error)", "false")
+    testSqlApi("json_exists('{\"foo\":\"bar\"}', "
+      + "'lax $.foo1' unknown on error)", "false")
+
+    // nulls
+    testSqlApi("json_exists(cast(null as varchar), 'lax $' unknown on error)", "null")
+  }
+
+  @Test
+  def testJsonFuncError(): Unit = {
+    expectedException.expect(classOf[CodeGenException])
+    expectedException.expectMessage(startsWith("Unsupported call: JSON_EXISTS"))
 
 Review comment:
   > This exception message is still misleading. We already support `JSON_EXISTS`, why the exception says not? I think we should improve the exception to give a better understandable message, e.g. `the json path 'lax $' is illegal.`
   
   Because `JSON_EXISTS (INT, CHAR (5) NOT NULL, RAW ('org.apache.calcite.sql.SqlJsonExistsErrorBehavior',?)` This is not supported. The json path 'lax $' is illegal will return `false`.

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services