Skip to content

Commit

Permalink
Improve panic messages for RowSelection::and_then (#2925) (#2928)
Browse files Browse the repository at this point in the history
* Improve panic messages for RowSelection::and_then (#2925)

* Review feedback
  • Loading branch information
tustvold committed Oct 26, 2022
1 parent ed5843e commit 51d3568
Showing 1 changed file with 38 additions and 2 deletions.
40 changes: 38 additions & 2 deletions parquet/src/arrow/arrow_reader/selection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,14 +223,21 @@ impl RowSelection {
/// returned: NNNNNNNNNNNNYYYYYNNNNYYYYYYYYYYYYYNNNYYNNN
///
///
/// # Panics
///
/// Panics if `other` does not have a length equal to the number of rows selected
/// by this RowSelection
///
pub fn and_then(&self, other: &Self) -> Self {
let mut selectors = vec![];
let mut first = self.selectors.iter().cloned().peekable();
let mut second = other.selectors.iter().cloned().peekable();

let mut to_skip = 0;
while let Some(b) = second.peek_mut() {
let a = first.peek_mut().unwrap();
let a = first
.peek_mut()
.expect("selection exceeds the number of selected rows");

if b.row_count == 0 {
second.next().unwrap();
Expand Down Expand Up @@ -269,7 +276,10 @@ impl RowSelection {

for v in first {
if v.row_count != 0 {
assert!(v.skip);
assert!(
v.skip,
"selection contains less than the number of selected rows"
);
to_skip += v.row_count
}
}
Expand Down Expand Up @@ -460,6 +470,32 @@ mod tests {
);
}

#[test]
#[should_panic(expected = "selection exceeds the number of selected rows")]
fn test_and_longer() {
let a = RowSelection::from(vec![
RowSelector::select(3),
RowSelector::skip(33),
RowSelector::select(3),
RowSelector::skip(33),
]);
let b = RowSelection::from(vec![RowSelector::select(36)]);
a.and_then(&b);
}

#[test]
#[should_panic(expected = "selection contains less than the number of selected rows")]
fn test_and_shorter() {
let a = RowSelection::from(vec![
RowSelector::select(3),
RowSelector::skip(33),
RowSelector::select(3),
RowSelector::skip(33),
]);
let b = RowSelection::from(vec![RowSelector::select(3)]);
a.and_then(&b);
}

#[test]
fn test_and_fuzz() {
let mut rand = thread_rng();
Expand Down

0 comments on commit 51d3568

Please sign in to comment.