This is an automated email from the ASF dual-hosted git repository.
Jefffrey pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-rs.git
The following commit(s) were added to refs/heads/main by this push:
new ee30b61b00 perf: allow users to skip utf8 validation (#10319)
ee30b61b00 is described below
commit ee30b61b00df8a590c4c45c490fbecc0962cfba5
Author: RIchard Baah <[email protected]>
AuthorDate: Wed Jul 15 19:48:15 2026 -0400
perf: allow users to skip utf8 validation (#10319)
# Which issue does this PR close?
<!--
We generally require a GitHub issue to be filed for all bug fixes and
enhancements and this helps us generate change logs for our releases.
You can link an issue to this PR using the GitHub syntax.
-->
- Closes #10275.
# Rationale for this change
see #10275
<!--
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.
-->
# What changes are included in this PR?
adds `with_validate_utf8_flag()` which allows callers to create
`RowParser` with `validate_utf8` set to false
<!--
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.
-->
# Are these changes tested?
yes a test is included to validate a round-trip behaves as expected.
<!--
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)?
If this PR claims a performance improvement, please include evidence
such as benchmark results.
-->
# Are there any user-facing changes?
`RowConverter` has a new method that skips utf8 checks.
<!--
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 call them out.
-->
---
arrow-row/src/lib.rs | 38 ++++++++++++++++++++++++++++++++++++++
1 file changed, 38 insertions(+)
diff --git a/arrow-row/src/lib.rs b/arrow-row/src/lib.rs
index 0773f08f26..f1cb42d3d8 100644
--- a/arrow-row/src/lib.rs
+++ b/arrow-row/src/lib.rs
@@ -1256,6 +1256,14 @@ impl RowConverter {
RowParser::new(Arc::clone(&self.fields))
}
+ /// Like [`Self::parser`] but skips UTF-8 validation on decode.
+ ///
+ /// # Safety
+ /// The caller must ensure all row bytes contain valid UTF-8 for string
columns.
+ pub unsafe fn parser_skip_utf8_validation(&self) -> RowParser {
+ unsafe { RowParser::with_skip_utf8_validate(Arc::clone(&self.fields)) }
+ }
+
/// Returns the size of this instance in bytes
///
/// Includes the size of `Self`.
@@ -1282,6 +1290,18 @@ impl RowParser {
},
}
}
+ /// Like [`RowConverter::parser`] but skips UTF-8 validation on decode.
+ ///
+ /// # Safety
+ /// The caller must ensure all row bytes contain valid UTF-8 for string
columns.
+ unsafe fn with_skip_utf8_validate(fields: Arc<[SortField]>) -> Self {
+ Self {
+ config: RowConfig {
+ fields,
+ validate_utf8: false,
+ },
+ }
+ }
/// Creates a [`Row`] from the provided `bytes`.
///
@@ -6676,6 +6696,24 @@ mod tests {
assert_eq!(rows_iter.next_back(), None);
}
+ /// Round-trip through `with_skip_utf8_validate` confirms skipping
validation preserves values.
+ #[test]
+ fn test_row_parser_skip_utf8_validation_roundtrip() {
+ let converter =
RowConverter::new(vec![SortField::new(DataType::Utf8)]).unwrap();
+ let array = StringArray::from(vec!["arrow", "rust"]);
+ let rows = converter.convert_columns(&[Arc::new(array) as _]).unwrap();
+ let binary = rows.try_into_binary().expect("fits in i32 offsets");
+
+ // SAFETY: bytes come from this RowConverter and are known-valid UTF-8.
+ let parser = unsafe {
RowParser::with_skip_utf8_validate(Arc::clone(&converter.fields)) };
+
+ let decoded = converter
+ .convert_rows(binary.iter().map(|b| parser.parse(b.unwrap())))
+ .unwrap();
+ let got: Vec<_> =
decoded[0].as_string::<i32>().iter().flatten().collect();
+ assert_eq!(got, vec!["arrow", "rust"]);
+ }
+
#[test]
fn row_iter_next_back() {
let row_converter =
RowConverter::new(vec![SortField::new(DataType::UInt8)]).unwrap();