Repository navigation
fix: Correctly subscript ViewArrayAsBytes, ViewArrayAsFixedSizeBytes and ViewBinaryViewArrayAsBytes with offset - #1016
Merged
Conversation
…ytes and ViewBinaryViewArrayAsBytes with offset operator[] on these views passed the logical index straight to RandomAccessRange::get(), which expects a physical index, so subscripting a sliced array returned elements from the start of the buffer. Add the range offset, as ViewArrayAs<T> already does.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1016 +/- ##
=======================================
Coverage 78.55% 78.56%
=======================================
Files 106 106
Lines 17297 17300 +3
Branches 2066 2066
=======================================
+ Hits 13587 13591 +4
Misses 2446 2446
+ Partials 1264 1263 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1015
What changed
operator[]inViewArrayAsBytes,ViewBinaryViewArrayAsBytesandViewArrayAsFixedSizeBytes(src/nanoarrow/hpp/view.hpp) now passesrange_.offset + itoRandomAccessRange::get(), the same asViewArrayAs<T>::operator[]already does.src/nanoarrow/hpp/view_test.cc, one per view. Each sets offset 2 and length 2 and checksview[0]andview[1]through both theArrowArrayandArrowArrayViewconstructors. The BinaryView test uses a string longer than the inline size, so it also covers the variadic-buffer path.Why
view[i]passed the logical index straight toRandomAccessRange::get(), which takes a physical index. On a sliced array (offset > 0),view[0]returned the first element of the underlying buffer instead of the first element of the slice. Iteration already respected the offset, so the two disagreed. This change does not add bounds checking tooperator[].How it was tested
cmake --build buildfollowed byctest -R "^NanoarrowHppTest": 15 of 15 tests pass.ctest -Rfor the three new tests: 3 of 3 pass.git diff --check upstream/main: pass.--dry-run --Werror) and codespell 2.2.5 on the changed files: clean.pre-commit run --all-fileswas not run.