You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "jackwener (via GitHub)" <gi...@apache.org> on 2023/02/28 04:33:30 UTC

[GitHub] [arrow-datafusion] jackwener commented on a diff in pull request #5425: Fix filter pushdown for extension plans

jackwener commented on code in PR #5425:
URL: https://github.com/apache/arrow-datafusion/pull/5425#discussion_r1119564307


##########
datafusion/optimizer/src/push_down_filter.rs:
##########
@@ -735,6 +735,48 @@ impl OptimizerRule for PushDownFilter {
                     None => new_scan,
                 }
             }
+            LogicalPlan::Extension(extension_plan) => {
+                let prevent_cols =
+                    extension_plan.node.prevent_predicate_push_down_columns();
+
+                let predicates = utils::split_conjunction_owned(filter.predicate.clone());
+
+                let mut keep_predicates = vec![];
+                let mut push_predicates = vec![];
+                for expr in predicates {
+                    let cols = expr.to_columns()?;
+                    if cols.iter().any(|c| prevent_cols.contains(&c.name)) {
+                        keep_predicates.push(expr);
+                    } else {
+                        push_predicates.push(expr);
+                    }
+                }
+
+                let new_children = match conjunction(push_predicates) {
+                    Some(predicate) => extension_plan
+                        .node
+                        .inputs()
+                        .into_iter()
+                        .map(|child| {
+                            Ok(LogicalPlan::Filter(Filter::try_new(
+                                predicate.clone(),
+                                Arc::new(child.clone()),
+                            )?))
+                        })
+                        .collect::<Result<Vec<_>>>()?,
+                    None => extension_plan.node.inputs().into_iter().cloned().collect(),
+                };
+                let new_extension =
+                    from_plan(&filter.input, &filter.input.expressions(), &new_children)?;

Review Comment:
   ```suggestion
                   // extension with new inputs.
                   let new_extension = child_plan.with_new_inputs(&new_children)?;
   ```



-- 
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-unsubscribe@arrow.apache.org

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