alamb commented on code in PR #7513: URL: https://github.com/apache/arrow-rs/pull/7513#discussion_r2113861230
########## arrow-select/src/filter.rs: ########## @@ -550,56 +671,18 @@ fn filter_boolean(array: &BooleanArray, predicate: &FilterPredicate) -> BooleanA BooleanArray::from(data) } -#[inline(never)] -fn filter_native<T: ArrowNativeType>(values: &[T], predicate: &FilterPredicate) -> Buffer { - assert!(values.len() >= predicate.filter.len()); - - match &predicate.strategy { - IterationStrategy::SlicesIterator => { - let mut buffer = Vec::with_capacity(predicate.count); - for (start, end) in SlicesIterator::new(&predicate.filter) { - buffer.extend_from_slice(&values[start..end]); - } - buffer.into() - } - IterationStrategy::Slices(slices) => { - let mut buffer = Vec::with_capacity(predicate.count); - for (start, end) in slices { - buffer.extend_from_slice(&values[*start..*end]); - } - buffer.into() - } - IterationStrategy::IndexIterator => { - let iter = IndexIterator::new(&predicate.filter, predicate.count).map(|x| values[x]); - - // SAFETY: IndexIterator is trusted length - unsafe { MutableBuffer::from_trusted_len_iter(iter) }.into() - } - IterationStrategy::Indices(indices) => { - let iter = indices.iter().map(|x| values[*x]); - iter.collect::<Vec<_>>().into() - } - IterationStrategy::All | IterationStrategy::None => unreachable!(), - } -} - /// `filter` implementation for primitive arrays fn filter_primitive<T>(array: &PrimitiveArray<T>, predicate: &FilterPredicate) -> PrimitiveArray<T> where T: ArrowPrimitiveType, { - let values = array.values(); - let buffer = filter_native(values, predicate); - let mut builder = ArrayDataBuilder::new(array.data_type().clone()) - .len(predicate.count) - .add_buffer(buffer); - - if let Some((null_count, nulls)) = filter_null_mask(array.nulls(), predicate) { - builder = builder.null_count(null_count).null_bit_buffer(Some(nulls)); - } + let builder = PrimitiveBuilder::<T>::with_capacity(predicate.count); Review Comment: No it is not necessary to change the original implementations -- I reworked the existing filter kernels in this PR so that I reuse the existing tests and have confidence in the correctness of the approach. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: github-unsubscr...@arrow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org