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



##########
File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/collectionOperations.scala
##########
@@ -1906,8 +1906,8 @@ case class ArrayPosition(left: Expression, right: 
Expression)
 @ExpressionDescription(
   usage = """
     _FUNC_(array, index) - Returns element of array at given (1-based) index. 
If index < 0,
-      accesses elements from the last to the first. Returns NULL if the index 
exceeds the length
-      of the array.
+      accesses elements from the last to the first. If the index exceeds the 
length of the array,
+      Returns NULL if ANSI mode is off; Throws ArrayIndexOutOfBoundsException 
when ANSI mode is on.

Review comment:
       How about rewriting it like this?
   ```
    The function returns NULL if the index exceeds the length of the array and 
`spark.sql.ansi.enabled` is set to false. If `spark.sql.ansi.enabled` is set to 
true, it throws ArrayIndexOutOfBoundsException for invalid indices.
   ```
   by referring to the `Size` usage:
   
https://github.com/apache/spark/blob/8760032f4f7e1ef36fee6afc45923d3826ef14fc/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/collectionOperations.scala#L79-L82

##########
File path: docs/sql-ref-ansi-compliance.md
##########
@@ -111,6 +111,13 @@ SELECT * FROM t;
 
 The behavior of some SQL functions can be different under ANSI mode 
(`spark.sql.ansi.enabled=true`).
   - `size`: This function returns null for null input under ANSI mode.

Review comment:
       (This is not related to this PR though) could you remove `under ANSI 
mode` in this statement, too?




----------------------------------------------------------------
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