amaliujia commented on a change in pull request #35352:
URL: https://github.com/apache/spark/pull/35352#discussion_r829468923



##########
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:
       hmm this is when ANSI mode is off what the code executes? Maybe a bug?

##########
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:
       hmm this is when ANSI mode is off what the code executes. Maybe a bug?




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