srielau commented on a change in pull request #35352:
URL: https://github.com/apache/spark/pull/35352#discussion_r828171475
##########
File path:
sql/core/src/test/scala/org/apache/spark/sql/StringFunctionsSuite.scala
##########
@@ -661,4 +661,53 @@ class StringFunctionsSuite extends QueryTest with
SharedSparkSession {
}.getMessage
assert(m.contains("data type mismatch: argument 1 requires string type"))
}
+
+ test("SPARK-38063: string split_part function") {
+ checkAnswer(
+ sql("select split_part('11,12,13', ',', 1)"),
+ Row("11"))
+
+ checkAnswer(
+ sql("select split_part('11.12.13', '.', 2)"),
+ Row("12"))
+
+ checkAnswer(
+ sql("select split_part('11.12.13', '.', -1)"),
+ Row("13"))
+
+ checkAnswer(
+ sql("select split_part('11.12.13', '.', -3)"),
+ Row("11"))
+
+ checkAnswer(
+ sql("select split_part('11.12.13', '.', 4)"),
+ Row(""))
+
+ checkAnswer(
+ sql("select split_part('11.12.13', '.', 5)"),
+ Row(""))
+
+ checkAnswer(
+ sql("select split_part('11.12.13', '.', -5)"),
+ Row(""))
+
+ checkAnswer(
+ sql("select split_part('11.12.13', '', 1)"),
+ Row("11.12.13"))
+
+ checkAnswer(
+ sql("select split_part('11ab12ab13', 'ab', 1)"),
+ Row("11"))
+
+ val m = intercept[ArrayIndexOutOfBoundsException] {
+ checkAnswer(
+ sql("select split_part('11.12.13', '.', 0)"),
+ Row("11"))
+ }.getMessage
+ assert(m.contains("SQL array indices start at 1"))
Review comment:
It doesn't look like this is a new error message, but the text is
factually false given that we support negative index...
--
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]