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


##########
common/unsafe/src/main/java/org/apache/spark/unsafe/types/UTF8String.java:
##########
@@ -863,6 +914,70 @@ private int rfind(UTF8String str, int start) {
     return -1;
   }
 
+  /**
+   * Find the `str` from right to left considering different collations.
+   */
+  private int rfind(UTF8String str, int start, int collationId) {
+    if (CollationFactory.fetchCollation(collationId).supportsBinaryEquality) {
+      return this.rfind(str, start);
+    }
+    if(collationId == CollationFactory.UTF8_BINARY_LCASE_COLLATION_ID) {
+      return rfindLowercase(str, start);
+    }
+    return collatedRFind(str, start, collationId);
+  }
+
+  /**
+   * Find the `str` from left to right considering binary lowercase collation.
+   */
+  private int rfindLowercase(UTF8String str, int start) {
+    if(numBytes == 0 || str.numBytes == 0) {
+      return -1;
+    }
+
+    UTF8String lowercaseThis = this.toLowerCase();
+    UTF8String lowercaseStr = str.toLowerCase();
+
+    int prevStart = -1;
+    int matchStart = lowercaseThis.indexOf(lowercaseStr, 0);
+    while(charPosToByte(matchStart) <= start) {
+      if(matchStart != -1) {
+        // Found a match, update the start position
+        prevStart = matchStart;
+        matchStart = lowercaseThis.indexOf(lowercaseStr, matchStart + 1);
+      } else {
+        return charPosToByte(prevStart);
+      }
+    }
+
+    return charPosToByte(prevStart);
+  }
+
+  /**
+   * Find the `str` from left to right considering non-binary collations.
+   */
+  private int collatedRFind(UTF8String str, int start, int collationId) {
+    if(numBytes == 0 || str.numBytes == 0) {

Review Comment:
   same questions as above for `str.numBytes == 0`



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