Skip to content

Commit

Permalink
Make RowSelection::intersection a member function
Browse files Browse the repository at this point in the history
  • Loading branch information
tustvold committed Nov 10, 2022
1 parent 9f14683 commit f5faf5d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
2 changes: 1 addition & 1 deletion parquet/src/arrow/arrow_reader/mod.rs
Expand Up @@ -41,7 +41,7 @@ mod filter;
mod selection;

pub use filter::{ArrowPredicate, ArrowPredicateFn, RowFilter};
pub use selection::{intersect_row_selections, RowSelection, RowSelector};
pub use selection::{RowSelection, RowSelector};

/// A generic builder for constructing sync or async arrow parquet readers. This is not intended
/// to be used directly, instead you should use the specialization for the type of reader
Expand Down
34 changes: 23 additions & 11 deletions parquet/src/arrow/arrow_reader/selection.rs
Expand Up @@ -323,6 +323,18 @@ impl RowSelection {
Self { selectors }
}

/// Compute the intersection of two [`RowSelection`]
/// For example:
/// self: NNYYYYNNYYNYN
/// other: NYNNNNNNY
///
/// returned: NNNNNNNNYYNYN
pub fn intersection(&self, other: &Self) -> Self {
Self {
selectors: intersect_row_selections(&self.selectors, &other.selectors),
}
}

/// Returns `true` if this [`RowSelection`] selects any rows
pub fn selects_any(&self) -> bool {
self.selectors.iter().any(|x| !x.skip)
Expand All @@ -349,19 +361,19 @@ impl From<RowSelection> for VecDeque<RowSelector> {
}
}

// Combine two lists of `RowSelection` return the intersection of them
// For example:
// self: NNYYYYNNYYNYN
// other: NYNNNNNNY
//
// returned: NNNNNNNNYYNYN
pub fn intersect_row_selections(
left: Vec<RowSelector>,
right: Vec<RowSelector>,
/// Combine two lists of `RowSelection` return the intersection of them
/// For example:
/// self: NNYYYYNNYYNYN
/// other: NYNNNNNNY
///
/// returned: NNNNNNNNYYNYN
fn intersect_row_selections(
left: &[RowSelector],
right: &[RowSelector],
) -> Vec<RowSelector> {
let mut res = Vec::with_capacity(left.len());
let mut l_iter = left.into_iter().peekable();
let mut r_iter = right.into_iter().peekable();
let mut l_iter = left.iter().copied().peekable();
let mut r_iter = right.iter().copied().peekable();

while let (Some(a), Some(b)) = (l_iter.peek_mut(), r_iter.peek_mut()) {
if a.row_count == 0 {
Expand Down

0 comments on commit f5faf5d

Please sign in to comment.