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);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Correct. Reserves the full slot regardless of payload; ((long) index + 1) avoids overflow. roundUpToMultipleOf16 is a no-op here but fine to keep.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thanks for reviewing @mbutrovich . I kept this code path unchanged since it reserves the full view slot regardless of payload size and the cast keeps the sizing expression safe before the multiplication. Let me know if there any other thoughts.

if (viewBuffer.capacity() < targetCapacity) {
reallocViewBuffer(targetCapacity);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,60 @@ public void testSizeOfViewBufferElements() {
}
}

@ParameterizedTest
@MethodSource({"vectorCreatorProvider"})
public void testSetSafeEmptyValueAtViewBufferBoundary(

@mbutrovich mbutrovich Jul 8, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Only covers the empty-value path. setNull and fillEmpties/setValueCount reach the same handleSafe(index, 0). Suggest adding tests for those.

setValueCount trailing gap (silent trigger, no empty string written)

@ParameterizedTest
@MethodSource({"vectorCreatorProvider"})
public void testSetValueCountFillsEmptiesAtViewBufferBoundary(
    Function<BufferAllocator, BaseVariableWidthViewVector> vectorCreator) {
  try (final BaseVariableWidthViewVector vector = vectorCreator.apply(allocator)) {
    vector.allocateNew();
    final int valueCapacity = vector.getValueCapacity();
    vector.setSafe(valueCapacity - 1, "x".getBytes(StandardCharsets.UTF_8));
    // Leaves index valueCapacity unset: fillEmpties -> handleSafe(_, 0) on a full buffer.
    vector.setValueCount(valueCapacity + 1);
    assertTrue(vector.getValueCapacity() > valueCapacity);
    assertTrue(vector.isNull(valueCapacity));
  }
}

setNull at the boundary

@ParameterizedTest
@MethodSource({"vectorCreatorProvider"})
public void testSetNullAtViewBufferBoundary(
    Function<BufferAllocator, BaseVariableWidthViewVector> vectorCreator) {
  try (final BaseVariableWidthViewVector vector = vectorCreator.apply(allocator)) {
    vector.allocateNew();
    final int valueCapacity = vector.getValueCapacity();
    for (int i = 0; i <= valueCapacity; i++) {
      vector.setNull(i);
    }
    vector.setValueCount(valueCapacity + 1);
    assertTrue(vector.getValueCapacity() > valueCapacity);
    assertTrue(vector.isNull(valueCapacity));
  }
}

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

@mbutrovich added coverage for both additional paths: setNull and setValueCount/fillEmpties at the view-buffer boundary. The production fix is unchanged and his just closes the missing regression coverage. Let me know. thanks!

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));
}
}

@ParameterizedTest
@MethodSource({"vectorCreatorProvider"})
public void testSetValueCountFillsEmptiesAtViewBufferBoundary(
Function<BufferAllocator, BaseVariableWidthViewVector> vectorCreator) {
try (final BaseVariableWidthViewVector vector = vectorCreator.apply(allocator)) {
vector.allocateNew();
final int valueCapacity = vector.getValueCapacity();

vector.setSafe(valueCapacity - 1, "x".getBytes(StandardCharsets.UTF_8));
vector.setValueCount(valueCapacity + 1);

assertTrue(vector.getValueCapacity() > valueCapacity);
assertTrue(vector.isNull(valueCapacity));
}
}

@ParameterizedTest
@MethodSource({"vectorCreatorProvider"})
public void testSetNullAtViewBufferBoundary(
Function<BufferAllocator, BaseVariableWidthViewVector> vectorCreator) {
try (final BaseVariableWidthViewVector vector = vectorCreator.apply(allocator)) {
vector.allocateNew();
final int valueCapacity = vector.getValueCapacity();

for (int i = 0; i <= valueCapacity; i++) {
vector.setNull(i);
}
vector.setValueCount(valueCapacity + 1);

assertTrue(vector.getValueCapacity() > valueCapacity);
assertTrue(vector.isNull(valueCapacity));
}
}

@Test
public void testNullableVarType1() {

Expand Down
Loading