-
Notifications
You must be signed in to change notification settings - Fork 159
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
[BUG] Add an allowlist of DataTypes that ColumnRangeStatistics supports and validation of TableStatistics #1632
Merged
Merged
Changes from 11 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
b2d3c4c
Add an allowlist of DataTypes that ColumnRangeStatistics supports
faf036f
Perform pruning in TableStats
26dff4d
Add TODOs
aaf02cf
Use individual schams instead of unioned schema
a58b431
Iterate through schema instead of RowGroupMetadata when constructing …
c5284ef
Add validation of MicroPartitions in ::new_* functions
1d49106
Added validations but now failing roundtrip tests
2286c38
Fix 3 failing roundtrip tests by casting the statistics Series when p…
cfdb8ab
Cast TableStatistics to schema and loosen validation against ScanTask…
60608ec
rm is_subset function
eddba58
rm is_subset function
99463be
reuse casting logic
e0507d8
Refactor casting logic for ColumnRangeStatistics to only allow certai…
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 |
---|---|---|
@@ -1,37 +1,51 @@ | ||
use common_error::DaftResult; | ||
use daft_core::schema::Schema; | ||
use daft_stats::{ColumnRangeStatistics, TableStatistics}; | ||
use snafu::ResultExt; | ||
|
||
use super::Wrap; | ||
use super::column_range::parquet_statistics_to_column_range_statistics; | ||
|
||
use indexmap::IndexMap; | ||
|
||
impl TryFrom<&crate::metadata::RowGroupMetaData> for Wrap<TableStatistics> { | ||
type Error = super::Error; | ||
fn try_from(value: &crate::metadata::RowGroupMetaData) -> Result<Self, Self::Error> { | ||
let _num_rows = value.num_rows(); | ||
let mut columns = IndexMap::new(); | ||
for col in value.columns() { | ||
let stats = col | ||
.statistics() | ||
.transpose() | ||
.context(super::UnableToParseParquetColumnStatisticsSnafu)?; | ||
let col_stats: Option<Wrap<ColumnRangeStatistics>> = | ||
stats.and_then(|v| v.as_ref().try_into().ok()); | ||
let col_stats = col_stats.unwrap_or(ColumnRangeStatistics::Missing.into()); | ||
columns.insert( | ||
col.descriptor().path_in_schema.get(0).unwrap().clone(), | ||
col_stats.0, | ||
); | ||
} | ||
|
||
Ok(TableStatistics { columns }.into()) | ||
} | ||
} | ||
|
||
pub fn row_group_metadata_to_table_stats( | ||
metadata: &crate::metadata::RowGroupMetaData, | ||
schema: &Schema, | ||
) -> DaftResult<TableStatistics> { | ||
let result = Wrap::<TableStatistics>::try_from(metadata)?; | ||
Ok(result.0) | ||
// Create a map from {field_name: statistics} from the RowGroupMetaData for easy access | ||
let mut parquet_column_metadata: IndexMap<_, _> = metadata | ||
.columns() | ||
.iter() | ||
.map(|col| { | ||
let top_level_column_name = col | ||
.descriptor() | ||
.path_in_schema | ||
.first() | ||
.expect("Parquet schema should have at least one entry in path_in_schema"); | ||
(top_level_column_name, col.statistics()) | ||
}) | ||
.collect(); | ||
|
||
// Iterate through the schema and construct ColumnRangeStatistics per field | ||
let columns = schema | ||
.fields | ||
.iter() | ||
.map(|(field_name, field)| { | ||
if ColumnRangeStatistics::supports_dtype(&field.dtype) { | ||
let stats: ColumnRangeStatistics = parquet_column_metadata | ||
.remove(field_name) | ||
.expect("Cannot find parsed Daft field in Parquet rowgroup metadata") | ||
.transpose() | ||
.context(super::UnableToParseParquetColumnStatisticsSnafu)? | ||
.and_then(|v| { | ||
parquet_statistics_to_column_range_statistics(v.as_ref(), &field.dtype).ok() | ||
}) | ||
.unwrap_or(ColumnRangeStatistics::Missing); | ||
Ok((field_name.clone(), stats)) | ||
} else { | ||
Ok((field_name.clone(), ColumnRangeStatistics::Missing)) | ||
} | ||
}) | ||
.collect::<DaftResult<IndexMap<_, _>>>()?; | ||
|
||
Ok(TableStatistics { columns }) | ||
} |
Oops, something went wrong.
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.
should be a panic or debug assert. regular assert here will kill the program
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.
assert!
just callspanic!
under the hood, is it special-cased for pyo3?https://doc.rust-lang.org/std/macro.assert.html