-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Return Vec<bool> from PredicateBuilder rather than an Fn
#370
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
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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -38,7 +38,10 @@ use arrow::{ | |
| error::{ArrowError, Result as ArrowResult}, | ||
| record_batch::RecordBatch, | ||
| }; | ||
| use parquet::file::reader::{FileReader, SerializedFileReader}; | ||
| use parquet::file::{ | ||
| metadata::RowGroupMetaData, | ||
| reader::{FileReader, SerializedFileReader}, | ||
| }; | ||
|
|
||
| use fmt::Debug; | ||
| use parquet::arrow::{ArrowReader, ParquetFileArrowReader}; | ||
|
|
@@ -454,6 +457,22 @@ fn send_result( | |
| Ok(()) | ||
| } | ||
|
|
||
| fn build_row_group_predicate( | ||
| predicate_builder: &PruningPredicateBuilder, | ||
| row_group_metadata: &[RowGroupMetaData], | ||
| ) -> Box<dyn Fn(&RowGroupMetaData, usize) -> bool> { | ||
| let predicate_values = predicate_builder.build_pruning_predicate(row_group_metadata); | ||
|
|
||
| let predicate_values = match predicate_values { | ||
| Ok(values) => values, | ||
| // stats filter array could not be built | ||
| // return a closure which will not filter out any row groups | ||
| _ => return Box::new(|_r, _i| true), | ||
|
Contributor
Author
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. The existing code also (silently) ignores error so we continue that tradition in this PR |
||
| }; | ||
|
|
||
| Box::new(move |_, i| predicate_values[i]) | ||
| } | ||
|
|
||
| fn read_files( | ||
| filenames: &[String], | ||
| projection: &[usize], | ||
|
|
@@ -467,8 +486,10 @@ fn read_files( | |
| let file = File::open(&filename)?; | ||
| let mut file_reader = SerializedFileReader::new(file)?; | ||
| if let Some(predicate_builder) = predicate_builder { | ||
| let row_group_predicate = predicate_builder | ||
| .build_pruning_predicate(file_reader.metadata().row_groups()); | ||
| let row_group_predicate = build_row_group_predicate( | ||
| predicate_builder, | ||
| file_reader.metadata().row_groups(), | ||
| ); | ||
| file_reader.filter_row_groups(&row_group_predicate); | ||
| } | ||
| let mut arrow_reader = ParquetFileArrowReader::new(Arc::new(file_reader)); | ||
|
|
@@ -643,7 +664,7 @@ mod tests { | |
| ); | ||
| let row_group_metadata = vec![rgm1, rgm2]; | ||
| let row_group_predicate = | ||
| predicate_builder.build_pruning_predicate(&row_group_metadata); | ||
| build_row_group_predicate(&predicate_builder, &row_group_metadata); | ||
| let row_group_filter = row_group_metadata | ||
| .iter() | ||
| .enumerate() | ||
|
|
@@ -673,7 +694,7 @@ mod tests { | |
| ); | ||
| let row_group_metadata = vec![rgm1, rgm2]; | ||
| let row_group_predicate = | ||
| predicate_builder.build_pruning_predicate(&row_group_metadata); | ||
| build_row_group_predicate(&predicate_builder, &row_group_metadata); | ||
| let row_group_filter = row_group_metadata | ||
| .iter() | ||
| .enumerate() | ||
|
|
@@ -718,7 +739,7 @@ mod tests { | |
| ); | ||
| let row_group_metadata = vec![rgm1, rgm2]; | ||
| let row_group_predicate = | ||
| predicate_builder.build_pruning_predicate(&row_group_metadata); | ||
| build_row_group_predicate(&predicate_builder, &row_group_metadata); | ||
| let row_group_filter = row_group_metadata | ||
| .iter() | ||
| .enumerate() | ||
|
|
@@ -733,7 +754,7 @@ mod tests { | |
| let expr = col("c1").gt(lit(15)).or(col("c2").modulus(lit(2))); | ||
| let predicate_builder = PruningPredicateBuilder::try_new(&expr, schema)?; | ||
| let row_group_predicate = | ||
| predicate_builder.build_pruning_predicate(&row_group_metadata); | ||
| build_row_group_predicate(&predicate_builder, &row_group_metadata); | ||
| let row_group_filter = row_group_metadata | ||
| .iter() | ||
| .enumerate() | ||
|
|
@@ -777,7 +798,7 @@ mod tests { | |
| ); | ||
| let row_group_metadata = vec![rgm1, rgm2]; | ||
| let row_group_predicate = | ||
| predicate_builder.build_pruning_predicate(&row_group_metadata); | ||
| build_row_group_predicate(&predicate_builder, &row_group_metadata); | ||
| let row_group_filter = row_group_metadata | ||
| .iter() | ||
| .enumerate() | ||
|
|
||
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.
The main change in this PR is this function's signature. The rest of the changes are fallout from doing that