Skip to content

Commit

Permalink
Use BitIndexIterator (#2675)
Browse files Browse the repository at this point in the history
  • Loading branch information
viirya committed Sep 7, 2022
1 parent c8bf1ca commit b36bc88
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions arrow/src/compute/kernels/aggregate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use crate::array::{
GenericBinaryArray, GenericStringArray, OffsetSizeTrait, PrimitiveArray,
};
use crate::datatypes::{ArrowNativeType, ArrowNumericType, DataType};
use crate::util::bit_iterator::BitIndexIterator;

/// Generic test for NaN, the optimizer should be able to remove this for integer types.
#[inline]
Expand Down Expand Up @@ -123,9 +124,27 @@ where
.map(|i| unsafe { array.value_unchecked(i) })
.reduce(|acc, item| if cmp(&acc, &item) { item } else { acc })
} else {
let iter = ArrayIter::new(array);
iter.flatten()
.reduce(|acc, item| if cmp(&acc, &item) { item } else { acc })
let null_buffer = array
.data_ref()
.null_buffer()
.map(|b| b.bit_slice(array.offset(), array.len()));
let iter = BitIndexIterator::new(
null_buffer.as_deref().unwrap(),
array.offset(),
array.len(),
);
unsafe {
let idx = iter.reduce(|acc_idx, idx| {
let acc = array.value_unchecked(acc_idx);
let item = array.value_unchecked(idx);
if cmp(&acc, &item) {
idx
} else {
acc_idx
}
});
idx.map(|idx| array.value_unchecked(idx))
}
}
}

Expand Down

0 comments on commit b36bc88

Please sign in to comment.