stefankandic commented on code in PR #45725:
URL: https://github.com/apache/spark/pull/45725#discussion_r1544731317


##########
sql/core/src/test/scala/org/apache/spark/sql/CollationStringExpressionsSuite.scala:
##########
@@ -73,6 +73,84 @@ class CollationStringExpressionsSuite extends QueryTest
     })
   }
 
+  test("SUBSTRING_INDEX check result on explicitly collated strings") {
+    def testSubstringIndex(str: String, delim: String, cnt: Integer,
+                           collationId: Integer, expected: String): Unit = {
+      val string = Literal.create(str, StringType(collationId))
+      val delimiter = Literal.create(delim, StringType(collationId))
+      val count = Literal(cnt)
+
+      checkEvaluation(SubstringIndex(string, delimiter, count), expected)
+    }
+
+    testSubstringIndex("wwwgapachegorg", "g", -3, 0, "apachegorg")
+    testSubstringIndex("www||apache||org", "||", 2, 0, "www||apache")
+    // UTF8_BINARY_LCASE
+    testSubstringIndex("AaAaAaAaAa", "aa", 2, 1, "A")
+    testSubstringIndex("www.apache.org", ".", 3, 1, "www.apache.org")
+    testSubstringIndex("wwwXapachexorg", "x", 2, 1, "wwwXapache")
+    testSubstringIndex("wwwxapacheXorg", "X", 1, 1, "www")
+    testSubstringIndex("www.apache.org", ".", 0, 1, "")
+    testSubstringIndex("www.apache.ORG", ".", -3, 1, "www.apache.ORG")
+    testSubstringIndex("wwwGapacheGorg", "g", 1, 1, "www")
+    testSubstringIndex("wwwGapacheGorg", "g", 3, 1, "wwwGapacheGor")
+    testSubstringIndex("gwwwGapacheGorg", "g", 3, 1, "gwwwGapache")
+    testSubstringIndex("wwwGapacheGorg", "g", -3, 1, "apacheGorg")
+    testSubstringIndex("wwwmapacheMorg", "M", -2, 1, "apacheMorg")
+    testSubstringIndex("www.apache.org", ".", -1, 1, "org")
+    testSubstringIndex("", ".", -2, 1, "")
+    // scalastyle:off
+    testSubstringIndex("test大千世界X大千世界", "x", -1, 1, "大千世界")
+    testSubstringIndex("test大千世界X大千世界", "X", 1, 1, "test大千世界")
+    testSubstringIndex("test大千世界大千世界", "千", 2, 1, "test大千世界大")
+    // scalastyle:on
+    testSubstringIndex("www||APACHE||org", "||", 2, 1, "www||APACHE")
+    testSubstringIndex("www||APACHE||org", "||", -1, 1, "org")
+    // UNICODE
+    testSubstringIndex("AaAaAaAaAa", "Aa", 2, 2, "Aa")
+    testSubstringIndex("wwwYapacheyorg", "y", 3, 2, "wwwYapacheyorg")
+    testSubstringIndex("www.apache.org", ".", 2, 2, "www.apache")

Review Comment:
   almost all of these have exact case match for both string - maybe randomize 
it a bit for case insensitive collations?



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