sunchao commented on a change in pull request #30297:
URL: https://github.com/apache/spark/pull/30297#discussion_r521545831



##########
File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/collectionOperations.scala
##########
@@ -2008,7 +2015,11 @@ case class ElementAt(left: Expression, right: Expression)
         val array = value.asInstanceOf[ArrayData]
         val index = ordinal.asInstanceOf[Int]
         if (array.numElements() < math.abs(index)) {
-          null
+          if (failOnError) {
+            throw new ArrayIndexOutOfBoundsException(s"Invalid index: $index")

Review comment:
       nit: can we include the total number of elements too in the error 
message? sometimes that is helpful for debugging.

##########
File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/internal/SQLConf.scala
##########
@@ -2144,9 +2144,10 @@ object SQLConf {
 
   val ANSI_ENABLED = buildConf("spark.sql.ansi.enabled")
     .doc("When true, Spark tries to conform to the ANSI SQL specification: 1. 
Spark will " +
-      "throw a runtime exception if an overflow occurs in any operation on 
integral/decimal " +
-      "field. 2. Spark will forbid using the reserved keywords of ANSI SQL as 
identifiers in " +
-      "the SQL parser.")
+      "throw an exception at runtime if the inputs to a SQL operator/function 
are invalid, " +
+      "e.g. overflow in arithmetic operations, out-of-range index when 
accessing array elements. " +
+      "2. Spark will forbid using the reserved keywords of ANSI SQL as 
identifiers in " +
+      "the SQL parser. 3. Spark will returns null for null input for function 
`size`.")

Review comment:
       will returns -> will return, and perhaps capital `NULL`?




----------------------------------------------------------------
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:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to