Manya0407 commented on code in PR #6616:
URL: https://github.com/apache/hive/pull/6616#discussion_r3637333561


##########
ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/StringTrimColScalarBase.java:
##########
@@ -43,14 +44,75 @@ public StringTrimColScalarBase() {
   }
 
   protected boolean shouldTrim(int character) {
-    for (int i = 0; i < trimChars.length; ++i) {
-      if (trimChars[i] == character) {
+    return shouldTrimByte((byte) character, trimChars, 0, trimChars.length);
+  }
+
+  static boolean shouldTrimByte(byte character, byte[] trimBytes, int 
trimStart, int trimLen) {
+    final int trimEnd = trimStart + trimLen;
+    for (int i = trimStart; i < trimEnd; ++i) {
+      if (trimBytes[i] == character) {
         return true;
       }
     }
     return false;
   }
 
+  static void trimBoth(BytesColumnVector outV, byte[] bytes, int startIndex, 
int length,
+      byte[] trimBytes, int trimStart, int trimLen, int batchIndex) {
+    final int end = startIndex + length;
+    int leftIndex = startIndex;
+    while (leftIndex < end && shouldTrimByte(bytes[leftIndex], trimBytes, 
trimStart, trimLen)) {
+      leftIndex++;
+    }
+    if (leftIndex == end) {
+      outV.setVal(batchIndex, EMPTY_BYTES, 0, 0);
+      return;
+    }
+
+    int rightIndex = end - 1;
+    final int rightLimit = leftIndex + 1;
+    while (rightIndex >= rightLimit && shouldTrimByte(bytes[rightIndex], 
trimBytes, trimStart, trimLen)) {
+      rightIndex--;
+    }
+    final int resultLength = rightIndex - leftIndex + 1;
+    if (resultLength <= 0) {
+      throw new RuntimeException("Not expected");
+    }
+    outV.setVal(batchIndex, bytes, leftIndex, resultLength);
+  }

Review Comment:
   Refactored the existing ColScalar func() methods to delegate to 
trimBoth/trimLeft/trimRight in StringTrimColScalarBase, so trim logic lives in 
one place for both ColScalar and the new ColCol/ScalarCol classes.



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