viirya opened a new pull request, #5741:
URL: https://github.com/apache/arrow-rs/pull/5741

   # Which issue does this PR close?
   
   <!--
   We generally require a GitHub issue to be filed for all bug fixes and 
enhancements and this helps us generate change logs for our releases. You can 
link an issue to this PR using the GitHub syntax. For example `Closes #123` 
indicates that this PR will close issue #123.
   -->
   
   Closes #.
   
   # Rationale for this change
    
   <!--
   Why are you proposing this change? If this is already explained clearly in 
the issue then this section is not needed.
   Explaining clearly why changes are proposed helps reviewers understand your 
changes and offer better suggestions for fixes.
   -->
   
   Encountered an issue when importing empty variable-size binary layout array 
(e.g., string) from Java Arrow.
   
   There is difference between Java Arrow and arrow-rs when computing the 
length of data buffer: 
https://github.com/apache/arrow/pull/41610#issuecomment-2103964293
   
   This is how Java Arrow imports an Utf8 array:
   
   ```
   try (ArrowBuf offsets = importOffsets(type, VarCharVector.OFFSET_WIDTH)) {
         final int start = offsets.getInt(0);
         final int end = offsets.getInt(fieldNode.getLength() * (long) 
VarCharVector.OFFSET_WIDTH);
         final int len = end - start;
         ...
   }
   ```
   
   So even the offset buffer is not initialized, for empty array with one 
element offset buffer, `end - start` is always 0 that is the length of data 
buffer. That is why the added roundtrip tests are passed.
   
   But in arrow-rs, it takes the last value of the offset buffer as the length 
of data buffer, i.e., `end`. If the value is not initialized to zero, the 
computed length of data buffer is incorrect.
   
   That is what I found for the first offset value from the 
[spec](https://arrow.apache.org/docs/format/Columnar.html#variable-size-binary-layout):
   
   ```
   Generally the first slot in the offsets array is 0, and the last slot is the 
length of the values array.
   When serializing this layout, we recommend normalizing the offsets to start 
at 0.
   ```
   
   It looks like the first value doesn't have to be 0, although generally it 
is. So seems Java Arrow's approach is (more) correct.
   
   # What changes are included in this PR?
   
   <!--
   There is no need to duplicate the description in the issue here but it is 
sometimes worth providing a summary of the individual changes in this PR.
   -->
   
   Changing the way to compute the length of data buffer when importing an 
empty variable-size binary layout array.
   
   # Are there any user-facing changes?
   
   
   <!--
   If there are user-facing changes then we may require documentation to be 
updated before approving the PR.
   -->
   
   <!---
   If there are any breaking changes to public APIs, please add the `breaking 
change` label.
   -->
   
   No
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to