-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
ParquetAccessPlan
that describes which part of the parquet file…
…s to read
- Loading branch information
Showing
5 changed files
with
176 additions
and
78 deletions.
There are no files selected for viewing
99 changes: 99 additions & 0 deletions
99
datafusion/core/src/datasource/physical_plan/parquet/access_plan.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
// Licensed to the Apache Software Foundation (ASF) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The ASF licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
use parquet::arrow::arrow_reader::RowSelection; | ||
|
||
/// Specifies a selection of row groups / rows within a ParquetFile to decode. | ||
/// | ||
/// This structure can limit the row groups and data pages a `ParquetExec` will | ||
/// read and decode. | ||
/// | ||
/// Note that page level pruning based on ArrowPredicate is applied after all of | ||
/// these selections | ||
/// | ||
/// This looks like: | ||
/// (TODO diagram) | ||
#[derive(Debug, Clone, PartialEq)] | ||
pub struct ParquetAccessPlan { | ||
/// How to access the i-th row group | ||
row_groups: Vec<RowGroupAccess>, | ||
} | ||
|
||
#[derive(Debug, Clone, PartialEq)] | ||
pub enum RowGroupAccess { | ||
/// The row group should not be read at all | ||
Skip, | ||
/// The row group should be scanned fully | ||
Scan, | ||
/// Only the specified rows within the row group should be scanned | ||
Selection(RowSelection), | ||
} | ||
|
||
impl RowGroupAccess { | ||
/// return true if this row group should be scanned | ||
pub fn should_scan(&self) -> bool { | ||
match self { | ||
RowGroupAccess::Skip => false, | ||
RowGroupAccess::Scan | RowGroupAccess::Selection(_) => true, | ||
} | ||
} | ||
} | ||
|
||
impl ParquetAccessPlan { | ||
/// Create a new `ParquetAccessPlan` to scan all row groups | ||
pub fn new_all(row_group_count: usize) -> Self { | ||
Self { | ||
row_groups: vec![RowGroupAccess::Scan; row_group_count], | ||
} | ||
} | ||
|
||
/// Set the i-th row group to false (should not be scanned) | ||
pub fn do_not_scan(&mut self, idx: usize) { | ||
self.row_groups[idx] = RowGroupAccess::Skip; | ||
} | ||
|
||
/// Return true if the i-th row group should be scanned | ||
pub fn should_scan(&self, idx: usize) -> bool { | ||
self.row_groups[idx].should_scan() | ||
} | ||
|
||
/// Return an iterator over the row group indexes that should be scanned | ||
pub fn row_group_index_iter(&self) -> impl Iterator<Item = usize> + '_ { | ||
self.row_groups.iter().enumerate().filter_map(|(idx, b)| { | ||
if b.should_scan() { | ||
Some(idx) | ||
} else { | ||
None | ||
} | ||
}) | ||
} | ||
|
||
/// Return a vec of all row group indexes to scan | ||
pub fn row_group_indexes(&self) -> Vec<usize> { | ||
self.row_group_index_iter().collect() | ||
} | ||
|
||
/// Return the total number of row groups (not the total number to be scanned) | ||
pub fn len(&self) -> usize { | ||
self.row_groups.len() | ||
} | ||
|
||
/// Return true if there are no row groups | ||
pub fn is_empty(&self) -> bool { | ||
self.row_groups.is_empty() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.