-
Notifications
You must be signed in to change notification settings - Fork 4k
ARROW-4532: [Java] fix bug causing very large varchar value buffers #3613
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1394,6 +1394,51 @@ public void testFillEmptiesNotOverfill() { | |
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void testSetSafeWithArrowBufNoExcessAllocs() { | ||
| final int numValues = BaseFixedWidthVector.INITIAL_VALUE_ALLOCATION * 2; | ||
| final byte[] valueBytes = "hello world".getBytes(); | ||
| final int valueBytesLength = valueBytes.length; | ||
| final int isSet = 1; | ||
|
|
||
| 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)) { | ||
| /* | ||
| * Populate the from vector with 'numValues' with byte-arrays, each of size 'valueBytesLength'. | ||
| */ | ||
| fromVector.setInitialCapacity(numValues); | ||
| fromVector.allocateNew(); | ||
| for (int i = 0; i < numValues; ++i) { | ||
| fromVector.setSafe(i, valueBytes, 0 /*start*/, valueBytesLength); | ||
| } | ||
| fromVector.setValueCount(numValues); | ||
| ArrowBuf fromDataBuffer = fromVector.getDataBuffer(); | ||
| assertTrue(numValues * valueBytesLength <= fromDataBuffer.capacity()); | ||
|
|
||
| /* | ||
| * Copy the entries one-by-one from 'fromVector' to 'toVector', but use the setSafe with | ||
| * ArrowBuf API (instead of setSafe with byte-array). | ||
| */ | ||
| 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, isSet, start, end, fromDataBuffer); | ||
| } | ||
|
|
||
| /* | ||
| * Since the 'fromVector' and 'toVector' have the same initial capacity, and were populated | ||
| * with the same varchar elements, the allocations and hence, the final capacity should be | ||
| * the same. | ||
| */ | ||
| assertEquals(fromDataBuffer.capacity(), toVector.getDataBuffer().capacity()); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
|
|
||
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i've added comments.