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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]