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

Minor: Use upstream BooleanArray::true_count #4129

Merged
merged 1 commit into from
Nov 7, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ impl ArrowPredicate for DatafusionArrowPredicate {
Ok(array) => {
if let Some(mask) = array.as_any().downcast_ref::<BooleanArray>() {
let bool_arr = BooleanArray::from(mask.data().clone());
let num_filtered = bool_arr.len() - true_count(&bool_arr);
let num_filtered = bool_arr.len() - bool_arr.true_count();
self.rows_filtered.add(num_filtered);
timer.stop();
Ok(bool_arr)
Expand All @@ -151,27 +151,6 @@ impl ArrowPredicate for DatafusionArrowPredicate {
}
}

/// Return the number of non null true vaulues in an array
// TODO remove when https://github.com/apache/arrow-rs/issues/2963 is released
fn true_count(arr: &BooleanArray) -> usize {
match arr.data().null_buffer() {
Some(nulls) => {
let null_chunks = nulls.bit_chunks(arr.offset(), arr.len());
let value_chunks = arr.values().bit_chunks(arr.offset(), arr.len());
null_chunks
.iter()
.zip(value_chunks.iter())
.chain(std::iter::once((
null_chunks.remainder_bits(),
value_chunks.remainder_bits(),
)))
.map(|(a, b)| (a & b).count_ones() as usize)
.sum()
}
None => arr.values().count_set_bits_offset(arr.offset(), arr.len()),
}
}

/// A candidate expression for creating a `RowFilter` contains the
/// expression as well as data to estimate the cost of evaluating
/// the resulting expression.
Expand Down