uros-db commented on code in PR #48521:
URL: https://github.com/apache/spark/pull/48521#discussion_r1812920798


##########
common/unsafe/src/main/java/org/apache/spark/sql/catalyst/util/CollationAwareUTF8String.java:
##########
@@ -1232,22 +1255,62 @@ public static UTF8String trimLeft(
     // Return the substring from the calculated position until the end of the 
string.
     return UTF8String.fromString(src.substring(charIndex));
   }
+  /**
+   * Trims the `srcString` string from the right side using the specified 
`trimString` characters,
+   * with respect to the UTF8_BINARY trim collation. For UTF8_BINARY trim 
collation, the method has
+   * one special case to cover with respect to trimRight function for regular 
UTF8_Binary collation.
+   * Trailing spaces should be ignored in case of trim collation (rtrim for 
example) and if
+   * trimString does not contain spaces. In this case, the method trims the 
string from the right
+   * and after call of regular trim functions returns back trimmed spaces as 
those should not get
+   * removed.
+   * @param srcString the input string to be trimmed from the right end of the 
string
+   * @param trimString the trim string characters to trim
+   * @param collationId the collation ID to use for string trim
+   * @return the trimmed string (for UTF8_LCASE collation)
+   */
+  public static UTF8String binaryTrimRight(
+      final UTF8String srcString,
+      final UTF8String trimString,
+      final int collationId) {
+    boolean ignoreSpaces = !trimString.contains(UTF8String.SPACE_UTF8) &&

Review Comment:
   not a huge fan of calling `contains` in O(n^2) here...



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