Skip to content
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

GH-44344: [Java] fix VectorSchemaRoot.getTransferPair for NullVector #44631

Merged
merged 1 commit into from
Nov 6, 2024
Merged
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 @@ -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;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I haven't added a test to check this returns null because this seems to me an implementation detail. Please let me know if you think otherwise.

}

@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
Loading