Skip to content

Commit 78ad6e7

Browse files
author
WanKun
committed
[SPARK-53552] Optimize substr SQL function
1 parent a820047 commit 78ad6e7

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

common/unsafe/src/main/java/org/apache/spark/unsafe/types/UTF8String.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -642,9 +642,13 @@ public UTF8String substring(final int start, final int until) {
642642
}
643643

644644
int j = i;
645-
while (i < numBytes && c < until) {
646-
i += numBytesForFirstByte(getByte(i));
647-
c += 1;
645+
if (until == Integer.MAX_VALUE) {
646+
i = numBytes;
647+
} else {
648+
while (i < numBytes && c < until) {
649+
i += numBytesForFirstByte(getByte(i));
650+
c += 1;
651+
}
648652
}
649653

650654
if (i > j) {

0 commit comments

Comments
 (0)