adriangb opened a new pull request, #27696: URL: https://github.com/apache/datafusion/pull/27696
## Which issue does this PR close? - Closes https://github.com/apache/datafusion/issues/27694. ## Rationale for this change A `TableScan` applies its filters, then its skip, then its fetch. The code does not state or enforce this order. `LogicalPlan::skip()` returns `None` for a `TableScan`, although https://github.com/apache/datafusion/pull/25404 added `TableScan::skip`. So the `PushDownFilter` guard does not see a scan skip. Each rule that adds filters to a scan must know the order by itself. SQL does not reach a wrong result today, because `PushDownLimit` sets a skip only together with a fetch. ## What changes are included in this PR? Review commit by commit: | Commit | Kind | Change | |---|---|---| | [`f9266b9`](https://github.com/apache/datafusion/commit/f9266b99641da89e6fdbd3036bfbc11377541814) | fix | `LogicalPlan::skip()` returns the scan skip. A zero skip returns `None`, the same as for `Limit`. Adds a `PushDownFilter` regression test for a scan with only a skip. | | [`58b5404`](https://github.com/apache/datafusion/commit/58b54040829414a9c84b4be8346ae4a876865351) | feat | Documents the row order on `TableScan` and adds `TableScan::try_with_filters`. | | [`3ce849d`](https://github.com/apache/datafusion/commit/3ce849de2ff123b6bc44ce6214b35b51851de469) | refactor | The `TableScan` arm of `PushDownFilter::rewrite` uses `try_with_filters`. No behavior change. | Design notes: - `try_with_filters` returns `Result<Self, Self>`, not `Option<Self>` as the issue sketches. The caller gets the scan back on refusal and can rebuild the plan without a clone. - It replaces the filters (like `TableScanBuilder::with_filters`). It does not append. - A `Some(0)` skip counts as no skip. A `Some(0)` fetch still refuses. - The general fetch and skip guard in `PushDownFilter` stays, because `Sort` and `Limit` also need it. So the `Err` arm in the `TableScan` arm is not reachable today. - `push_down_into_table_scan` does not exist on `main`. https://github.com/apache/datafusion/pull/26281 adds it and should use `try_with_filters` too. Related ideas, not in this PR: - Add tests that optimize an already optimized plan. The bugs in https://github.com/apache/datafusion/issues/21063 and https://github.com/apache/datafusion/pull/26281 appear only in that case. - `PartialEq`, `Hash` and `PartialOrd` for `TableScan` ignore `skip`. ## What is the testing strategy for this PR? - `table_scan_skip` in `plan.rs`: `LogicalPlan::skip()` for `None`, `Some(0)` and `Some(3)`. - `table_scan_try_with_filters` in `plan.rs`: accepts a plain scan and a zero skip, refuses a skip, a fetch and a zero fetch. - `filter_not_pushed_down_through_table_scan_with_skip` in `push_down_filter.rs`. - The existing fetch guard tests and the sqllogictest suite pass. ## Are there any user-facing changes? Yes, for library users. `LogicalPlan::skip()` returns the skip of a `TableScan`, and `TableScan::try_with_filters` is a new public method. No API breaks, so the upgrade guide does not change. 🤖 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]
