adriangb opened a new pull request, #27734: URL: https://github.com/apache/datafusion/pull/27734
## Which issue does this PR close? - Closes https://github.com/apache/datafusion/issues/20871. - Part of https://github.com/apache/datafusion/issues/24119. ## Rationale for this change `SELECT * FROM t WHERE s['a'] > 5` reads every Parquet row group. `PruningPredicate` only understands predicates on top-level columns, and `PruningStatistics` has no way to ask for the statistics of a struct field. ## What changes are included in this PR? ```diff PruningStatistics (datafusion-common) min_values(&Column) / max_values / null_counts + min_values_for_field(&Column, path: &[String]) // default: None + max_values_for_field / null_counts_for_field PruningPredicate (datafusion-pruning) ColumnReferenceCount::One(Column) + ColumnReferenceCount::One(StatsKey { column, path }) // get_field(s, 'a', ...) is one key RequiredColumns: (Column, StatisticsType, Field) + + field path per entry (empty = the column itself) + single_column() -> None when any key is a field path RowGroupPruningStatistics (datafusion-datasource-parquet) + *_for_field: field path -> Parquet leaf -> StatisticsConverter::from_column_index ``` A field path is only accepted when every step is a struct field and the leaf is not nested. Map lookups and paths below a list (per-element statistics) are rejected. `datafusion-pruning` does not depend on `datafusion-functions`, so it matches `get_field` by name. A function-agnostic accessor trait would let `variant_get` opt in later (https://github.com/apache/datafusion/issues/21306). Review commit by commit: 1. `test:` adds `parquet_struct_field_pruning.slt` with today's output (no pruning). 2. `refactor:` keys `RequiredColumns` / `PruningExpressionBuilder` by column + path. No behavior change. 3. `feat:` adds the `*_for_field` methods to `PruningStatistics`, with `None` defaults. 4. `feat:` recognizes `get_field` in `PruningPredicate`. Plans gain a `pruning_predicate`, but nothing is pruned yet. 5. `feat:` implements the methods for Parquet row groups. The slt diff shows the pruning. 6. `test:` unit tests for rejected shapes and `single_column()`. Not included: page index pruning (follow-up), and file-level pruning, which needs nested `Statistics` (https://github.com/apache/datafusion/issues/20707). ## What is the testing strategy for this PR? `parquet_struct_field_pruning.slt` covers 4 row groups, including a null struct and a null leaf, plus 2 files: | Query | Before | After | |---|---|---| | `s['a'] > 15` | 4 → 4 matched | 4 → 2 matched | | `s['a'] <= 2`, `11 = s['a']`, `s['a'] = 20` | 4 → 4 | 4 → 1 | | `s['a'] > 25 OR id < 2` | 4 → 4 | 4 → 3 | | `s['a'] > s['b']` | 4 → 4 | 4 → 4 (not prunable) | | 2 files, `s['a'] < 10` | 2 → 2 | 2 → 1 | Unit tests in `pruning_predicate.rs` cover the rejected shapes and `single_column()`. ## Are there any user-facing changes? Fewer row groups are read for struct field predicates. `EXPLAIN` shows a `pruning_predicate` such as `s.a_null_count@1 != row_count@2 AND s.a_max@0 > 15`. API: three new provided methods on `PruningStatistics`. Existing implementations keep compiling. `RequiredColumns::single_column()` now returns `None` for predicates that touch a struct field. **Door:** two-way. Revert restores the old plans. **Blast radius:** pruning. A wrong field-to-leaf mapping or wrong null count would prune row groups that hold matching rows (wrong results). The checks above and the null-struct / null-leaf slt cases target that. 🤖 Generated with [Claude Code](https://claude.com/claude-code) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
