Repository navigation
Fix limited statistic collection accross files with no stats #4521
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
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 | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -47,29 +47,42 @@ use futures::StreamExt; | |||||||||||||||||||||||||||||||||
| /// Get all files as well as the file level summary statistics (no statistic for partition columns). | ||||||||||||||||||||||||||||||||||
| /// If the optional `limit` is provided, includes only sufficient files. | ||||||||||||||||||||||||||||||||||
| /// Needed to read up to `limit` number of rows. | ||||||||||||||||||||||||||||||||||
| /// TODO fix case where `num_rows` and `total_byte_size` are not defined (stat should be None instead of Some(0)) | ||||||||||||||||||||||||||||||||||
| pub async fn get_statistics_with_limit( | ||||||||||||||||||||||||||||||||||
| all_files: impl Stream<Item = Result<(PartitionedFile, Statistics)>>, | ||||||||||||||||||||||||||||||||||
| file_schema: SchemaRef, | ||||||||||||||||||||||||||||||||||
| limit: Option<usize>, | ||||||||||||||||||||||||||||||||||
| ) -> Result<(Vec<PartitionedFile>, Statistics)> { | ||||||||||||||||||||||||||||||||||
| let mut result_files = vec![]; | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| let mut total_byte_size = 0; | ||||||||||||||||||||||||||||||||||
| let mut null_counts = vec![0; file_schema.fields().len()]; | ||||||||||||||||||||||||||||||||||
| let mut has_statistics = false; | ||||||||||||||||||||||||||||||||||
| let (mut max_values, mut min_values) = create_max_min_accs(&file_schema); | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| let mut num_rows = 0; | ||||||||||||||||||||||||||||||||||
| let mut is_exact = true; | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| // The number of rows and the total byte size can be calculated as long as | ||||||||||||||||||||||||||||||||||
| // at least one file has them. If none of the files provide them, then they | ||||||||||||||||||||||||||||||||||
| // will be omitted from the statistics. The missing values will be counted | ||||||||||||||||||||||||||||||||||
| // as zero. | ||||||||||||||||||||||||||||||||||
| let mut num_rows = None; | ||||||||||||||||||||||||||||||||||
| let mut total_byte_size = None; | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| // fusing the stream allows us to call next safely even once it is finished | ||||||||||||||||||||||||||||||||||
| let mut all_files = Box::pin(all_files.fuse()); | ||||||||||||||||||||||||||||||||||
| while let Some(res) = all_files.next().await { | ||||||||||||||||||||||||||||||||||
| let (file, file_stats) = res?; | ||||||||||||||||||||||||||||||||||
| result_files.push(file); | ||||||||||||||||||||||||||||||||||
| is_exact &= file_stats.is_exact; | ||||||||||||||||||||||||||||||||||
| num_rows += file_stats.num_rows.unwrap_or(0); | ||||||||||||||||||||||||||||||||||
| total_byte_size += file_stats.total_byte_size.unwrap_or(0); | ||||||||||||||||||||||||||||||||||
| num_rows = if let Some(num_rows) = num_rows { | ||||||||||||||||||||||||||||||||||
| Some(num_rows + file_stats.num_rows.unwrap_or(0)) | ||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||
| file_stats.num_rows | ||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||
| total_byte_size = if let Some(total_byte_size) = total_byte_size { | ||||||||||||||||||||||||||||||||||
| Some(total_byte_size + file_stats.total_byte_size.unwrap_or(0)) | ||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||
| file_stats.total_byte_size | ||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+76
to
+85
Contributor
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. If you are into a more functional style of coding, you can do something like the following as well
Suggested change
|
||||||||||||||||||||||||||||||||||
| if let Some(vec) = &file_stats.column_statistics { | ||||||||||||||||||||||||||||||||||
| has_statistics = true; | ||||||||||||||||||||||||||||||||||
| for (i, cs) in vec.iter().enumerate() { | ||||||||||||||||||||||||||||||||||
|
|
@@ -102,7 +115,12 @@ pub async fn get_statistics_with_limit( | |||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| if num_rows > limit.unwrap_or(usize::MAX) { | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| // If the number of rows exceeds the limit, we can stop processing | ||||||||||||||||||||||||||||||||||
| // files. This only applies when we know the number of rows. It also | ||||||||||||||||||||||||||||||||||
| // currently ignores tables that have no statistics regarding the | ||||||||||||||||||||||||||||||||||
| // number of rows. | ||||||||||||||||||||||||||||||||||
| if num_rows.unwrap_or(usize::MIN) > limit.unwrap_or(usize::MAX) { | ||||||||||||||||||||||||||||||||||
| break; | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
@@ -125,8 +143,8 @@ pub async fn get_statistics_with_limit( | |||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| let statistics = Statistics { | ||||||||||||||||||||||||||||||||||
| num_rows: Some(num_rows), | ||||||||||||||||||||||||||||||||||
| total_byte_size: Some(total_byte_size), | ||||||||||||||||||||||||||||||||||
| num_rows, | ||||||||||||||||||||||||||||||||||
| total_byte_size, | ||||||||||||||||||||||||||||||||||
| column_statistics: column_stats, | ||||||||||||||||||||||||||||||||||
| is_exact, | ||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
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
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.
👍