This is an automated email from the ASF dual-hosted git repository.
maxgekk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/spark.git
The following commit(s) were added to refs/heads/master by this push:
new 8d59fdbacf2 [SPARK-38736][SQL][TESTS] Test the error classes:
INVALID_ARRAY_INDEX & INVALID_ARRAY_INDEX_IN_ELEMENT_AT
8d59fdbacf2 is described below
commit 8d59fdbacf28427f72dd30e5e7e135644a0f2190
Author: panbingkun <[email protected]>
AuthorDate: Fri Apr 22 12:54:48 2022 +0300
[SPARK-38736][SQL][TESTS] Test the error classes: INVALID_ARRAY_INDEX &
INVALID_ARRAY_INDEX_IN_ELEMENT_AT
## What changes were proposed in this pull request?
This pr aims to add one test for the error class INVALID_ARRAY_INDEX &
INVALID_ARRAY_INDEX_IN_ELEMENT_AT to QueryExecutionAnsiErrorsSuite.
### Why are the changes needed?
The changes improve test coverage, and document expected error messages in
tests.
### Does this PR introduce any user-facing change?
No.
### How was this patch tested?
By running new test:
```
build/sbt "sql/testOnly *QueryExecutionAnsiErrorsSuite*"
```
Closes #36314 from panbingkun/SPARK-38736.
Authored-by: panbingkun <[email protected]>
Signed-off-by: Max Gekk <[email protected]>
---
.../sql/errors/QueryExecutionAnsiErrorsSuite.scala | 25 +++++++++++++++++++++-
1 file changed, 24 insertions(+), 1 deletion(-)
diff --git
a/sql/core/src/test/scala/org/apache/spark/sql/errors/QueryExecutionAnsiErrorsSuite.scala
b/sql/core/src/test/scala/org/apache/spark/sql/errors/QueryExecutionAnsiErrorsSuite.scala
index 3580f90f1bd..22e6711d74d 100644
---
a/sql/core/src/test/scala/org/apache/spark/sql/errors/QueryExecutionAnsiErrorsSuite.scala
+++
b/sql/core/src/test/scala/org/apache/spark/sql/errors/QueryExecutionAnsiErrorsSuite.scala
@@ -16,7 +16,7 @@
*/
package org.apache.spark.sql.errors
-import org.apache.spark.{SparkArithmeticException, SparkConf,
SparkDateTimeException}
+import org.apache.spark.{SparkArithmeticException,
SparkArrayIndexOutOfBoundsException, SparkConf, SparkDateTimeException}
import org.apache.spark.sql.QueryTest
import org.apache.spark.sql.internal.SQLConf
@@ -81,4 +81,27 @@ class QueryExecutionAnsiErrorsSuite extends QueryTest with
QueryErrorsSuiteBase
|""".stripMargin,
sqlState = Some("22005"))
}
+
+ test("INVALID_ARRAY_INDEX: get element from array") {
+ checkErrorClass(
+ exception = intercept[SparkArrayIndexOutOfBoundsException] {
+ sql("select array(1, 2, 3, 4, 5)[8]").collect()
+ },
+ errorClass = "INVALID_ARRAY_INDEX",
+ msg = "Invalid index: 8, numElements: 5. " +
+ "If necessary set spark.sql.ansi.enabled to false to bypass this
error."
+ )
+ }
+
+ test("INVALID_ARRAY_INDEX_IN_ELEMENT_AT: element_at from array") {
+ checkErrorClass(
+ exception = intercept[SparkArrayIndexOutOfBoundsException] {
+ sql("select element_at(array(1, 2, 3, 4, 5), 8)").collect()
+ },
+ errorClass = "INVALID_ARRAY_INDEX_IN_ELEMENT_AT",
+ msg = "Invalid index: 8, numElements: 5. " +
+ "To return NULL instead, use 'try_element_at'. " +
+ "If necessary set spark.sql.ansi.enabled to false to bypass this
error."
+ )
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]