diff --git storage-api/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/StringExpr.java storage-api/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/StringExpr.java index 90817a5..fe47987 100644 --- storage-api/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/StringExpr.java +++ storage-api/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/StringExpr.java @@ -168,6 +168,11 @@ public static void rightTrim(BytesColumnVector outV, int i, byte[] bytes, int st * return the new byte length. */ public static int truncate(byte[] bytes, int start, int length, int maxLength) { + // Assume 1 byte per-char minimum + if (length < maxLength) { + return length; + } + int end = start + length; // count characters forward @@ -191,6 +196,12 @@ public static int truncate(byte[] bytes, int start, int length, int maxLength) { * place the result into element i of a vector. */ public static void truncate(BytesColumnVector outV, int i, byte[] bytes, int start, int length, int maxLength) { + // Assume 1 byte per-char minimum + if (length <= maxLength) { + outV.setVal(i, bytes, start, length); + return; + } + int end = start + length; // count characters forward @@ -216,6 +227,11 @@ public static void truncate(BytesColumnVector outV, int i, byte[] bytes, int sta * return a byte array with only truncated bytes. */ public static byte[] truncateScalar(byte[] bytes, int maxLength) { + // Assume 1 byte per-char minimum + if (bytes.length <= maxLength) { + return bytes; + } + int end = bytes.length; // count characters forward