Skip to content

Support Utf8View and BinaryView in substring - #10672

Open
1fanwang wants to merge 2 commits into
apache:mainfrom
1fanwang:feat/substring-view-types
Open

Support Utf8View and BinaryView in substring#10672
1fanwang wants to merge 2 commits into
apache:mainfrom
1fanwang:feat/substring-view-types

Conversation

@1fanwang

Copy link
Copy Markdown

Which issue does this PR close?

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.

Tests
$ 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

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 <1fannnw@gmail.com>
@github-actions github-actions Bot added arrow Changes to the arrow crate arrow-string labels Aug 13, 2026
@Jefffrey Jefffrey added the enhancement Any new improvement worthy of a entry in the changelog label Aug 13, 2026
Comment thread arrow-string/src/substring.rs Outdated
Comment thread arrow-string/src/substring.rs Outdated
Comment thread arrow-string/src/substring.rs Outdated

#[test]
fn binary_view_matches_binary() {
let values: Vec<Option<&[u8]>> = vec![Some(b"hello world"), Some(b""), None, Some(b"abc")];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should add a long one here too

@1fanwang 1fanwang Aug 13, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 336f3d5

}

#[test]
fn string_view_rejects_an_invalid_char_boundary() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we have a positive case, for slicing on a valid boundary that isnt only ascii?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added in 336f3d5

Signed-off-by: 1fanwang <1fannnw@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arrow Changes to the arrow crate arrow-string enhancement Any new improvement worthy of a entry in the changelog

Projects

None yet

Development

Successfully merging this pull request may close these issues.

substring does not support Utf8View or BinaryView

2 participants