diff --git a/storage-api/src/java/org/apache/hadoop/hive/ql/exec/vector/BytesColumnVector.java b/storage-api/src/java/org/apache/hadoop/hive/ql/exec/vector/BytesColumnVector.java index e386109920..0ef547de4a 100644 --- a/storage-api/src/java/org/apache/hadoop/hive/ql/exec/vector/BytesColumnVector.java +++ b/storage-api/src/java/org/apache/hadoop/hive/ql/exec/vector/BytesColumnVector.java @@ -304,12 +304,20 @@ public void increaseBufferSpace(int nextElemLength) { } // smallBuffer might still be out of space + if (smallBuffer.length == Integer.MAX_VALUE) { + throw new RuntimeException("SmallBuffer size has reached 2GB and cannot be increased."); + } if ((nextFree + nextElemLength) > buffer.length) { int newLength = smallBuffer.length * 2; while (newLength < nextElemLength) { - if (newLength < 0) { - throw new RuntimeException("Overflow of newLength. smallBuffer.length=" - + smallBuffer.length + ", nextElemLength=" + nextElemLength); + if (newLength < 0) { // integer overflow + if (smallBuffer.length + nextElemLength > 0) { + newLength = Integer.MAX_VALUE; // try to maximize smallBuffer size + } else { + throw new RuntimeException( + "BytesColumnVector smallBuffer is too full for next element. smallBuffer length=" + + smallBuffer.length + ", next element length =" + nextElemLength); + } } newLength *= 2; }