neilconway commented on code in PR #11206:
URL: https://github.com/apache/arrow-rs/pull/11206#discussion_r4116125435
##########
arrow-select/src/filter.rs:
##########
@@ -199,7 +199,38 @@ pub fn prep_null_mask_filter(filter: &BooleanArray) ->
BooleanArray {
/// assert_eq!(c, &Int32Array::from(vec![5, 8]));
/// ```
pub fn filter(values: &dyn Array, predicate: &BooleanArray) ->
Result<ArrayRef, ArrowError> {
- let mut filter_builder = FilterBuilder::new(predicate);
+ // SAFETY: the count is computed from `predicate` itself.
+ unsafe { filter_with_count(values, predicate, predicate.true_count()) }
+}
+
+/// [`filter`] for a `predicate` whose number of selected rows is already
known.
+///
+/// For callers that already know the total number of selected rows, this is
+/// more efficient than calling `filter` directly.
+///
+/// # Safety
+///
+/// `count` must equal [`BooleanArray::true_count`] of `predicate`; see
+/// [`FilterBuilder::new_with_count`].
+///
+/// # Example
+/// ```rust
+/// # use arrow_array::{Int32Array, BooleanArray};
+/// # use arrow_select::filter::filter_with_count;
+/// let array = Int32Array::from(vec![5, 6, 7, 8, 9]);
+/// let filter_array = BooleanArray::from(vec![true, false, false, true,
false]);
+/// // SAFETY: the count matches the mask.
+/// let c = unsafe { filter_with_count(&array, &filter_array, 2) }.unwrap();
+/// let c = c.as_any().downcast_ref::<Int32Array>().unwrap();
+/// assert_eq!(c, &Int32Array::from(vec![5, 8]));
+/// ```
+pub unsafe fn filter_with_count(
Review Comment:
Sure -- I made this change and updated the docs for `filter` and
`filter_record_batch` to point at the new API.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]