Teach row group pruning about struct field predicates#21003
Teach row group pruning about struct field predicates#21003friendlymatthew wants to merge 1 commit intoapache:mainfrom
Conversation
friendlymatthew
left a comment
There was a problem hiding this comment.
self review
| impl From<Column> for PruningColumn { | ||
| fn from(column: Column) -> Self { | ||
| Self { | ||
| column, | ||
| field_path: vec![], | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl From<&Column> for PruningColumn { | ||
| fn from(column: &Column) -> Self { | ||
| Self { | ||
| column: column.clone(), | ||
| field_path: vec![], | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
As you can see from the diff of this PR, it introduces a lot of the same breaking change where we once accepted a Column and now require a PruningColumn
Hopefully these convenience methods help
| return Ok(StatisticsConverter::from_column_index( | ||
| leaf_idx, | ||
| arrow_field, | ||
| self.parquet_schema, | ||
| )?); |
There was a problem hiding this comment.
7873e80 to
55ef323
Compare
| fn min_values(&self, column: &Column) -> Option<ArrayRef>; | ||
| fn min_values(&self, column: &PruningColumn) -> Option<ArrayRef>; |
There was a problem hiding this comment.
I wonder if instead of PruningColumn we can / should allow arbitrary Expr? Essentially the implementation would match on the Expr. It can only handle Column and return None for anything else but the Parquet RowGroup stats implementation can match on struct field access as well and handle that accordingly.
We could add new methods like max_expression_values that have a default impl
match expr {
Expr::Column(col) => self.max_values(col),
_ => None,
}Or something like that.
Which issue does this PR close?
Rationale for this change
This PR enables Parquet row group pruning for predicates on struct fields like
WHERE s['value']> 5Previously, the pruning predicate system only understood top level column references. When it encountered a struct field access via
get_field, it marked the expression as unhandled and conservatively kept every row group, even though Parquet stores valid min/max stats for each leaf column in the file metadata. This meant queries filtering on struct fields always read all row groups, missing a significant optimization opportunity on struct heavy tables (like Variant!)This optimization introduces
PruningColumnwhich wraps aColumnthat carries an optional field path for nested struct access. The pruning expression builder now recognizesget_Fieldexpressions, extracts the field path, and threads it through the statistics lookup pipelineOn the Parquet side,
RowGroupPruningStatisticsresolves the field path to the corresponding leaf column index in the Parquet schema and uses apache/arrow-rs#9540 to fetch the correct row group stats