Skip to content
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

Convince the compiler to auto-vectorize the range check in parquet DictionaryBuffer #4453

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions parquet/src/arrow/buffer/dictionary_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,15 @@ impl<K: ScalarValue + ArrowNativeType + Ord, V: ScalarValue + OffsetSizeTrait>
let min = K::from_usize(0).unwrap();
let max = K::from_usize(values.len()).unwrap();

// It may be possible to use SIMD here
if keys.as_slice().iter().any(|x| *x < min || *x >= max) {
// using copied and fold gets auto-vectorized since rust 1.70
// all/any would allow early exit on invalid values
// but in the happy case all values have to be checked anyway
if !keys
.as_slice()
.iter()
.copied()
.fold(true, |a, x| a && x >= min && x < max)
{
return Err(general_err!(
"dictionary key beyond bounds of dictionary: 0..{}",
values.len()
Expand Down