diff --git a/java/vector/src/main/java/org/apache/arrow/vector/BaseNullableVariableWidthVector.java b/java/vector/src/main/java/org/apache/arrow/vector/BaseNullableVariableWidthVector.java index 5ab884831e7ad..0ff3959d4bf5c 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/BaseNullableVariableWidthVector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/BaseNullableVariableWidthVector.java @@ -24,7 +24,6 @@ import org.apache.arrow.memory.OutOfMemoryException; import org.apache.arrow.memory.BaseAllocator; import org.apache.arrow.memory.BufferAllocator; -import org.apache.arrow.vector.complex.NullableMapVector; import org.apache.arrow.vector.schema.ArrowFieldNode; import org.apache.arrow.vector.types.pojo.Field; import org.apache.arrow.vector.types.pojo.FieldType; @@ -188,10 +187,14 @@ public void setInitialCapacity(int valueCount) { * @param density average number of bytes per variable width element */ public void setInitialCapacity(int valueCount, double density) { - final long size = (long) (valueCount * density); + long size = (long) (valueCount * density); if (size > MAX_ALLOCATION_SIZE) { throw new OversizedAllocationException("Requested amount of memory is more than max allowed"); } + + if(size == 0) { + size = 1; + } valueAllocationSizeInBytes = (int) size; validityAllocationSizeInBytes = getValidityBufferSizeFromCount(valueCount); /* to track the end offset of last data element in vector, we need diff --git a/java/vector/src/main/java/org/apache/arrow/vector/complex/BaseRepeatedValueVector.java b/java/vector/src/main/java/org/apache/arrow/vector/complex/BaseRepeatedValueVector.java index fef2cf3c98bde..1cd9b718523ee 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/complex/BaseRepeatedValueVector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/complex/BaseRepeatedValueVector.java @@ -172,7 +172,12 @@ public void setInitialCapacity(int numRecords, double density) { throw new OversizedAllocationException("Requested amount of memory is more than max allowed"); } offsetAllocationSizeInBytes = (numRecords + 1) * OFFSET_WIDTH; - final int innerValueCapacity = (int)(numRecords * density); + int innerValueCapacity = (int)(numRecords * density); + + if(innerValueCapacity == 0) { + innerValueCapacity = 1; + } + vector.setInitialCapacity(innerValueCapacity); }