adriangb opened a new pull request, #27975: URL: https://github.com/apache/datafusion/pull/27975
## Which issue does this PR close? - Part of https://github.com/apache/datafusion/issues/20871. It is split out of https://github.com/apache/datafusion/pull/27736, which changes this code to read statistics of struct fields. This PR does not depend on that one and is useful without it. ## Rationale for this change `PagePruningAccessPlanFilter::prune_plan_with_page_index_and_metrics` is one function of about 250 lines with 11 mutable locals. It mixes four things: ```text prune_plan_with_page_index_and_metrics about 250 lines guards (3 early returns) build inverse predicates only for LIMIT for each row group skip if fully matched for each predicate -> selection, matched pages apply selection to the access plan, count rows for each inverse predicate -> fully matched rows, only for LIMIT count pages write 4 metrics apply the LIMIT plan ``` The LIMIT path is the hardest part to follow, and it sits in the middle of ordinary pruning. The same four references to the file (`arrow_schema`, `parquet_schema`, `parquet_metadata`, `file_metrics`) go to every helper. ## What changes are included in this PR? `PagePruner` holds the file and the counts of one pass. Each step is one method: ```text prune_plan_with_page_index_and_metrics about 100 lines guards inverted_predicates() only for LIMIT for each row group skip if fully matched pruner.prune_row_group() pruner.apply_selection() pruner.fully_matched_selection() only for LIMIT pruner.counts.add_to(metrics) apply the LIMIT plan ``` | New item | Replaces | |---|---| | `PagePruner::prune_row_group` | The loop over the predicates, and the page counters | | `PagePruner::apply_selection` | The update of the access plan, and the row counters | | `PagePruner::fully_matched_selection` | The loop over the inverse predicates, with its `complete` flag | | `PagePruner::prune_pages_for_predicate` | The free function of the same name with six arguments | | `PagePruner::page_count` | `fully_matched_page_count`, and an inline copy of the same expression | | `PagePruner::has_complete_page_index` | The inline check and its debug message | | `PagePruningCounts` | Four `let mut total_*` and the four metric writes | | `PagePruningAccessPlanFilter::inverted_predicates` | The inline closure | No behavior changes. The points that could change it, and that I checked against the old code: - The order of the early returns. - When the row and page counts are updated. Page counts are still added once per row group that is not fully matched. - The number of predicate evaluations on the LIMIT path. The test `inverse_pruning_short_circuits` counts them. - A row group whose inverse predicates give an empty selection is still recorded as an empty selection, and not as "unknown". ## What is the testing strategy for this PR? No new tests: this is a refactor, and the existing tests cover the code. They pass without changes: - The unit tests of `datafusion-datasource-parquet` (318), including the page filter tests for LIMIT pruning. - The Parquet integration tests in `datafusion/core/tests/parquet` (265), which assert the page index metrics. - The Parquet and LIMIT pruning sqllogictests. I did not run benchmarks. The code runs the same steps in the same order, and it keeps the two page sets that the old code reuses across row groups. ## Are there any user-facing changes? No. Every new item is private. 🤖 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]
