Github user kevinyu98 commented on a diff in the pull request:
https://github.com/apache/spark/pull/12646#discussion_r77079325
--- Diff:
common/unsafe/src/main/java/org/apache/spark/unsafe/types/UTF8String.java ---
@@ -501,6 +578,38 @@ public UTF8String trimRight() {
}
}
+ /**
+ * Removes all specified trim character from the ending of a string
+ * @param trimChar the trim character
+ */
+ public UTF8String trimRight(UTF8String trimChar) {
+ int numTrimBytes = trimChar.numBytes;
+ if (numTrimBytes == 0) {
+ return this;
+ }
+ int e = this.numBytes - numTrimBytes;
+ // skip all the consecutive matching character in the right side
+ // index 'e' points to first no matching byte position in the input
string from right side.
+ // Index 'e' moves the number of bytes of the trimming character first.
+ if (e < 0) {
+ e = this.numBytes - 1;
+ } else {
+ while (e >= 0 && e == this.rfind(trimChar, e)) {
+ e -= numTrimBytes;
+ }
+ if (e >= 0) {
+ e += numTrimBytes - 1;
+ }
+ }
+
+ if (e < 0) {
+ // empty string
+ return UTF8String.fromBytes(new byte[0]);
--- End diff --
I will change it.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]