You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by vi...@apache.org on 2022/10/26 20:10:57 UTC
[arrow-rs] branch master updated: Improve panic messages for RowSelection::and_then (#2925) (#2928)
This is an automated email from the ASF dual-hosted git repository.
viirya pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow-rs.git
The following commit(s) were added to refs/heads/master by this push:
new 51d356845 Improve panic messages for RowSelection::and_then (#2925) (#2928)
51d356845 is described below
commit 51d35684507a5a1a818bfb69497011f4e4593b9d
Author: Raphael Taylor-Davies <17...@users.noreply.github.com>
AuthorDate: Thu Oct 27 09:10:52 2022 +1300
Improve panic messages for RowSelection::and_then (#2925) (#2928)
* Improve panic messages for RowSelection::and_then (#2925)
* Review feedback
---
parquet/src/arrow/arrow_reader/selection.rs | 40 +++++++++++++++++++++++++++--
1 file changed, 38 insertions(+), 2 deletions(-)
diff --git a/parquet/src/arrow/arrow_reader/selection.rs b/parquet/src/arrow/arrow_reader/selection.rs
index 6a965dc9b..f1270926b 100644
--- a/parquet/src/arrow/arrow_reader/selection.rs
+++ b/parquet/src/arrow/arrow_reader/selection.rs
@@ -223,6 +223,11 @@ 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();
@@ -230,7 +235,9 @@ impl RowSelection {
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();
@@ -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
}
}
@@ -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();