You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "thinkharderdev (via GitHub)" <gi...@apache.org> on 2023/02/27 18:54:40 UTC
[GitHub] [arrow-datafusion] thinkharderdev opened a new pull request, #5425: Fix filter pushdown for extension plans
thinkharderdev opened a new pull request, #5425:
URL: https://github.com/apache/arrow-datafusion/pull/5425
# Which issue does this PR close?
<!--
We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123.
-->
Closes #5424
# Rationale for this change
<!--
Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed.
Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes.
-->
# What changes are included in this PR?
<!--
There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR.
-->
# Are these changes tested?
<!--
We typically require tests for all PRs in order to:
1. Prevent the code from being accidentally broken by subsequent changes
2. Serve as another way to document the expected behavior of the code
If tests are not included in your PR, please explain why (for example, are they covered by existing tests)?
-->
Yes
# Are there any user-facing changes?
<!--
If there are user-facing changes then we may require documentation to be updated before approving the PR.
-->
Predicates will be pushed down through extension plan nodes
<!--
If there are any breaking changes to public APIs, please add the `api change` label.
-->
No
--
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
[GitHub] [arrow-datafusion] jackwener commented on a diff in pull request #5425: Fix filter pushdown for extension plans
Posted by "jackwener (via GitHub)" <gi...@apache.org>.
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
[GitHub] [arrow-datafusion] alamb commented on a diff in pull request #5425: Fix filter pushdown for extension plans
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #5425:
URL: https://github.com/apache/arrow-datafusion/pull/5425#discussion_r1119315050
##########
datafusion/optimizer/src/push_down_filter.rs:
##########
@@ -1029,6 +1074,131 @@ mod tests {
assert_optimized_plan_eq(&plan, expected)
}
+ #[derive(Debug)]
+ struct NoopPlan {
+ input: Vec<LogicalPlan>,
+ schema: DFSchemaRef,
+ }
+
+ impl UserDefinedLogicalNode for NoopPlan {
+ fn as_any(&self) -> &dyn Any {
+ self
+ }
+
+ fn inputs(&self) -> Vec<&LogicalPlan> {
+ self.input.iter().collect()
+ }
+
+ fn schema(&self) -> &DFSchemaRef {
+ &self.schema
+ }
+
+ fn expressions(&self) -> Vec<Expr> {
+ self.input
+ .iter()
+ .flat_map(|child| child.expressions())
+ .collect()
+ }
+
+ fn prevent_predicate_push_down_columns(&self) -> HashSet<String> {
+ HashSet::from_iter(vec!["c".to_string()])
+ }
+
+ fn fmt_for_explain(&self, f: &mut Formatter) -> std::fmt::Result {
+ write!(f, "NoopPlan")
+ }
+
+ fn from_template(
+ &self,
+ _exprs: &[Expr],
+ inputs: &[LogicalPlan],
+ ) -> Arc<dyn UserDefinedLogicalNode> {
+ Arc::new(Self {
+ input: inputs.to_vec(),
+ schema: self.schema.clone(),
+ })
+ }
+ }
+
+ #[test]
+ fn user_defined_plan() -> Result<()> {
+ let table_scan = test_table_scan()?;
+
+ let custom_plan = LogicalPlan::Extension(Extension {
+ node: Arc::new(NoopPlan {
+ input: vec![table_scan.clone()],
+ schema: table_scan.schema().clone(),
+ }),
+ });
+ let plan = LogicalPlanBuilder::from(custom_plan)
+ .filter(col("a").eq(lit(1i64)))?
+ .build()?;
+
+ // Push filter below NoopPlan
+ let expected = "\
+ NoopPlan\
+ \n Filter: test.a = Int64(1)\
+ \n TableScan: test";
+ assert_optimized_plan_eq(&plan, expected)?;
+
+ let custom_plan = LogicalPlan::Extension(Extension {
+ node: Arc::new(NoopPlan {
+ input: vec![table_scan.clone()],
+ schema: table_scan.schema().clone(),
+ }),
+ });
+ let plan = LogicalPlanBuilder::from(custom_plan)
+ .filter(col("a").eq(lit(1i64)).and(col("c").eq(lit(2i64))))?
+ .build()?;
+
+ // Push only predicate on `a` below NoopPlan
Review Comment:
👍
--
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
[GitHub] [arrow-datafusion] thinkharderdev merged pull request #5425: Fix filter pushdown for extension plans
Posted by "thinkharderdev (via GitHub)" <gi...@apache.org>.
thinkharderdev merged PR #5425:
URL: https://github.com/apache/arrow-datafusion/pull/5425
--
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
[GitHub] [arrow-datafusion] ursabot commented on pull request #5425: Fix filter pushdown for extension plans
Posted by "ursabot (via GitHub)" <gi...@apache.org>.
ursabot commented on PR #5425:
URL: https://github.com/apache/arrow-datafusion/pull/5425#issuecomment-1448156011
Benchmark runs are scheduled for baseline = c676d1026f8fa25c1495ec139b8a379ce1f2f86b and contender = c477fc0ca991cfb84d8d6f082879e969761d9125. c477fc0ca991cfb84d8d6f082879e969761d9125 is a master commit associated with this PR. Results will be available as each benchmark for each run completes.
Conbench compare runs links:
[Skipped :warning: Benchmarking of arrow-datafusion-commits is not supported on ec2-t3-xlarge-us-east-2] [ec2-t3-xlarge-us-east-2](https://conbench.ursa.dev/compare/runs/7e976e71922a41bf8606f1cbb1a0ff98...ecd37d3a08b34f64b027676d1d1dc31a/)
[Skipped :warning: Benchmarking of arrow-datafusion-commits is not supported on test-mac-arm] [test-mac-arm](https://conbench.ursa.dev/compare/runs/35f6c78895da44b0ab935cf853b0a182...33155bb9810142ce9b9767ba60a716dd/)
[Skipped :warning: Benchmarking of arrow-datafusion-commits is not supported on ursa-i9-9960x] [ursa-i9-9960x](https://conbench.ursa.dev/compare/runs/aff3bde7f323481eac659c6a9fb6ab88...db228f0fe0ed4ff6a1df1ab52a75414b/)
[Skipped :warning: Benchmarking of arrow-datafusion-commits is not supported on ursa-thinkcentre-m75q] [ursa-thinkcentre-m75q](https://conbench.ursa.dev/compare/runs/fafb62b1637e44aa834bbc21a95f0e98...28d3df49a8ed4f43b384c18b88954875/)
Buildkite builds:
Supported benchmarks:
ec2-t3-xlarge-us-east-2: Supported benchmark langs: Python, R. Runs only benchmarks with cloud = True
test-mac-arm: Supported benchmark langs: C++, Python, R
ursa-i9-9960x: Supported benchmark langs: Python, R, JavaScript
ursa-thinkcentre-m75q: Supported benchmark langs: C++, Java
--
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