Skip to content

Commit

Permalink
Minor: Use upstream BooleanArray::true_count (#4129)
Browse files Browse the repository at this point in the history
  • Loading branch information
alamb authored Nov 7, 2022
1 parent a9add0e commit 3892a1f
Showing 1 changed file with 1 addition and 22 deletions.
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

0 comments on commit 3892a1f

Please sign in to comment.