Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make intersect_row_selections a member function #3084

Merged
merged 1 commit into from
Nov 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion parquet/src/arrow/arrow_reader/mod.rs
Original file line number Diff line number Diff line change
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
42 changes: 27 additions & 15 deletions parquet/src/arrow/arrow_reader/selection.rs
Original file line number Diff line number Diff line change
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(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could also keep this public, but I don't see a reason to do so

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 Expand Up @@ -692,7 +704,7 @@ mod tests {
RowSelector::select(1),
];

let res = intersect_row_selections(a, b);
let res = intersect_row_selections(&a, &b);
assert_eq!(
RowSelection::from_selectors_and_combine(&res).selectors,
vec![
Expand All @@ -710,7 +722,7 @@ mod tests {
RowSelector::skip(33),
];
let b = vec![RowSelector::select(36), RowSelector::skip(36)];
let res = intersect_row_selections(a, b);
let res = intersect_row_selections(&a, &b);
assert_eq!(
RowSelection::from_selectors_and_combine(&res).selectors,
vec![RowSelector::select(3), RowSelector::skip(69)]
Expand All @@ -725,7 +737,7 @@ mod tests {
RowSelector::skip(2),
RowSelector::select(2),
];
let res = intersect_row_selections(a, b);
let res = intersect_row_selections(&a, &b);
assert_eq!(
RowSelection::from_selectors_and_combine(&res).selectors,
vec![RowSelector::select(2), RowSelector::skip(8)]
Expand All @@ -739,7 +751,7 @@ mod tests {
RowSelector::skip(2),
RowSelector::select(2),
];
let res = intersect_row_selections(a, b);
let res = intersect_row_selections(&a, &b);
assert_eq!(
RowSelection::from_selectors_and_combine(&res).selectors,
vec![RowSelector::select(2), RowSelector::skip(8)]
Expand Down