[Java] VectorSchemaRoot.slice() throws for NullVector
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
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
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.
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.
take
Issue resolved by pull request 44631 https://github.com/apache/arrow/pull/44631