This is an automated email from the ASF dual-hosted git repository. github-merge-queue[bot] pushed a commit to branch gh-readonly-queue/main/pr-12116-3a2c35683ade21d90f3a317d64f871c3d76c39ab in repository https://gitbox.apache.org/repos/asf/arrow-rs.git
commit 59dac8a4d20e0330aeeea8c895978e85ff2df69d Author: WaterWhisperer <[email protected]> AuthorDate: Sun Nov 8 02:37:47 2026 +0000 docs(arrow-select): document shorter filter predicates (#12116) # Which issue does this PR close? <!-- It is not necessary to raise an issue, but it is encouraged if it is a non-trivial enhancement/bug. If this PR relates to an existing issue, but does not fully resolve it, please change the wording below from "Closes #NNN" to "Relates to #NNN" or "Part of #NNN" to avoid false closing an issue. --> - Closes #12001 # Rationale for this change <!-- Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed. Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes. Please try to explain the problem you are trying to solve in terms of the user-visible behavior, rather than the implementation. --> The API docs do not explain that a shorter filter predicate leaves the remaining rows unselected. # What changes are included in this PR? <!-- There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR. --> Document this behavior on the array and record-batch filtering APIs, including `FilterPredicate`. Update the existing example to use a shorter predicate. # Are these changes tested? <!-- We typically require tests for all PRs in order to: 1. Prevent the code from being accidentally broken by subsequent changes 2. Serve as another way to document the expected behavior of the code If tests are not included in your PR, please explain why (for example, are they covered by existing tests, if so identify these tests)? If this PR claims a performance improvement, please include evidence such as benchmark results. DO NOT simply paste a list of commands ran to verify the code; this is what our CI is for and it pollutes the PR. ONLY explain if testing was included with this PR, or why it wasn't. --> The updated example passes as a doctest. Existing filter tests also pass, including short-predicate coverage in the RunArray test and `fuzz_filter`. # Are there any significant user-facing changes? <!-- Significant user-facing changes include: - Breaking public API change - Significant change to existing functionality (e.g. function returns something different) These need to be explicitly called out to ensure we have proper documentation if required and to ensure we follow proper semantic versioning. DO NOT restate the changes of this PR; if a bug was fixed and already explained above, we don't need this to be restated as a user-facing change. --> No. # AI usage disclosure AI drafted the documentation. I reviewed and adjusted it, and confirmed that it matches my understanding of the behavior. --- arrow-select/src/filter.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/arrow-select/src/filter.rs b/arrow-select/src/filter.rs index ea337b675f..fc9b833a92 100644 --- a/arrow-select/src/filter.rs +++ b/arrow-select/src/filter.rs @@ -162,6 +162,9 @@ pub fn prep_null_mask_filter(filter: &BooleanArray) -> BooleanArray { /// Returns a filtered `values` [`Array`] where the corresponding elements of /// `predicate` are `true`. /// +/// `predicate` may be shorter than `values`. Rows beyond the end of `predicate` +/// are not selected. +/// /// If multiple arrays (or record batches) need to be filtered using the same predicate array, /// consider using [FilterBuilder] to create a single [FilterPredicate] and then /// calling [FilterPredicate::filter_record_batch]. @@ -185,10 +188,11 @@ pub fn prep_null_mask_filter(filter: &BooleanArray) -> BooleanArray { /// # use arrow_array::{Int32Array, BooleanArray}; /// # use arrow_select::filter::filter; /// let array = Int32Array::from(vec![5, 6, 7, 8, 9]); -/// let filter_array = BooleanArray::from(vec![true, false, false, true, false]); +/// // Rows beyond the end of the predicate are not selected. +/// let filter_array = BooleanArray::from(vec![true, false, true]); /// let c = filter(&array, &filter_array).unwrap(); /// let c = c.as_any().downcast_ref::<Int32Array>().unwrap(); -/// assert_eq!(c, &Int32Array::from(vec![5, 8])); +/// assert_eq!(c, &Int32Array::from(vec![5, 7])); /// ``` pub fn filter(values: &dyn Array, predicate: &BooleanArray) -> Result<ArrayRef, ArrowError> { let mut filter_builder = FilterBuilder::new(predicate); @@ -209,6 +213,9 @@ pub fn filter(values: &dyn Array, predicate: &BooleanArray) -> Result<ArrayRef, /// /// This is the equivalent of calling [filter] on each column of the [RecordBatch]. /// +/// `predicate` may be shorter than the batch. Rows beyond the end of `predicate` +/// are not selected. +/// /// If multiple record batches (or arrays) need to be filtered using the same predicate array, /// consider using [FilterBuilder] to create a single [FilterPredicate] and then /// calling [FilterPredicate::filter_record_batch]. @@ -478,6 +485,8 @@ pub struct FilterPredicate { impl FilterPredicate { /// Selects rows from `values` based on this [`FilterPredicate`] + /// + /// This predicate may be shorter than `values`. Rows beyond its length are not selected. pub fn filter(&self, values: &dyn Array) -> Result<ArrayRef, ArrowError> { filter_array(values, self) } @@ -486,6 +495,8 @@ impl FilterPredicate { /// [`FilterPredicate`]. /// /// This is the equivalent of calling [filter] on each column of the [`RecordBatch`]. + /// + /// This predicate may be shorter than the batch. Rows beyond its length are not selected. pub fn filter_record_batch( &self, record_batch: &RecordBatch,
