XuQianJin-Stars commented on a change in pull request #11186:
URL: https://github.com/apache/flink/pull/11186#discussion_r433724128



##########
File path: 
flink-table/flink-table-planner-blink/src/test/scala/org/apache/flink/table/planner/expressions/JsonFunctionsTest.scala
##########
@@ -117,12 +131,48 @@ class JsonFunctionsTest extends ExpressionTestBase {
       s"$candidate is not json scalar")
 
     for (sql <- sqlCandidates) {
-      try {
-        testSqlApi(sql, "null")
-      } catch {
+      try testSqlApi(sql, "null") catch {
         case e: Exception => assertEquals(e.getClass, expectedException)
       }
     }
   }
 
+  @Test
+  def testJsonExists(): Unit = {
+    testSqlApi("json_exists(f9, '$.info.type')", "false")
+
+    // lax json test
+    testSqlApi("json_exists(f9, 'lax $')", "true")
+    testSqlApi("json_exists(f9, 'lax $.info.type')", "true")
+    testSqlApi("json_exists(f9, 'lax $.info.address.town')", "true")
+    testSqlApi("json_exists(f9, 'lax $.info.\"address\"')", "false")
+    testSqlApi("json_exists(f9, 'lax $.info.tags')", "true")
+    testSqlApi("json_exists(f9, 'lax $.info.type[0]')", "false")
+    testSqlApi("json_exists(f9, 'lax $.info.none')", "false")
+    testSqlApi("json_exists(f9, 'lax $' error on error)", "true")
+
+    // strict + no error
+    testSqlApi("json_exists(f9, 'strict $.info.type')", "true")
+    testSqlApi("json_exists(f9, 'strict $.info.type1')", "false")
+    // strict + error
+    testSqlApi("json_exists(f9, 'strict $.info.type1' false on error)", 
"false")
+    testSqlApi("json_exists(f9, 'strict $.info.type1' true on error)", "true")
+    testSqlApi("json_exists(f9, 'strict $.info.type' true on error)", "true")
+    testSqlApi("json_exists(f9, 'strict $.info.type' false on error)", "true")
+    testSqlApi("json_exists(f9, 'strict $.info.type' unknown on error)", 
"true")
+    testSqlApi("json_exists(f9, 'strict $.info.\"type\"' unknown on error)", 
"null")
+    testSqlApi("json_exists(f9, 'strict $.info.type' error on error)", "true")
+
+    verifyJsonExistsException("json_exists(f7, 'lax aa')", "SQL validation 
failed")
+  }
+
+  private def verifyJsonExistsException[T <: Exception](
+       sqlExpr: String,
+       expectedMessage: String
+     ): Unit = {
+    expectedException.expect(classOf[ValidationException])
+    expectedException.expectMessage(startsWith(expectedMessage))
+    testSqlApi(sqlExpr, "null")
+    expectedException = ExpectedException.none()

Review comment:
       > have you verified this test? I seems that if we encounter one 
exception, it will abort the test no matter it satisfies the expected exception.
   
   Well, I tested this place. no problem.




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


Reply via email to