arrow icon indicating copy to clipboard operation
arrow copied to clipboard

[Java] VectorSchemaRoot.slice() throws for NullVector

Open maksimyego-db opened this issue 1 year ago • 4 comments

Describe the bug, including details regarding any error messages, version, and platform.

When slicing a VectorSchemaRoot wrapping a NullVector, NullVector.getAllocator() will throw UnsupportedOperationException("Tried to get allocator from NullVector")

It appears that the call could pass in a null for allocator in https://github.com/apache/arrow/blob/release-17.0.0-rc2/java/vector/src/main/java/org/apache/arrow/vector/NullVector.java#L172-L174. Would it make sense to return null instead of throw from NullVector.getAllocator()?

Tangentially related to https://github.com/apache/arrow/issues/30866 that was fixed in https://github.com/apache/arrow/pull/41066 for some vector types.

Component(s)

Java

maksimyego-db avatar Oct 09 '24 02:10 maksimyego-db

This predates my involvement to Arrow, but I think throw is the right way to go. Because we are requesting an attribute which is defined as something we should not support for a NullVector.

cc @lidavidm

vibhatha avatar Oct 09 '24 04:10 vibhatha

Not to lose sight of the original issue: We should be able to slice a VectorSchemaRoot containing NullVectors, like we do for any other ValueVector types. That NullVector does not require a BufferAllocator suggests to me this attribute is optional for any public methods operating on NullVector.

Another alternative is to case match on NullVector in https://github.com/apache/arrow/blob/release-17.0.0-rc2/java/vector/src/main/java/org/apache/arrow/vector/VectorSchemaRoot.java#L340-L341 but that seems like a one off workaround where conceivably any public ValueVector APIs that require the allocator parameter should work on NullVectors.

maksimyego-db avatar Oct 09 '24 16:10 maksimyego-db

I prefer throwing over null since that makes it evident where the failure occurred, but I suppose in context it's preferable over special casing APIs. (And once we have proper @Nullable annotations that should help.) I would be OK returning null so long as this is clearly documented in the base method.

lidavidm avatar Oct 10 '24 06:10 lidavidm

take

myegorov avatar Nov 04 '24 03:11 myegorov

Issue resolved by pull request 44631 https://github.com/apache/arrow/pull/44631

lidavidm avatar Nov 06 '24 00:11 lidavidm