| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
Sorry, something went wrong.
There was a problem hiding this comment.
It's the similar fix as for valueBuffer afair. It sounds good to me.
Sorry, something went wrong.
|
@Yicong-Huang sorry to be a pain, can you please rebase ? Thanks ! |
Sorry, something went wrong.
Thanks @jbonofre . I did rebase but I think the root error in this change is BaseVariableWidthVector's offsetBuffer is allocated to be 0 capacity when it is empty. Writing the offset 0 to it would be invalid. It is also not easy to increase the allocation as all tests are written against that. Could you advise on this case? |
Sorry, something went wrong.
|
@Yicong-Huang can you please rebase again ? Sorry about that. Else I can do the rebase for you. |
Sorry, something went wrong.
Thanks. Just merged the latest master back in. |
Sorry, something went wrong.
|
@Yicong-Huang thanks a lot ! I would like to include this fix on Arrow Java 19.0.0 release 😄 |
Sorry, something went wrong.
Thanks that'd be nice! I can work with you closely on fixing this. However I see it is still failing CI, I think the original issue is still persist
Do you have any suggestions? |
Sorry, something went wrong.
|
I did a new pass on the PR and I don't think it's correct.
I think the problem is that the PR changes setReaderAndWriterIndex() to always use (valueCount + 1) + OFFSET_WIDTH for the offset buffer. The text expectations need to be adjusted by +4 bytes (one 32-bit offset) for the affected cases. |
Sorry, something went wrong.
There was a problem hiding this comment.
See my previous comment about the tests.
Sorry, something went wrong.
|
Thanks a lot, @jbonofre, for the new pass! I've reworked the PR based on your feedback. Here's a summary of the changes:
You were right that the test expectations for empty vectors should stay at 0. my earlier approach of allocating in the constructor was causing cascading issues. I've reverted that entirely. The constructor now continues to use allocator.getEmpty() as before. The actual fix is now just in setReaderAndWriterIndex(): instead of setting offsetBuffer.writerIndex(0) when valueCount == 0, we always set it to (valueCount + 1) * OFFSET_WIDTH. There's a capacity check before that — if the buffer is too small (e.g. loaded from IPC with an empty offset buffer), we allocate just enough space on demand.
For the memory leaks in test you flagged, I fixed one failing case, the ResultSetUtilityTest: the empty vector now allocates a 4-byte offset buffer in setReaderAndWriterIndex(), and the test wasn't closing the iterator and root properly. I can also include the same fix (clean up after test) to make the other tests more correct, if needed. |
Sorry, something went wrong.
|
@Yicong-Huang awesome ! Thanks ! I'm doing a new pass. |
Sorry, something went wrong.
There was a problem hiding this comment.
LGTM with the latest changes.
Thanks !
Sorry, something went wrong.
…columns `checkBinaryOffsetsBuffer` always required at least `sizeof(offset_type)` bytes (the `+1` sentinel entry), even when `chunk.length() == 0`. Apache Arrow Java < 19.0.0, as bundled with Apache Spark, emits a 0-byte offsets buffer for empty String/Binary children (e.g. when every map row is empty so the key child has zero elements). Every other Arrow implementation (arrow-cpp, pyarrow, arrow-rs, Arrow Java >= 19) accepts this; arrow-java fixed the non-compliance in apache/arrow-java#989. When `chunk.length() == 0`, every caller's iteration loop is skipped and no byte of the offsets buffer is ever accessed, so requiring any bytes was a spec-pedantry regression, not a security necessity (confirmed by thorough code review of all 8 call sites). The `checkValidityBitmap` call inside `checkBinaryOffsetsBuffer` is unconditional and continues to validate the null bitmap. Fix: gate the `+1` sentinel on `chunk.length() > 0`; when the column is empty, set `count_plus_one = 0` so any buffer size (including 0 bytes) passes the check. Regression tests in `04356_arrow_empty_string_offsets.sh` cover: standalone empty `String` column, `Map(String, Int32)` with all-empty rows, and `Array(String)` with all-empty rows — all using the 0-byte offsets buffer that Arrow Java < 19.0.0 produces. Closes: ClickHouse#107749 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
| Back | FazBrowse Home | New Git URL |
What's Changed
Fix BaseVariableWidthVector/BaseLargeVariableWidthVector IPC serialization when valueCount is 0.
Problem
When valueCount == 0, setReaderAndWriterIndex() was setting offsetBuffer.writerIndex(0), which means readableBytes() == 0. IPC serializer uses readableBytes() to determine buffer size, so 0 bytes were written to the IPC stream. This crashes IPC readers in other libraries because Arrow spec requires offset buffer to have at least one entry [0].
This is a follow-up to #967 which fixed the same issue in ListVector/LargeListVector.
Fix
Modify setReaderAndWriterIndex() to always use (valueCount + 1) * OFFSET_WIDTH for the offset buffer's writerIndex, moved outside the if/else branch. When the offset buffer capacity is insufficient (e.g., empty buffer from constructor or loaded via loadFieldBuffers()), it reallocates a properly sized buffer on demand.
Testing
Added tests for empty VarCharVector and LargeVarCharVector verifying offset buffer has correct readableBytes() after setValueCount(0).
Closes #343