adriangb commented on code in PR #15770:
URL: https://github.com/apache/datafusion/pull/15770#discussion_r2052761831


##########
datafusion/physical-optimizer/src/push_down_filter.rs:
##########
@@ -382,7 +383,7 @@ impl PhysicalOptimizerRule for PushdownFilter {
 
         context
             .transform_up(|node| {
-                if node.plan.as_any().downcast_ref::<FilterExec>().is_some() {
+                if node.plan.as_any().downcast_ref::<FilterExec>().is_some() 
|| node.plan.as_any().downcast_ref::<SortExec>().is_some() {

Review Comment:
   I propose an API something like this:
   
   ```rust
   trait ExecutionPlan {
       fn gather_filters_for_pushdown(
           &self,
           parent_filters: &[Arc<dyn ExecutionPlan>],
       ) -> Result<FilterPushdownPlan> {
           let unsupported = vec![FilterPushdownSupport::Unsupported; 
parent_filters.len()];
           Ok(
               FilterPushdownPlan {
                   parent_filters_for_children: vec![unsupported; 
self.children().len()],
                   self_filters_for_children: vec![vec![]; 
self.children().len()],
               },
           )
       }
   
       fn propagate_filter_pushdown(
           &self,
           parent_pushdown_result: Vec<FilterPushdowChildResult>,
           _self_filter_pushdown_result: Vec<FilterPushdowChildResult>,
       ) -> Result<FilterPushdownPropagation> {
           Ok(
               FilterPushdownPropagation {
                   parent_filter_result: parent_pushdown_result,
                   new_node: None,
               },
           )
       }
   }
   
   pub struct FilterPushdownPropagation {
       parent_filter_result: Vec<FilterPushdowChildResult>,
       new_node: Option<Arc<dyn ExecutionPlan>>,
   }
   
   
   #[derive(Debug, Clone, Copy)]
   pub enum FilterPushdowChildResult {
       Supported,
       Unsupported,
   }
   
   impl FilterPushdowChildResult {
   
   }
   
   #[derive(Debug, Clone)]
   pub enum FilterPushdownSupport {
       Supported(Arc<dyn PhysicalExpr>),
       Unsupported,
   }
   
   #[derive(Debug, Clone)]
   pub struct FilterPushdownPlan {
       parent_filters_for_children: Vec<Vec<FilterPushdownSupport>>,
       self_filters_for_children: Vec<Vec<FilterPushdownSupport>>,
   }
   ```
   
   The optimizer rule will have to do a bit of bookeeping and slicing correctly 
but this should avoid the need for any downcast matching or `retry` and 
minimize clones of plans. And it should do one walk down and up regardless of 
what ends up happening with the filters.



-- 
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: github-unsubscr...@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org
For additional commands, e-mail: github-h...@datafusion.apache.org

Reply via email to