Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1100,7 +1100,7 @@ public void setSafe(int index, int isSet, int start, int end, ArrowBuf buffer) {
assert index >= 0;
final int dataLength = end - start;
fillEmpties(index);
handleSafe(index, end);
handleSafe(index, dataLength);
BitVectorHelper.setValidityBit(validityBuffer, index, isSet);
final int startOffset = offsetBuffer.getInt(index * OFFSET_WIDTH);
offsetBuffer.setInt((index + 1) * OFFSET_WIDTH, startOffset + dataLength);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1394,6 +1394,35 @@ public void testFillEmptiesNotOverfill() {
}
}

@Test
public void testSetSafeWithArrowBuf() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe add to the title doesntAllocateExcessiveMemory

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

final int numValues = BaseFixedWidthVector.INITIAL_VALUE_ALLOCATION * 2;

try (
final VarCharVector fromVector = newVector(VarCharVector.class, EMPTY_SCHEMA_PATH,
MinorType.VARCHAR, allocator);
final VarCharVector toVector = newVector(VarCharVector.class, EMPTY_SCHEMA_PATH,
MinorType.VARCHAR, allocator)) {
fromVector.setInitialCapacity(numValues);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it might make the unit test easier to read if you separated each section by a comment.
i.e.
//Setup

// Execute

// Verify

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i've added comments.

fromVector.allocateNew();
for (int i = 0; i < numValues; ++i) {
fromVector.setSafe(i, "hello world".getBytes(), 0, 11);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it might make the test easier to read if 0 and 11 where constants or had comments next to them.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed.

}
fromVector.setValueCount(numValues);
ArrowBuf fromDataBuffer = fromVector.getDataBuffer();
assertEquals(BaseAllocator.nextPowerOfTwo(numValues * 11), fromDataBuffer.capacity());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this test seems like it is potentially brittle if the allocator expansion algorithm was changed. Is this an intrinsic property of this method? Maybe make this an inequality?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed.


toVector.setInitialCapacity(numValues);
toVector.allocateNew();
for (int i = 0; i < numValues; i++) {
int start = fromVector.getstartOffset(i);
int end = fromVector.getstartOffset(i + 1);
toVector.setSafe(i, 1, start, end, fromDataBuffer);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

making this a named constant or putting in comments what the value represents might make the test easier to read.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

}
assertEquals(fromDataBuffer.capacity(), toVector.getDataBuffer().capacity());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it might pay to add a comment why the capacity is expected to be equal

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added.

}
}

@Test
public void testCopyFromWithNulls() {
try (final VarCharVector vector = newVector(VarCharVector.class, EMPTY_SCHEMA_PATH, MinorType.VARCHAR, allocator);
Expand Down