Repository navigation
feat: add QueryResult::data_str to read results without copying - #59
Merged
ShawnChen-Sirius merged 1 commit intoSep 30, 2026
Merged
Conversation
The only ways to get a result as text were data_utf8(), which copies the whole buffer into a new String, or data_utf8_lossy(). data_str() checks the bytes in place and hands back a &str into the result buffer. On a 92MB JSONEachRow result it takes ~6ms vs ~45ms for data_utf8, and skips the 92MB allocation. Adds Error::InvalidUtf8 for when the data isn't valid UTF-8.
ShawnChen-Sirius
approved these changes
Sep 30, 2026
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.
Right now if you want a query result as text you've got
data_utf8(), which copies the whole result buffer into a newString, ordata_utf8_lossy(). There's no way to just look at it as a&str.This adds
QueryResult::data_str() -> Result<&str>. It checks the bytes are valid UTF-8 in place and borrows straight from the result buffer, so nothing gets allocated.On a 92MB
JSONEachRowresult (3M rows):data_utf8(): ~45ms, plus a 92MB allocationdata_str(): ~6ms, no allocationAlso:
Error::InvalidUtf8for when the data isn't valid UTF-8 (binary formats likeRowBinaryorParquet).Erroris#[non_exhaustive]so it's not a breaking change.data_utf8()is unchanged, its docs now point atdata_str()if you don't need an owned string.examples/03_query_results.rsanddocs/examples.mdshow it.Tests cover a normal result (and check it points at the same memory as
data_ref()), a binary result returningInvalidUtf8, and an empty result.Note
Add
QueryResult::data_strto return result text as a borrowed&strdata_strmethod that validates the result buffer in place withstd::str::from_utf8and returns a borrowed string slice without allocating. See query_result.rs.Error::InvalidUtf8variant carryingstd::str::Utf8Errorfor results that are not valid UTF-8, such as binary output. See error.rs.Macroscope summarized 085dcd2.