-
Notifications
You must be signed in to change notification settings - Fork 796
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
Add ParquetMetaDataBuilder
#6466
Merged
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a2818bf
Add `ParquetMetadtaBuilder`
alamb 572ce5c
Merge remote-tracking branch 'apache/master' into alamb/metadata_buil…
alamb 5e324f6
Add accessors for ColumnIndex / OffsetIndex
alamb b6c63a8
Deprecate ParquetMetaData::new_with_page_index
alamb 997c3f9
Merge remote-tracking branch 'apache/master' into alamb/metadata_buil…
alamb c0432e6
simplify reading metadata
alamb 21e8dc2
Revert "simplify reading metadata"
alamb 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,7 +27,6 @@ use crate::bloom_filter::Sbbf; | |
use crate::column::page::{Page, PageMetadata, PageReader}; | ||
use crate::compression::{create_codec, Codec}; | ||
use crate::errors::{ParquetError, Result}; | ||
use crate::file::page_index::index_reader; | ||
use crate::file::page_index::offset_index::OffsetIndexMetaData; | ||
use crate::file::{ | ||
metadata::*, | ||
|
@@ -191,54 +190,30 @@ impl<R: 'static + ChunkReader> SerializedFileReader<R> { | |
/// Creates file reader from a Parquet file with read options. | ||
/// Returns error if Parquet file does not exist or is corrupt. | ||
pub fn new_with_options(chunk_reader: R, options: ReadOptions) -> Result<Self> { | ||
let metadata = ParquetMetaDataReader::new().parse_and_finish(&chunk_reader)?; | ||
let mut metadata_builder = ParquetMetaDataReader::new() | ||
.with_page_indexes(options.enable_page_index) | ||
alamb marked this conversation as resolved.
Show resolved
Hide resolved
|
||
.parse_and_finish(&chunk_reader)? | ||
.into_builder(); | ||
|
||
let mut predicates = options.predicates; | ||
let row_groups = metadata.row_groups().to_vec(); | ||
let mut filtered_row_groups = Vec::<RowGroupMetaData>::new(); | ||
for (i, rg_meta) in row_groups.into_iter().enumerate() { | ||
let mut keep = true; | ||
for predicate in &mut predicates { | ||
if !predicate(&rg_meta, i) { | ||
keep = false; | ||
break; | ||
|
||
// Filter row groups based on the predicates | ||
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. I think the cleanup of this code (which is modifying the ParquetMetaData) is the best example of why having this API makes sense -- it makes one fewer copies and also I think is quite a bit clearer |
||
if !predicates.is_empty() { | ||
for (i, rg_meta) in metadata_builder.take_row_groups().into_iter().enumerate() { | ||
if predicates | ||
.iter_mut() | ||
.all(|predicate| predicate(&rg_meta, i)) | ||
{ | ||
metadata_builder = metadata_builder.add_row_group(rg_meta); | ||
} | ||
} | ||
if keep { | ||
filtered_row_groups.push(rg_meta); | ||
} | ||
} | ||
|
||
if options.enable_page_index { | ||
let mut columns_indexes = vec![]; | ||
let mut offset_indexes = vec![]; | ||
|
||
for rg in &mut filtered_row_groups { | ||
let column_index = index_reader::read_columns_indexes(&chunk_reader, rg.columns())?; | ||
let offset_index = index_reader::read_offset_indexes(&chunk_reader, rg.columns())?; | ||
columns_indexes.push(column_index); | ||
offset_indexes.push(offset_index); | ||
} | ||
|
||
Ok(Self { | ||
chunk_reader: Arc::new(chunk_reader), | ||
metadata: Arc::new(ParquetMetaData::new_with_page_index( | ||
metadata.file_metadata().clone(), | ||
filtered_row_groups, | ||
Some(columns_indexes), | ||
Some(offset_indexes), | ||
)), | ||
props: Arc::new(options.props), | ||
}) | ||
} else { | ||
Ok(Self { | ||
chunk_reader: Arc::new(chunk_reader), | ||
metadata: Arc::new(ParquetMetaData::new( | ||
metadata.file_metadata().clone(), | ||
filtered_row_groups, | ||
)), | ||
props: Arc::new(options.props), | ||
}) | ||
} | ||
Ok(Self { | ||
chunk_reader: Arc::new(chunk_reader), | ||
metadata: Arc::new(metadata_builder.build()), | ||
props: Arc::new(options.props), | ||
}) | ||
} | ||
} | ||
|
||
|
Oops, something went wrong.
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 methods follow the exsiting convention of
add
andset
as the other Builders in this crate sucha s