Repository navigation
Support Utf8View and BinaryView in substring - #10672
Merged
Merged
Conversation
substring() handles Utf8, LargeUtf8, Binary, LargeBinary, FixedSizeBinary and Dictionary, but rejects the view types with "substring does not support type Utf8View". The sibling kernels in this crate already take them: length, bit_length, like and concat_elements all have Utf8View arms. Views carry their own offsets rather than sharing one value buffer, so the byte range is computed per element and the result is built through the view builder. The utf-8 boundary check applies to Utf8View as it does to Utf8; the offset in that error is per element, since there is no shared buffer to index. Tested by comparing the view result against the Utf8 and Binary results over the same inputs, including empty strings, nulls, values longer than the twelve-byte inline limit, zero length, and starts past either end. Signed-off-by: 1fanwang <[email protected]>
Jefffrey
reviewed
Aug 13, 2026
|
|
||
| #[test] | ||
| fn binary_view_matches_binary() { | ||
| let values: Vec<Option<&[u8]>> = vec![Some(b"hello world"), Some(b""), None, Some(b"abc")]; |
Contributor
There was a problem hiding this comment.
should add a long one here too
| } | ||
|
|
||
| #[test] | ||
| fn string_view_rejects_an_invalid_char_boundary() { |
Contributor
There was a problem hiding this comment.
do we have a positive case, for slicing on a valid boundary that isnt only ascii?
Signed-off-by: 1fanwang <[email protected]>
Jefffrey
approved these changes
Aug 13, 2026
Contributor
|
thanks @1fanwang |
MassivePizza
pushed a commit
to massive-com/arrow-rs
that referenced
this pull request
Aug 19, 2026
# Which issue does this PR close? - Closes apache#10671. # Rationale for this change `substring()` takes `Utf8`, `LargeUtf8`, `Binary`, `LargeBinary`, `FixedSizeBinary` and `Dictionary`, but rejects the view types, so a caller holding a `StringViewArray` has to cast to `Utf8` first and pay for the copy. The other string kernels in this crate already accept them: `length`, `bit_length`, `like` and `concat_elements` all have `Utf8View` arms. # What changes are included in this PR? `Utf8View` and `BinaryView` arms. Views carry their own offsets rather than sharing one value buffer, so the byte range is computed per element and the result is built through the view builder. The existing `Dictionary` arm recurses, so a dictionary of views now works too. The utf-8 boundary check applies to `Utf8View` the same way it does to `Utf8`. The offset quoted in that error is per element, because there is no shared buffer to index into. # Are these changes tested? Yes. The view result is compared against the `Utf8` and `Binary` result for the same inputs, so the two paths cannot drift: empty strings, nulls, values longer than the twelve-byte inline limit, zero length, lengths past the end, and starts past either end in both directions. Plus the boundary error and a dictionary of views. The cross-check earned its keep — it caught the error offsets differing between the two paths, which is what prompted the note above. <details><summary>Tests</summary> ``` $ cargo test -p arrow-string 186 passed; 0 failed ``` Removing the two new match arms fails exactly the four new tests, so they cannot pass vacuously: ``` test substring::tests::string_view_matches_utf8 ... FAILED test substring::tests::binary_view_matches_binary ... FAILED test substring::tests::string_view_rejects_an_invalid_char_boundary ... FAILED test substring::tests::dictionary_of_string_view ... FAILED ``` </details> --------- Signed-off-by: 1fanwang <[email protected]>
Phoenix500526
pushed a commit
to Phoenix500526/arrow-rs
that referenced
this pull request
Nov 4, 2026
…ng (apache#12006) # Which issue does this PR close? - Follow-up to apache#10995, which made the other `substring` arms saturate large lengths. The `Utf8View` / `BinaryView` arms added in apache#10672 were missed. # Rationale for this change `view_substring_range` computed the end as `new_start.saturating_add(length as i64)`. For `length > i64::MAX` the cast wraps negative, so the end lands before the start: - `substring(&BinaryViewArray["hello"], 1, Some(u64::MAX))` panics with `slice index starts at 1 but ends at 0`; - the same call on `StringViewArray` returns `ComputeError("The offset 9223372036854775808 is at an invalid utf-8 boundary.")`. `LargeUtf8` and `LargeBinary` return `"ello"` for the same input. # What changes are included in this PR? Use the existing `u64_to_i64_saturating(length)` in `view_substring_range`, like the other arms. # Are these changes tested? Yes. A new test checks that `Utf8View` matches `LargeUtf8` and `BinaryView` matches `LargeBinary` for several starts (including negative and beyond the end) with lengths `2^63` and `u64::MAX`. # Are there any significant user-facing changes? No. --- AI disclosure: the bug was found and the patch and test drafted with AI assistance (Claude); I reviewed every line, verified the failing test before/after the fix, and ran fmt/clippy/tests for the crate.
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.
Which issue does this PR close?
Rationale for this change
substring()takesUtf8,LargeUtf8,Binary,LargeBinary,FixedSizeBinaryandDictionary, but rejects the view types, so a caller holding aStringViewArrayhas to cast toUtf8first and pay for the copy. The other string kernels in this crate already accept them:length,bit_length,likeandconcat_elementsall haveUtf8Viewarms.What changes are included in this PR?
Utf8ViewandBinaryViewarms. Views carry their own offsets rather than sharing one value buffer, so the byte range is computed per element and the result is built through the view builder. The existingDictionaryarm recurses, so a dictionary of views now works too.The utf-8 boundary check applies to
Utf8Viewthe same way it does toUtf8. The offset quoted in that error is per element, because there is no shared buffer to index into.Are these changes tested?
Yes. The view result is compared against the
Utf8andBinaryresult for the same inputs, so the two paths cannot drift: empty strings, nulls, values longer than the twelve-byte inline limit, zero length, lengths past the end, and starts past either end in both directions. Plus the boundary error and a dictionary of views.The cross-check earned its keep — it caught the error offsets differing between the two paths, which is what prompted the note above.
Tests
Removing the two new match arms fails exactly the four new tests, so they cannot pass vacuously: