You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "viirya (via GitHub)" <gi...@apache.org> on 2024/05/09 21:52:43 UTC

[PR] GH-41609: [Java] Initialize non empty offset buffer for variable-size layout before exporting [arrow]

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

   <!--
   Thanks for opening a pull request!
   If this is your first pull request you can find detailed information on how 
   to contribute here:
     * [New Contributor's Guide](https://arrow.apache.org/docs/dev/developers/guide/step_by_step/pr_lifecycle.html#reviews-and-merge-of-the-pull-request)
     * [Contributing Overview](https://arrow.apache.org/docs/dev/developers/overview.html)
   
   
   If this is not a [minor PR](https://github.com/apache/arrow/blob/main/CONTRIBUTING.md#Minor-Fixes). Could you open an issue for this pull request on GitHub? https://github.com/apache/arrow/issues/new/choose
   
   Opening GitHub issues ahead of time contributes to the [Openness](http://theapacheway.com/open/#:~:text=Openness%20allows%20new%20users%20the,must%20happen%20in%20the%20open.) of the Apache Arrow project.
   
   Then could you also rename the pull request title in the following format?
   
       GH-${GITHUB_ISSUE_ID}: [${COMPONENT}] ${SUMMARY}
   
   or
   
       MINOR: [${COMPONENT}] ${SUMMARY}
   
   In the case of PARQUET issues on JIRA the title also supports:
   
       PARQUET-${JIRA_ISSUE_ID}: [${COMPONENT}] ${SUMMARY}
   
   -->
   
   ### 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.  
   -->
   
   This is a follow up of https://github.com/apache/arrow/issues/40038. In https://github.com/apache/arrow/issues/40038, we fixed null offset buffer issue for BaseVariableWidthVector. For empty vector, instead of a empty offset buffer which turns to be a null buffer through C Data Interface, we export a non-empty offset which is supposed to contain zero value.
   
   But the initialization code has a bug in the PR https://github.com/apache/arrow/pull/40043, so the offset buffer is not initialized. Note that this is not a regression because the exported vector never works due to null offset buffer.
   
   ### 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.
   -->
   
   Fixed the uninitialized offset buffer of empty `BaseVariableWidthVector`.
   
   ### Are these changes tested?
   
   <!--
   We typically require tests for all PRs in order to:
   1. Prevent the code from being accidentally broken by subsequent changes
   2. Serve as another way to document the expected behavior of the code
   
   If tests are not included in your PR, please explain why (for example, are they covered by existing tests)?
   -->
   
   Added test cases.
   
   ### 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 uncomment the line below and explain which changes are breaking.
   -->
   <!-- **This PR includes breaking changes to public APIs.** -->
   
   <!--
   Please uncomment the line below (and provide explanation) if the changes fix either (a) a security vulnerability, (b) a bug that caused incorrect or invalid data to be produced, or (c) a bug that causes a crash (even when the API contract is upheld). We use this to highlight fixes to issues that may affect users without their knowledge. For this reason, fixing bugs that cause errors don't count, since those are usually obvious.
   -->
   
   No
   
   <!-- **This PR contains a "Critical Fix".** -->


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-41609: [Java] Initialize non empty offset buffer for variable-size layout before exporting [arrow]

Posted by "viirya (via GitHub)" <gi...@apache.org>.
viirya commented on PR #41610:
URL: https://github.com/apache/arrow/pull/41610#issuecomment-2103481591

   Marked it as a draft and will make it ready for review once I submit the fix.


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-41609: [Java] Initialize non empty offset buffer for variable-size layout before exporting [arrow]

Posted by "viirya (via GitHub)" <gi...@apache.org>.
viirya commented on PR #41610:
URL: https://github.com/apache/arrow/pull/41610#issuecomment-2103732519

   Thank you @vibhatha 


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-41609: [Java] Initialize non empty offset buffer for variable-size layout before exporting [arrow]

Posted by "viirya (via GitHub)" <gi...@apache.org>.
viirya commented on PR #41610:
URL: https://github.com/apache/arrow/pull/41610#issuecomment-2103965074

   Let me open an issue at arrow-rs and see if it makes more sense to fix it there.


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-41609: [Java] Initialize non empty offset buffer for variable-size layout before exporting [arrow]

Posted by "viirya (via GitHub)" <gi...@apache.org>.
viirya closed pull request #41610: GH-41609: [Java] Initialize non empty offset buffer for variable-size layout before exporting
URL: https://github.com/apache/arrow/pull/41610


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-41609: [Java] Initialize non empty offset buffer for variable-size layout before exporting [arrow]

Posted by "viirya (via GitHub)" <gi...@apache.org>.
viirya commented on PR #41610:
URL: https://github.com/apache/arrow/pull/41610#issuecomment-2103964293

   Hmm, I think I know why the tests are not failed in Java Arrow.  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 correct without issue?
   
   


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-41609: [Java] Initialize non empty offset buffer for variable-size layout before exporting [arrow]

Posted by "vibhatha (via GitHub)" <gi...@apache.org>.
vibhatha commented on PR #41610:
URL: https://github.com/apache/arrow/pull/41610#issuecomment-2104148566

   @viirya just for my curiosity, so the error you experience comes when Arrow Java vector is imported in Rust? 


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-41609: [Java] Initialize non empty offset buffer for variable-size layout before exporting [arrow]

Posted by "viirya (via GitHub)" <gi...@apache.org>.
viirya commented on PR #41610:
URL: https://github.com/apache/arrow/pull/41610#issuecomment-2103720979

   @vibhatha I have some fix locally but I am unable to run the C module tests locally on a Mac. I am trying to write these tests that are supposed to fail in CI to verify that.
   
   Once the tests are verified and the fix are submitted, I will make this ready for review.


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-41609: [Java] Initialize non empty offset buffer for variable-size layout before exporting [arrow]

Posted by "vibhatha (via GitHub)" <gi...@apache.org>.
vibhatha commented on PR #41610:
URL: https://github.com/apache/arrow/pull/41610#issuecomment-2103731271

   Thanks for explaining @viirya . If you need help please let me know. 


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-41609: [Java] Initialize non empty offset buffer for variable-size layout before exporting [arrow]

Posted by "vibhatha (via GitHub)" <gi...@apache.org>.
vibhatha commented on PR #41610:
URL: https://github.com/apache/arrow/pull/41610#issuecomment-2103710811

   @viirya just to make sure I understand the change here. Are we introducing the required change in this PR itself right?
   
   And these test cases supposed to fail without that fix? 


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-41609: [Java] Initialize non empty offset buffer for variable-size layout before exporting [arrow]

Posted by "viirya (via GitHub)" <gi...@apache.org>.
viirya commented on PR #41610:
URL: https://github.com/apache/arrow/pull/41610#issuecomment-2104637967

   > @viirya just for my curiosity, so the error you experience comes when Arrow Java vector is imported in Rust?
   
   Yes


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-41609: [Java] Initialize non empty offset buffer for variable-size layout before exporting [arrow]

Posted by "viirya (via GitHub)" <gi...@apache.org>.
viirya commented on PR #41610:
URL: https://github.com/apache/arrow/pull/41610#issuecomment-2106675772

   I fixed the issue at arrow-rs by https://github.com/apache/arrow-rs/issues/5756. So I am closing this. 
   
   Thanks @vibhatha for review.


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org