wangyum commented on code in PR #37626:
URL: https://github.com/apache/spark/pull/37626#discussion_r952483300


##########
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/CollectionExpressionsSuite.scala:
##########
@@ -2522,4 +2522,24 @@ class CollectionExpressionsSuite extends SparkFunSuite 
with ExpressionEvalHelper
           Date.valueOf("2017-02-12")))
     }
   }
+
+  test("SplitPart") {
+    val delimiter = Literal.create(".", StringType)
+    val str = StringSplitSQL(Literal.create("11.12.13", StringType), delimiter)
+    val outOfBoundValue = Some(Literal.create("", StringType))
+
+    checkEvaluation(ElementAt(str, Literal(3), outOfBoundValue), 
UTF8String.fromString("13"))
+    checkEvaluation(ElementAt(str, Literal(1), outOfBoundValue), 
UTF8String.fromString("11"))
+    checkEvaluation(ElementAt(str, Literal(10), outOfBoundValue), 
UTF8String.fromString(""))
+    checkEvaluation(ElementAt(str, Literal(-10), outOfBoundValue), 
UTF8String.fromString(""))
+
+    checkEvaluation(ElementAt(StringSplitSQL(Literal.create(null, StringType), 
delimiter),
+      Literal(1), outOfBoundValue), null)
+    checkEvaluation(ElementAt(StringSplitSQL(Literal.create("11.12.13", 
StringType),
+      Literal.create(null, StringType)), Literal(1), outOfBoundValue), null)
+
+    intercept[Exception] {

Review Comment:
   org.scalatest.exceptions.TestFailedException is scala test exception, not 
Spark exception. It seems meaningless:
   ```scala
       intercept[SparkRuntimeException] {
         checkEvaluation(ElementAt(str, Literal(0), outOfBoundValue), null)
       }.getMessage.contains("The index 0 is invalid")
   ```
   
   ```
   Expected exception org.apache.spark.SparkRuntimeException to be thrown, but 
org.scalatest.exceptions.TestFailedException was thrown
   ScalaTestFailureLocation: 
org.apache.spark.sql.catalyst.expressions.CollectionExpressionsSuite at 
(CollectionExpressionsSuite.scala:2543)
   org.scalatest.exceptions.TestFailedException: Expected exception 
org.apache.spark.SparkRuntimeException to be thrown, but 
org.scalatest.exceptions.TestFailedException was thrown
        at 
org.scalatest.Assertions.newAssertionFailedException(Assertions.scala:472)
        at 
org.scalatest.Assertions.newAssertionFailedException$(Assertions.scala:471)
        at 
org.scalatest.funsuite.AnyFunSuite.newAssertionFailedException(AnyFunSuite.scala:1563)
   ```



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

Reply via email to