You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2022/04/17 08:27:33 UTC

[GitHub] [spark] MaxGekk commented on a diff in pull request #36232: [SPARK-38741][SQL][TESTS] Test the error class: MAP_KEY_DOES_NOT_EXIST*

MaxGekk commented on code in PR #36232:
URL: https://github.com/apache/spark/pull/36232#discussion_r851721680


##########
sql/core/src/test/scala/org/apache/spark/sql/errors/QueryExecutionErrorsSuite.scala:
##########
@@ -400,4 +400,37 @@ class QueryExecutionErrorsSuite extends QueryTest
         "If necessary set spark.sql.ansi.enabled to false to bypass this error. ")
     }
   }
+
+  test("MAP_KEY_DOES_NOT_EXIST_IN_ELEMENT_AT: key does not exist") {
+    withSQLConf(SQLConf.ANSI_ENABLED.key -> "true") {
+      val e1 = intercept[SparkNoSuchElementException] {
+        sql("select element_at(map(1, 'a', 2, 'b'), 3)").collect()
+      }
+      assert(e1.getErrorClass === "MAP_KEY_DOES_NOT_EXIST_IN_ELEMENT_AT")
+      assert(e1.getMessage ===
+        "Key 3 does not exist. To return NULL instead, use 'try_element_at'. " +
+          "If necessary set spark.sql.ansi.enabled to false to bypass this error." +
+          """
+            |== SQL(line 1, position 7) ==
+            |select element_at(map(1, 'a', 2, 'b'), 3)
+            |       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+            |""".stripMargin)

Review Comment:
   Not need to indent additionally.



##########
sql/core/src/test/scala/org/apache/spark/sql/errors/QueryExecutionErrorsSuite.scala:
##########
@@ -400,4 +400,37 @@ class QueryExecutionErrorsSuite extends QueryTest
         "If necessary set spark.sql.ansi.enabled to false to bypass this error. ")
     }
   }
+
+  test("MAP_KEY_DOES_NOT_EXIST_IN_ELEMENT_AT: key does not exist") {
+    withSQLConf(SQLConf.ANSI_ENABLED.key -> "true") {
+      val e1 = intercept[SparkNoSuchElementException] {
+        sql("select element_at(map(1, 'a', 2, 'b'), 3)").collect()
+      }
+      assert(e1.getErrorClass === "MAP_KEY_DOES_NOT_EXIST_IN_ELEMENT_AT")
+      assert(e1.getMessage ===
+        "Key 3 does not exist. To return NULL instead, use 'try_element_at'. " +
+          "If necessary set spark.sql.ansi.enabled to false to bypass this error." +
+          """
+            |== SQL(line 1, position 7) ==
+            |select element_at(map(1, 'a', 2, 'b'), 3)
+            |       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+            |""".stripMargin)
+    }
+  }
+
+  test("MAP_KEY_DOES_NOT_EXIST: key does not exist") {

Review Comment:
   Where is the checks of error class and error message?



-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org