-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Simplify file struct abstractions #1120
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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 |
---|---|---|
|
@@ -23,6 +23,7 @@ use std::{any::Any, convert::TryInto}; | |
|
||
use crate::datasource::file_format::parquet::ChunkObjectReader; | ||
use crate::datasource::object_store::ObjectStore; | ||
use crate::datasource::PartitionedFile; | ||
use crate::{ | ||
error::{DataFusionError, Result}, | ||
logical_plan::{Column, Expr}, | ||
|
@@ -59,14 +60,13 @@ use tokio::{ | |
|
||
use async_trait::async_trait; | ||
|
||
use crate::datasource::{FilePartition, PartitionedFile}; | ||
|
||
/// Execution plan for scanning one or more Parquet partitions | ||
#[derive(Debug, Clone)] | ||
pub struct ParquetExec { | ||
object_store: Arc<dyn ObjectStore>, | ||
/// Parquet partitions to read | ||
partitions: Vec<ParquetPartition>, | ||
/// Grouped list of files. Each group will be processed together by one | ||
/// partition of the `ExecutionPlan`. | ||
file_groups: Vec<Vec<PartitionedFile>>, | ||
/// Schema after projection is applied | ||
schema: SchemaRef, | ||
/// Projection for which columns to load | ||
|
@@ -83,23 +83,6 @@ pub struct ParquetExec { | |
limit: Option<usize>, | ||
} | ||
|
||
/// Represents one partition of a Parquet data set and this currently means one Parquet file. | ||
/// | ||
/// In the future it would be good to support subsets of files based on ranges of row groups | ||
/// so that we can better parallelize reads of large files across available cores (see | ||
/// [ARROW-10995](https://issues.apache.org/jira/browse/ARROW-10995)). | ||
/// | ||
/// We may also want to support reading Parquet files that are partitioned based on a key and | ||
/// in this case we would want this partition struct to represent multiple files for a given | ||
/// partition key (see [ARROW-11019](https://issues.apache.org/jira/browse/ARROW-11019)). | ||
#[derive(Debug, Clone)] | ||
pub struct ParquetPartition { | ||
/// The Parquet filename for this partition | ||
pub file_partition: FilePartition, | ||
/// Execution metrics | ||
metrics: ExecutionPlanMetricsSet, | ||
} | ||
|
||
/// Stores metrics about the parquet execution for a particular parquet file | ||
#[derive(Debug, Clone)] | ||
struct ParquetFileMetrics { | ||
|
@@ -115,24 +98,16 @@ impl ParquetExec { | |
#[allow(clippy::too_many_arguments)] | ||
pub fn new( | ||
object_store: Arc<dyn ObjectStore>, | ||
files: Vec<Vec<PartitionedFile>>, | ||
file_groups: Vec<Vec<PartitionedFile>>, | ||
statistics: Statistics, | ||
schema: SchemaRef, | ||
projection: Option<Vec<usize>>, | ||
predicate: Option<Expr>, | ||
batch_size: usize, | ||
limit: Option<usize>, | ||
) -> Self { | ||
debug!("Creating ParquetExec, desc: {:?}, projection {:?}, predicate: {:?}, limit: {:?}", | ||
files, projection, predicate, limit); | ||
|
||
let metrics = ExecutionPlanMetricsSet::new(); | ||
|
||
let partitions = files | ||
.into_iter() | ||
.enumerate() | ||
.map(|(i, f)| ParquetPartition::new(f, i, metrics.clone())) | ||
.collect::<Vec<_>>(); | ||
debug!("Creating ParquetExec, files: {:?}, projection {:?}, predicate: {:?}, limit: {:?}", | ||
file_groups, projection, predicate, limit); | ||
|
||
let metrics = ExecutionPlanMetricsSet::new(); | ||
let predicate_creation_errors = | ||
|
@@ -162,7 +137,7 @@ impl ParquetExec { | |
|
||
Self { | ||
object_store, | ||
partitions, | ||
file_groups, | ||
schema: projected_schema, | ||
projection, | ||
metrics, | ||
|
@@ -204,11 +179,8 @@ impl ParquetExec { | |
} | ||
|
||
/// List of data files | ||
pub fn partitions(&self) -> Vec<&[PartitionedFile]> { | ||
self.partitions | ||
.iter() | ||
.map(|fp| fp.file_partition.files.as_slice()) | ||
.collect() | ||
pub fn file_groups(&self) -> &[Vec<PartitionedFile>] { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We replace
|
||
&self.file_groups | ||
} | ||
/// Optional projection for which columns to load | ||
pub fn projection(&self) -> &[usize] { | ||
|
@@ -225,20 +197,6 @@ impl ParquetExec { | |
} | ||
} | ||
|
||
impl ParquetPartition { | ||
/// Create a new parquet partition | ||
pub fn new( | ||
files: Vec<PartitionedFile>, | ||
index: usize, | ||
metrics: ExecutionPlanMetricsSet, | ||
) -> Self { | ||
Self { | ||
file_partition: FilePartition { index, files }, | ||
metrics, | ||
} | ||
} | ||
} | ||
|
||
impl ParquetFileMetrics { | ||
/// Create new metrics | ||
pub fn new( | ||
|
@@ -279,7 +237,7 @@ impl ExecutionPlan for ParquetExec { | |
|
||
/// Get the output partitioning of this plan | ||
fn output_partitioning(&self) -> Partitioning { | ||
Partitioning::UnknownPartitioning(self.partitions.len()) | ||
Partitioning::UnknownPartitioning(self.file_groups.len()) | ||
} | ||
|
||
fn with_new_children( | ||
|
@@ -304,7 +262,7 @@ impl ExecutionPlan for ParquetExec { | |
Receiver<ArrowResult<RecordBatch>>, | ||
) = channel(2); | ||
|
||
let partition = self.partitions[partition_index].clone(); | ||
let partition = self.file_groups[partition_index].clone(); | ||
let metrics = self.metrics.clone(); | ||
let projection = self.projection.clone(); | ||
let predicate_builder = self.predicate_builder.clone(); | ||
|
@@ -338,18 +296,12 @@ impl ExecutionPlan for ParquetExec { | |
) -> std::fmt::Result { | ||
match t { | ||
DisplayFormatType::Default => { | ||
let files: Vec<_> = self | ||
.partitions | ||
.iter() | ||
.map(|pp| format!("{}", pp.file_partition)) | ||
.collect(); | ||
|
||
write!( | ||
f, | ||
"ParquetExec: batch_size={}, limit={:?}, partitions=[{}]", | ||
"ParquetExec: batch_size={}, limit={:?}, partitions={}", | ||
self.batch_size, | ||
self.limit, | ||
files.join(", ") | ||
super::FileGroupsDisplay(&self.file_groups) | ||
) | ||
} | ||
} | ||
|
@@ -493,7 +445,7 @@ fn build_row_group_predicate( | |
fn read_partition( | ||
object_store: &dyn ObjectStore, | ||
partition_index: usize, | ||
partition: ParquetPartition, | ||
partition: Vec<PartitionedFile>, | ||
metrics: ExecutionPlanMetricsSet, | ||
projection: &[usize], | ||
predicate_builder: &Option<PruningPredicate>, | ||
|
@@ -502,8 +454,7 @@ fn read_partition( | |
limit: Option<usize>, | ||
) -> Result<()> { | ||
let mut total_rows = 0; | ||
let all_files = partition.file_partition.files; | ||
'outer: for partitioned_file in all_files { | ||
'outer: for partitioned_file in partition { | ||
let file_metrics = ParquetFileMetrics::new( | ||
partition_index, | ||
&*partitioned_file.file_meta.path(), | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These comments were mostly outdated and the other features mentioned are now planned in the
ListingTable
provider