-
Notifications
You must be signed in to change notification settings - Fork 1.1k
parquet: Optimized ByteArrayReader, Add UTF-8 Validation (#1040) #1082
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
585d0f5
Optimized ByteArrayReader (#1040)
tustvold 503f31f
Fix arrow_array_reader benchmark
tustvold 38da212
Allow running subset of arrow_array_reader benchmarks
tustvold 3d59a4c
Faster UTF-8 validation
tustvold f510f8e
Tweak null handling
tustvold 9626728
Add license
tustvold 014be9f
Merge remote-tracking branch 'upstream/master' into string-array-reader
tustvold 0ba1ca7
Refine `ValuesBuffer::pad_nulls`
tustvold 23887f5
Tweak error handling
tustvold 7812799
Use page null count if available
tustvold 2057048
Merge remote-tracking branch 'upstream/master' into string-array-reader
tustvold 9f6bcac
Doc comments
tustvold 8e27ce2
Test DELTA_BYTE_ARRAY encoding
tustvold a12babb
Support legacy Encoding::PLAIN_DICTIONARY
tustvold 971622c
Add OffsetBuffer unit tests
tustvold dbf7b56
More tests
tustvold cf099c3
Fix lint
tustvold c941606
Review feedback
tustvold File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,13 +29,22 @@ impl<I: OffsetSizeTrait + ScalarValue> OffsetBuffer<I> { | |
| self.offsets.len() - 1 | ||
| } | ||
|
|
||
| /// If `validate_utf8` this verifies that the first character of `data` is | ||
| /// the start of a UTF-8 codepoint | ||
| /// | ||
| /// Note: This does not verify that the entirety of `data` is valid | ||
| /// UTF-8. This should be done by calling [`Self::values_as_str`] after | ||
| /// all data has been written | ||
| pub fn try_push(&mut self, data: &[u8], validate_utf8: bool) -> Result<()> { | ||
| if validate_utf8 { | ||
| if let Err(e) = std::str::from_utf8(data) { | ||
| return Err(ParquetError::General(format!( | ||
| "encountered non UTF-8 data: {}", | ||
| e | ||
| ))); | ||
| if let Some(&b) = data.first() { | ||
| // A valid code-point iff it does not start with 0b10xxxxxx | ||
| // Bit-magic taken from `std::str::is_char_boundary` | ||
| if (b as i8) < -0x40 { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| return Err(ParquetError::General( | ||
| "encountered non UTF-8 data".to_string(), | ||
| )); | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -68,6 +77,16 @@ impl<I: OffsetSizeTrait + ScalarValue> OffsetBuffer<I> { | |
| Ok(()) | ||
| } | ||
|
|
||
| /// Returns the values buffer as a string slice, returning an error | ||
| /// if it is invalid UTF-8 | ||
| /// | ||
| /// `start_offset` is the offset in bytes from the start | ||
| pub fn values_as_str(&self, start_offset: usize) -> Result<&str> { | ||
| std::str::from_utf8(&self.values.as_slice()[start_offset..]).map_err(|e| { | ||
tustvold marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ParquetError::General(format!("encountered non UTF-8 data: {}", e)) | ||
| }) | ||
| } | ||
|
|
||
| pub fn into_array( | ||
| self, | ||
| null_buffer: Option<Buffer>, | ||
|
|
@@ -84,7 +103,7 @@ impl<I: OffsetSizeTrait + ScalarValue> OffsetBuffer<I> { | |
|
|
||
| let data = match cfg!(debug_assertions) { | ||
| true => array_data_builder.build().unwrap(), | ||
| false => unsafe { array_data_builder.build_unchecked() } | ||
| false => unsafe { array_data_builder.build_unchecked() }, | ||
| }; | ||
|
|
||
| make_array(data) | ||
|
|
||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for anyone else following along, I double checked the code and
validate_utf8is disabled forDataType::Binaryas one would expect. It is always enabled forDataType::Utf8