Repository navigation
Simplify Filter Pushdown APIs for Better Maintainability and Developer Experience #16188
Description
Is your feature request related to a problem or challenge?
The current filter pushdown APIs in DataFusion (FilterPushdownPropagation, PredicateSupports, etc.) have grown organically but now appear convoluted and redundant. The complex layering of abstractions makes the filter pushdown mechanism difficult to understand, maintain, and extend.
Specific issues include:
- Multiple overlapping abstraction layers (PredicateSupport, PredicateSupports, FilterDescription, etc.)
- Redundant helper methods with inconsistent naming patterns (.unsupported(), .transparent(), .with_filters(), .with_updated_node(), .new_with_supported_check(), .collect_supported(), .is_all_supported(), etc.)
- Complex mental model requiring developers to track multiple states and transformations
- Lack of clear documentation about the conceptual model and flow
- Inconsistent naming conventions (e.g., all_supported creates new objects while make_supported transforms existing ones)
These issues increase the learning curve for new contributors and make maintenance more challenging for all developers.
Describe the solution you'd like
Redesign the filter pushdown APIs with a focus on simplicity, consistency, and clarity:
-
Reduce abstraction layers: Consolidate the multiple wrappers into fewer, more focused data structures.
-
Consistent API patterns: Use clear naming conventions:
- with_* for non-mutating methods that return new objects
- mark_* for transformations
- collect_* for extraction methods
- Simplified core data structures:
/// A predicate with its support status for pushdown
enum PredicateWithSupport {
Supported(Arc<dyn PhysicalExpr>),
Unsupported(Arc<dyn PhysicalExpr>),
}
/// Collection of predicates with clearly defined operations
struct Predicates {
// Core operations that are intuitive to use
// ...
}
/// Clear result type for pushdown operations
struct FilterPushdownResult<T> {
pushed_predicates: Vec<Arc<dyn PhysicalExpr>>,
retained_predicates: Vec<Arc<dyn PhysicalExpr>>,
updated_plan: Option<T>,
}-
More declarative approach: Let execution plan nodes declare which predicates they support rather than relying on complex negotiation.
-
Better documentation: Add clear documentation about the mental model, flow, and expected usage patterns.
-
Test coverage: Ensure robust test coverage for the new APIs to prevent regressions.
This redesign should aim to reduce cognitive load for developers while maintaining all current functionality. It should also make future extensions to the filter pushdown system more straightforward.
Describe alternatives you've considered
No response
Additional context
The current implementation reflects the complexity of the problem space, but I believe it could be made more approachable with a clearer design focused on the essential operations and better documentation of the conceptual model.
Activity
adriangb commentedon May 28, 2025
Thank you @kosiew.
Clearly what we have now needs work but I think I'd like to defer cleaning this up until some other folks try to implement more things with these APIs (e.g. join filter pushdown) which will give us both:
@alamb does that sound reasonable? It means any changes are more of a breaking change but since these APIs are very new and complex I think it's reasonable to have a bit of churn before they stabilize.
alamb commentedon May 28, 2025
Thank you for this ticket @kosiew and @adriangb
In general I agree with the premise that making the filter pushdown APIs easier to use / understand would be very valuable to DataFusion -- the goals @kosiew describe all sound wonderful to me
I think the key question would be exactly what the new API would look like and how much API churn it would entail
I do think getting more ideas would be valuable and I would enjoy reviewing proposals. As @adriangb mentions, one thing that might help drive / force these API changes is trying to add new features.
xudong963 commentedon May 29, 2025
I still don't get a chance to read the whole Filter pushdown APIs, but will do in a week, then will give some feedback.
xudong963 commentedon Jun 20, 2025
@kosiew 's suggestions look good to me, I have one another question about
FilterPushdownPhase::Pre:IMO,
FilterPushdownPhase::Preruns before most other physical optimizations, It only handles "static filters that do not reference any ExecutionPlans", this type of static filter pushdown should logically belong in the logical optimization phase.Is there a duplication with
push_down_filterin the logical optimizer?IMO, we should only process dynamic filters in the physical filter push down optimizer rule and highlight the point, to avoid confusion and duplication
adriangb commentedon Jun 20, 2025
I don't think so. The logical optimizer pushes things down into the table scan phase, the physical optimizer rule pushes them down into the actual physical scan, e.g. parquet accepts pushdown but CSV does not (I think).
But I hear you!
Thinking about it a bit I think what would make the most sense is that the logical optimizer pushes down into the TableScan and then the TableProvider attaches them to the DataSourceExec that it creates. That's kind of how it was before, but it created a lot of duplication and special casing. See #15769. The main con of having TableProvider attach the filters to the scan is that implementing it correctly is quite cumbersome and makes custom TableProvider's more complex, with TableProvider being one of the most common hooks in DataFusion. Having that happen as an optimizer rule keeps the complexity out of the TableProvider. But maybe we should have made it work with a refactor to TableProvider e.g. to return not only an ExecutionPlan but also filter pushdown results or something.
alamb commentedon Jun 20, 2025
In my opinion there is duplication in the sense that they both do similar things (push filters down in the plan) but for the reasons that @adriangb mentions we can't combine them
It is interesting that InfluxData also ended up with its own physical rule to push filters down (in our case for other reasons)
Thus I think it is inevitable that we'll have similar functonality in both the Logical and Physical plan layers
xudong963 commentedon Jun 23, 2025
@adriangb @alamb Thank you, now I understand the background about the filter pushdown in logical & physical phases.
I see, we should keep custom TableProviders easy to implement and reduce the users' burden. It's fair to keep the current status. Thanks for your detailed explanation.
xudong963 commentedon Jun 23, 2025
FYI, I added more doc for the related code based on my understanding: #16504
alamb commentedon Jun 23, 2025
That writeup is 🧑🍳 👌 really nice