Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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 @@ -1405,7 +1405,8 @@ public final int getTotalValueLengthUpToIndex(int index) {
}

protected final void handleSafe(int index, int dataLength) {
final long targetCapacity = roundUpToMultipleOf16((long) index * ELEMENT_SIZE + dataLength);
// The view buffer stores one fixed-width view per value; payload bytes are allocated separately.
final long targetCapacity = roundUpToMultipleOf16(((long) index + 1) * ELEMENT_SIZE);
if (viewBuffer.capacity() < targetCapacity) {
reallocViewBuffer(targetCapacity);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,26 @@ public void testSizeOfViewBufferElements() {
}
}

@ParameterizedTest
@MethodSource({"vectorCreatorProvider"})
public void testSetSafeEmptyValueAtViewBufferBoundary(
Function<BufferAllocator, BaseVariableWidthViewVector> vectorCreator) {
try (final BaseVariableWidthViewVector vector = vectorCreator.apply(allocator)) {
final byte[] emptyValue = new byte[0];
vector.allocateNew();
final int valueCapacity = vector.getValueCapacity();

for (int i = 0; i <= valueCapacity; i++) {
vector.setSafe(i, emptyValue);
}

vector.setValueCount(valueCapacity + 1);
assertTrue(vector.getValueCapacity() > valueCapacity);
assertEquals(0, vector.getValueLength(valueCapacity));
assertArrayEquals(emptyValue, vector.get(valueCapacity));
}
}

@Test
public void testNullableVarType1() {

Expand Down
Loading