Skip to content

Commit

Permalink
Ensure density driven initial capacity is never less than 1.
Browse files Browse the repository at this point in the history
  • Loading branch information
jacques-n authored and siddharthteotia committed Jan 26, 2018
1 parent 182e67a commit 80bc33c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit 80bc33c

Please sign in to comment.