cloud-fan commented on a change in pull request #30296:
URL: https://github.com/apache/spark/pull/30296#discussion_r520260092
##########
File path:
sql/core/src/test/scala/org/apache/spark/sql/DataFrameFunctionsSuite.scala
##########
@@ -1401,6 +1401,40 @@ class DataFrameFunctionsSuite extends QueryTest with
SharedSparkSession {
assert(e3.message.contains(errorMsg3))
}
+ test("SPARK-33391: element_at with CreateArray") {
+ // element_at should use one-based index and support negative index.
+ // valid index for array(1, 2, 3) should be 1,2,3,-1,-2,-3
+ var df = OneRowRelation().selectExpr("element_at(array(1, 2, 3), 1)")
+ assert(!df.schema.head.nullable)
+ checkAnswer(
+ df,
+ Seq(Row(1))
+ )
+
+ df = OneRowRelation().selectExpr("element_at(array(1, 2, 3), -1)")
+ assert(!df.schema.head.nullable)
+ checkAnswer(
+ df,
+ Seq(Row(3))
+ )
+
+ df = OneRowRelation().selectExpr("element_at(array(1, 2, 3), 3)")
+ assert(!df.schema.head.nullable)
+ checkAnswer(
+ df,
+ Seq(Row(3))
+ )
+
+ // 0 is not a valid index, return nullable = false since it throws
exception.
Review comment:
can we test `4, -4` as well?
----------------------------------------------------------------
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]