You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Nullability in schema is not considered in VectorLoader #648
Describe the bug, including details regarding any error messages, version, and platform.
We hit an issue on using VectorLoader to load some Arrow vectors.
java.util.NoSuchElementException
at java.base/java.util.ArrayList$Itr.next(ArrayList.java:970)
at org.apache.arrow.vector.VectorLoader.loadBuffers(VectorLoader.java:104)
at org.apache.arrow.vector.VectorLoader.load(VectorLoader.java:84)
The schema of the VectorSchemaRoot is Schema<_0: Utf8 not null>.
The field vector in the root is Utf8 type, not nullable. As it is Utf8 type, TypeLayout.getTypeBufferCount reports buffer count 3 for it.
The IPC ArrowRecordBatch message to load has one node: ArrowFieldNode [length=1500, nullCount=0], and two buffers:
So when VectorLoader.loadBuffers is trying to load buffers by iterating the buffer list, it assumes there are 3 buffers but actually there are only 2 buffers (null buffer doesn't exist). That's why it hits NoSuchElementException.
I think that an array that in the spec can contain a null bitmap may choose to not allocate the validity buffer (also see the doc). So the Utf8 array with 2 buffers is correct by the spec. The issue looks like that VectorLoader doesn't consider field nullability when loading buffers.
We uses Arrow Java 15.0.2 version. But as I just looked at the current code in this repo, looks like current TypeLayout has this issue still.
Field nullability is irrelevant: it's the actual number of nulls that matters. A nullable vector may still contain no nulls and this case should still apply.
/// The number of observed nulls. Fields with null_count == 0 may choose not
/// to write their physical validity bitmap out as a materialized buffer,
/// instead setting the length of the bitmap buffer to 0.
null_count: long;
It seems that the problem is more that the code loading the buffers should be inserting a zero-length (or possibly null) buffer where the nullability buffer would have gone so that expectations line up.
(Also, note that nothing really validates field nullability so it is very possible to have a non-nullable field and yet still have nulls in the data; IPC code shouldn't rely on field nullability ever IMO.)
Field nullability is irrelevant: it's the actual number of nulls that matters. A nullable vector may still contain no nulls and this case should still apply.
Oh, yes, that's correct. It is not due to the field nullability but actually the null count in the vector. My description is not accurate.
Hmm, after re-thinking it, I wonder if this is a bug actually? Although in the physical memory layout of an array, the null buffer may not be allocated, however, as the message to load is an ipc RecordBatch message, maybe the null buffer cannot be ignored in the message? I.e., at least it needs to be an empty one? If so, then the issue maybe due to the incorrect message produced by somewhere in our code (it seems not from Arrow Java).
Yeah, so seems the issue is that we don't put the entry in the message. The code is not from me. So I may need to take more looks. Thanks for confirming it.
Ah, I see now - there's not an entry, so there's not a buffer generated, and VectorLoader iterates based on fixed knowledge of the type layout, ignoring the entries? In that case yes I think the Java library is right, albeit not very clear about what went wrong.
There are 2 entries in the messages for the data and offset. The null buffer is not. The message is not produced by the Java library, I think. It comes from other internal library. I need to look where it was produced like that.
VectorLoader needs to read 3 entries for the case, so it just hits the NoSuchElementException.
Activity
viirya commentedon Mar 4, 2025
I will open a PR soon.
apacheGH-648: Nullability in schema is not considered in VectorLoader
lidavidm commentedon Mar 4, 2025
Field nullability is irrelevant: it's the actual number of nulls that matters. A nullable vector may still contain no nulls and this case should still apply.
It seems that the problem is more that the code loading the buffers should be inserting a zero-length (or possibly null) buffer where the nullability buffer would have gone so that expectations line up.
lidavidm commentedon Mar 4, 2025
(Also, note that nothing really validates field nullability so it is very possible to have a non-nullable field and yet still have nulls in the data; IPC code shouldn't rely on field nullability ever IMO.)
viirya commentedon Mar 4, 2025
Oh, yes, that's correct. It is not due to the field nullability but actually the null count in the vector. My description is not accurate.
viirya commentedon Mar 4, 2025
Hmm, after re-thinking it, I wonder if this is a bug actually? Although in the physical memory layout of an array, the null buffer may not be allocated, however, as the message to load is an ipc
RecordBatchmessage, maybe the null buffer cannot be ignored in the message? I.e., at least it needs to be an empty one? If so, then the issue maybe due to the incorrect message produced by somewhere in our code (it seems not from Arrow Java).lidavidm commentedon Mar 4, 2025
AIUI, yes, there still needs to be an entry in the list of buffers in the Flatbuffer metadata, even if there is no memory allocated.
viirya commentedon Mar 4, 2025
Yeah, so seems the issue is that we don't put the entry in the message. The code is not from me. So I may need to take more looks. Thanks for confirming it.
lidavidm commentedon Mar 4, 2025
Though, from the exception, it seems actually the issue is that there's more entries than buffers, not the other way around?
lidavidm commentedon Mar 4, 2025
Ah, I see now - there's not an entry, so there's not a buffer generated, and VectorLoader iterates based on fixed knowledge of the type layout, ignoring the entries? In that case yes I think the Java library is right, albeit not very clear about what went wrong.
viirya commentedon Mar 4, 2025
There are 2 entries in the messages for the data and offset. The null buffer is not. The message is not produced by the Java library, I think. It comes from other internal library. I need to look where it was produced like that.
VectorLoaderneeds to read 3 entries for the case, so it just hits theNoSuchElementException.viirya commentedon Mar 4, 2025
Oh, the error case could be improved than an exception like current one, though. I will open a small PR for it. Sounds good?
lidavidm commentedon Mar 4, 2025
That would be appreciated, yes!
MINOR: Add explicit exception when no more buffer can be read when lo…