You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "haohuaijin (via GitHub)" <gi...@apache.org> on 2023/12/07 13:42:21 UTC
[PR] fix: don't unifies projection if expr is non-trival [arrow-datafusion]
haohuaijin opened a new pull request, #8454:
URL: https://github.com/apache/arrow-datafusion/pull/8454
## 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 #8453
## 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.
-->
don't unifies projection if the expression in non-trival. see discussion in #8296
## 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)?
-->
## Are there any user-facing changes?
add physical plan check in `.slt` test
<!--
If there are user-facing changes then we may require documentation to be updated before approving the PR.
-->
<!--
If there are any breaking changes to public APIs, please add the `api change` label.
-->
--
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
Re: [PR] fix: don't unifies projection if expr is non-trival [arrow-datafusion]
Posted by "Weijun-H (via GitHub)" <gi...@apache.org>.
Weijun-H commented on code in PR #8454:
URL: https://github.com/apache/arrow-datafusion/pull/8454#discussion_r1420125094
##########
datafusion/core/src/physical_optimizer/projection_pushdown.rs:
##########
@@ -265,6 +290,12 @@ fn try_unifying_projections(
.map(|e| Some(Arc::new(e) as _))
}
+// check if the expr trival
Review Comment:
nit:
```suggestion
/// Checks if the given expression is trivial.
/// An expression is considered trivial if it is either a `Column` or a `Literal`.
```
--
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
Re: [PR] fix: don't unifies projection if expr is non-trival [arrow-datafusion]
Posted by "haohuaijin (via GitHub)" <gi...@apache.org>.
haohuaijin commented on code in PR #8454:
URL: https://github.com/apache/arrow-datafusion/pull/8454#discussion_r1419900172
##########
datafusion/core/src/physical_optimizer/projection_pushdown.rs:
##########
@@ -245,12 +246,36 @@ fn try_swapping_with_streaming_table(
}
/// Unifies `projection` with its input (which is also a [`ProjectionExec`]).
-/// Two consecutive projections can always merge into a single projection.
fn try_unifying_projections(
projection: &ProjectionExec,
child: &ProjectionExec,
) -> Result<Option<Arc<dyn ExecutionPlan>>> {
let mut projected_exprs = vec![];
+ let mut column_ref_map: HashMap<Column, usize> = HashMap::new();
+
+ // Collect the column references usage in the outer projection.
+ projection.expr().iter().for_each(|(expr, _)| {
Review Comment:
We don't prevent `Column` and `Literal` push_down. We prevent other express push_down, used to prevent multiple evaluation of the same expression.
```rust
if column_ref_map.iter().any(|(column, count)| {
*count > 1 && !is_expr_trivial(&child.expr()[column.index()].0.clone())
}) {
return Ok(None);
}
```
--
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
Re: [PR] fix: don't unifies projection if expr is non-trival [arrow-datafusion]
Posted by "haohuaijin (via GitHub)" <gi...@apache.org>.
haohuaijin commented on code in PR #8454:
URL: https://github.com/apache/arrow-datafusion/pull/8454#discussion_r1420129886
##########
datafusion/core/src/physical_optimizer/projection_pushdown.rs:
##########
@@ -265,6 +290,12 @@ fn try_unifying_projections(
.map(|e| Some(Arc::new(e) as _))
}
+// check if the expr trival
Review Comment:
Good.
--
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
Re: [PR] fix: don't unifies projection if expr is non-trival [arrow-datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb merged PR #8454:
URL: https://github.com/apache/arrow-datafusion/pull/8454
--
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
Re: [PR] fix: don't unifies projection if expr is non-trival [arrow-datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #8454:
URL: https://github.com/apache/arrow-datafusion/pull/8454#discussion_r1419729028
##########
datafusion/core/src/physical_optimizer/projection_pushdown.rs:
##########
@@ -245,12 +246,36 @@ fn try_swapping_with_streaming_table(
}
/// Unifies `projection` with its input (which is also a [`ProjectionExec`]).
-/// Two consecutive projections can always merge into a single projection.
fn try_unifying_projections(
projection: &ProjectionExec,
child: &ProjectionExec,
) -> Result<Option<Arc<dyn ExecutionPlan>>> {
let mut projected_exprs = vec![];
+ let mut column_ref_map: HashMap<Column, usize> = HashMap::new();
+
+ // Collect the column references usage in the outer projection.
+ projection.expr().iter().for_each(|(expr, _)| {
Review Comment:
I may be mistaken and it may not matter, but I think this will prevent pushing down exprs that refer to the same column more than once
```
Projection exprs=[b as c, b as d]
Projection exprs = [a as b]
```
Into
```
Projection exprs=[a as c, a as d]
```
--
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
Re: [PR] fix: don't unifies projection if expr is non-trival [arrow-datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #8454:
URL: https://github.com/apache/arrow-datafusion/pull/8454#issuecomment-1847063557
Thank you @haohuaijin,. @Weijun-H and @mustafasrepo
--
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
Re: [PR] fix: don't unifies projection if expr is non-trival [arrow-datafusion]
Posted by "haohuaijin (via GitHub)" <gi...@apache.org>.
haohuaijin commented on code in PR #8454:
URL: https://github.com/apache/arrow-datafusion/pull/8454#discussion_r1419900172
##########
datafusion/core/src/physical_optimizer/projection_pushdown.rs:
##########
@@ -245,12 +246,36 @@ fn try_swapping_with_streaming_table(
}
/// Unifies `projection` with its input (which is also a [`ProjectionExec`]).
-/// Two consecutive projections can always merge into a single projection.
fn try_unifying_projections(
projection: &ProjectionExec,
child: &ProjectionExec,
) -> Result<Option<Arc<dyn ExecutionPlan>>> {
let mut projected_exprs = vec![];
+ let mut column_ref_map: HashMap<Column, usize> = HashMap::new();
+
+ // Collect the column references usage in the outer projection.
+ projection.expr().iter().for_each(|(expr, _)| {
Review Comment:
We don't prevent `Column` and `Literal` push_down. We prevent other express push_down, used to prevent multiple evaluation of an equal expression.
```rust
if column_ref_map.iter().any(|(column, count)| {
*count > 1 && !is_expr_trivial(&child.expr()[column.index()].0.clone())
}) {
return Ok(None);
}
```
--
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