Skip to content

Commit

Permalink
ARROW-2019: [JAVA] Control the memory allocated for inner vector in LIST
Browse files Browse the repository at this point in the history
and handle 0 initial capacity in all vectors.
  • Loading branch information
siddharthteotia committed Jan 26, 2018
1 parent 9e828ee commit 182e67a
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions java/vector/src/main/codegen/templates/UnionVector.java
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ private void reallocTypeBuffer() {

long newAllocationSize = baseSize * 2L;
newAllocationSize = BaseAllocator.nextPowerOfTwo(newAllocationSize);
newAllocationSize = Math.max(newAllocationSize, 1);

if (newAllocationSize > BaseValueVector.MAX_ALLOCATION_SIZE) {
throw new OversizedAllocationException("Unable to expand the buffer");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,7 @@ private ArrowBuf reallocBufferHelper(ArrowBuf buffer, final boolean dataBuffer)

long newAllocationSize = baseSize * 2L;
newAllocationSize = BaseAllocator.nextPowerOfTwo(newAllocationSize);
newAllocationSize = Math.max(newAllocationSize, 1);

if (newAllocationSize > MAX_ALLOCATION_SIZE) {
throw new OversizedAllocationException("Unable to expand the buffer");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,7 @@ public void reallocDataBuffer() {

long newAllocationSize = baseSize * 2L;
newAllocationSize = BaseAllocator.nextPowerOfTwo(newAllocationSize);
newAllocationSize = Math.max(newAllocationSize, 1);

if (newAllocationSize > MAX_ALLOCATION_SIZE) {
throw new OversizedAllocationException("Unable to expand the buffer");
Expand Down Expand Up @@ -549,6 +550,7 @@ private ArrowBuf reallocBufferHelper(ArrowBuf buffer, final boolean offsetBuffer

long newAllocationSize = baseSize * 2L;
newAllocationSize = BaseAllocator.nextPowerOfTwo(newAllocationSize);
newAllocationSize = Math.max(newAllocationSize, 1);

if (newAllocationSize > MAX_ALLOCATION_SIZE) {
throw new OversizedAllocationException("Unable to expand the buffer");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ protected void reallocOffsetBuffer() {

long newAllocationSize = baseSize * 2L;
newAllocationSize = BaseAllocator.nextPowerOfTwo(newAllocationSize);
newAllocationSize = Math.max(newAllocationSize, 1);

if (newAllocationSize > MAX_ALLOCATION_SIZE) {
throw new OversizedAllocationException("Unable to expand the buffer");
Expand Down Expand Up @@ -136,10 +137,10 @@ public FieldVector getDataVector() {
@Override
public void setInitialCapacity(int numRecords) {
offsetAllocationSizeInBytes = (numRecords + 1) * OFFSET_WIDTH;
if (vector instanceof BaseNullableFixedWidthVector || vector instanceof BaseNullableVariableWidthVector) {
if (vector instanceof BaseNullableVariableWidthVector || vector instanceof BaseNullableFixedWidthVector) {
vector.setInitialCapacity(numRecords * RepeatedValueVector.DEFAULT_REPEAT_PER_RECORD);
} else {
vector.setInitialCapacity(numRecords);
vector.setInitialCapacity(numRecords);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ private void reallocValidityBuffer() {

long newAllocationSize = baseSize * 2L;
newAllocationSize = BaseAllocator.nextPowerOfTwo(newAllocationSize);
newAllocationSize = Math.max(newAllocationSize, 1);

if (newAllocationSize > MAX_ALLOCATION_SIZE) {
throw new OversizedAllocationException("Unable to expand the buffer");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ private void reallocValidityBuffer() {

long newAllocationSize = baseSize * 2L;
newAllocationSize = BaseAllocator.nextPowerOfTwo(newAllocationSize);
newAllocationSize = Math.max(newAllocationSize, 1);

if (newAllocationSize > MAX_ALLOCATION_SIZE) {
throw new OversizedAllocationException("Unable to expand the buffer");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,7 @@ private void reallocValidityBuffer() {

long newAllocationSize = baseSize * 2L;
newAllocationSize = BaseAllocator.nextPowerOfTwo(newAllocationSize);
newAllocationSize = Math.max(newAllocationSize, 1);

if (newAllocationSize > BaseValueVector.MAX_ALLOCATION_SIZE) {
throw new OversizedAllocationException("Unable to expand the buffer");
Expand Down

0 comments on commit 182e67a

Please sign in to comment.