Skip to content

Commit

Permalink
GH-44344: [Java] Fix VectorSchemaRoot.getTransferPair for NullVector
Browse files Browse the repository at this point in the history
Signed-off-by: Maksim Yegorov <[email protected]>

Code review comment: Add javadoc to getAllocator base method.

mvn spotless:apply linter

retrigger checks
  • Loading branch information
maksimyego-db authored and myegorov committed Nov 5, 2024
1 parent 4274db8 commit 00f7573
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,16 @@ public boolean allocateNewSafe() {
@Override
public void reAlloc() {}

/*
* IMPORTANT NOTE
* It's essential that NullVector (and ZeroVector) do not require BufferAllocator for any data storage.
* However, some methods of the parent interface may require passing in a BufferAllocator, even if null.
*
* @return null
*/
@Override
public BufferAllocator getAllocator() {
throw new UnsupportedOperationException("Tried to get allocator from NullVector");
return null;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ public interface ValueVector extends Closeable, Iterable<ValueVector> {
*/
void reAlloc();

/**
* Get the allocator associated with the vector. CAVEAT: Some ValueVector subclasses (e.g.
* NullVector) do not require an allocator for data storage and may return null.
*
* @return Returns nullable allocator.
*/
BufferAllocator getAllocator();

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,31 @@ public void testWithEmptyVector() {
toDUV.clear();
}

@Test
public void testWithNullVector() {
int valueCount = 123;
int startIndex = 10;
NullVector fromNullVector = new NullVector("nullVector");
fromNullVector.setValueCount(valueCount);
TransferPair transferPair = fromNullVector.getTransferPair(fromNullVector.getAllocator());
transferPair.splitAndTransfer(startIndex, valueCount - startIndex);
NullVector toNullVector = (NullVector) transferPair.getTo();

assertEquals(valueCount - startIndex, toNullVector.getValueCount());
// no allocations to clear for NullVector
}

@Test
public void testWithZeroVector() {
ZeroVector fromZeroVector = new ZeroVector("zeroVector");
TransferPair transferPair = fromZeroVector.getTransferPair(fromZeroVector.getAllocator());
transferPair.splitAndTransfer(0, 0);
ZeroVector toZeroVector = (ZeroVector) transferPair.getTo();

assertEquals(0, toZeroVector.getValueCount());
// no allocations to clear for ZeroVector
}

@Test /* VarCharVector */
public void test() throws Exception {
try (final VarCharVector varCharVector = new VarCharVector("myvector", allocator)) {
Expand Down

0 comments on commit 00f7573

Please sign in to comment.