|
15 | 15 | // specific language governing permissions and limitations
|
16 | 16 | // under the License.
|
17 | 17 |
|
18 |
| -use parquet::arrow::arrow_reader::RowSelection; |
| 18 | +use parquet::arrow::arrow_reader::{RowSelection, RowSelector}; |
19 | 19 |
|
20 | 20 | /// Specifies a selection of rows and row groups within a ParquetFile to decode.
|
21 | 21 | ///
|
@@ -71,6 +71,60 @@ impl ParquetAccessPlan {
|
71 | 71 | self.row_groups[idx].should_scan()
|
72 | 72 | }
|
73 | 73 |
|
| 74 | + /// Set to scan only the [`RowSelection`] in the specified row group. |
| 75 | + /// |
| 76 | + /// Based on the existing row groups plan: |
| 77 | + /// * Skip: does nothing |
| 78 | + /// * Scan: Updates to scan only the rows in the `RowSelection` |
| 79 | + /// * Selection: Updates to scan only the specified in the exising selection and the new selection |
| 80 | + pub fn scan_selection(&mut self, idx: usize, selection: RowSelection) { |
| 81 | + self.row_groups[idx] = match &self.row_groups[idx] { |
| 82 | + // already skipping the entire row group |
| 83 | + RowGroupAccess::Skip => RowGroupAccess::Skip, |
| 84 | + RowGroupAccess::Scan => RowGroupAccess::Selection(selection), |
| 85 | + RowGroupAccess::Selection(existing_selection) => { |
| 86 | + RowGroupAccess::Selection(existing_selection.intersection(&selection)) |
| 87 | + } |
| 88 | + } |
| 89 | + } |
| 90 | + |
| 91 | + /// Return the overall RowSelection for all scanned row groups, if |
| 92 | + /// there are any RowGroupAccess::Selection; |
| 93 | + /// |
| 94 | + /// |
| 95 | + /// TODO better doc / explanation |
| 96 | + pub fn overall_row_selection(&self) -> Option<RowSelection> { |
| 97 | + if !self |
| 98 | + .row_groups |
| 99 | + .iter() |
| 100 | + .any(|rg| matches!(rg, RowGroupAccess::Selection(_))) |
| 101 | + { |
| 102 | + return None; |
| 103 | + } |
| 104 | + |
| 105 | + let total_selection: RowSelection = self |
| 106 | + .row_groups |
| 107 | + .iter() |
| 108 | + .flat_map(|rg| { |
| 109 | + match rg { |
| 110 | + RowGroupAccess::Skip => vec![], |
| 111 | + RowGroupAccess::Scan => { |
| 112 | + // need a row group access to scan the entire row group (need row group counts) |
| 113 | + // This is clearly not tested TODO |
| 114 | + todo!(); |
| 115 | + } |
| 116 | + RowGroupAccess::Selection(selection) => { |
| 117 | + // todo avoid these clones |
| 118 | + let selection: Vec<RowSelector> = selection.clone().into(); |
| 119 | + selection |
| 120 | + } |
| 121 | + } |
| 122 | + }) |
| 123 | + .collect(); |
| 124 | + |
| 125 | + Some(total_selection) |
| 126 | + } |
| 127 | + |
74 | 128 | /// Return an iterator over the row group indexes that should be scanned
|
75 | 129 | pub fn row_group_index_iter(&self) -> impl Iterator<Item = usize> + '_ {
|
76 | 130 | self.row_groups.iter().enumerate().filter_map(|(idx, b)| {
|
|
0 commit comments