This is an automated email from the ASF dual-hosted git repository.
alamb 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 a20116ec36f Make RowSelection's from_consecutive_ranges public (#5848)
a20116ec36f is described below
commit a20116ec36f8c0c959aa9e6c547dc7e5625ebb1b
Author: advancedxy <[email protected]>
AuthorDate: Wed Jun 12 03:47:56 2024 +0900
Make RowSelection's from_consecutive_ranges public (#5848)
* Make RowSelection's from_consecutive_ranges public
This constructor method should be easier to use.
* Address reviewers' comments
---------
Co-authored-by: Andrew Lamb <[email protected]>
---
parquet/src/arrow/arrow_reader/selection.rs | 19 ++++++++++++++++---
1 file changed, 16 insertions(+), 3 deletions(-)
diff --git a/parquet/src/arrow/arrow_reader/selection.rs
b/parquet/src/arrow/arrow_reader/selection.rs
index 82f21461290..0287e5b4215 100644
--- a/parquet/src/arrow/arrow_reader/selection.rs
+++ b/parquet/src/arrow/arrow_reader/selection.rs
@@ -81,6 +81,13 @@ impl RowSelector {
///
/// let actual: Vec<RowSelector> = selection.into();
/// assert_eq!(actual, expected);
+///
+/// // you can also create a selection from consecutive ranges
+/// let ranges = vec![5..10, 10..15];
+/// let selection =
+/// RowSelection::from_consecutive_ranges(ranges.into_iter(), 20);
+/// let actual: Vec<RowSelector> = selection.into();
+/// assert_eq!(actual, expected);
/// ```
///
/// A [`RowSelection`] maintains the following invariants:
@@ -115,7 +122,7 @@ impl RowSelection {
}
/// Creates a [`RowSelection`] from an iterator of consecutive ranges to
keep
- pub(crate) fn from_consecutive_ranges<I: Iterator<Item = Range<usize>>>(
+ pub fn from_consecutive_ranges<I: Iterator<Item = Range<usize>>>(
ranges: I,
total_rows: usize,
) -> Self {
@@ -1136,7 +1143,7 @@ mod tests {
}
#[test]
- fn test_empty_ranges() {
+ fn test_from_ranges() {
let ranges = [1..3, 4..6, 6..6, 8..8, 9..10];
let selection =
RowSelection::from_consecutive_ranges(ranges.into_iter(), 10);
assert_eq!(
@@ -1149,7 +1156,13 @@ mod tests {
RowSelector::skip(3),
RowSelector::select(1)
]
- )
+ );
+
+ let out_of_order_ranges = [1..3, 8..10, 4..7];
+ let result = std::panic::catch_unwind(|| {
+
RowSelection::from_consecutive_ranges(out_of_order_ranges.into_iter(), 10)
+ });
+ assert!(result.is_err());
}
#[test]