You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2023/01/11 21:34:29 UTC
[GitHub] [arrow-datafusion] jonmmease opened a new pull request, #4878: Fix column indices in EnforceDistribution optimizer in Partial AggregateMode
jonmmease opened a new pull request, #4878:
URL: https://github.com/apache/arrow-datafusion/pull/4878
# Which issue does this PR close?
Closes #4873.
# Rationale for this change
See #4873 for a failing example and some preliminary investigation.
The issue is in the EnforceDistribution physical optimizer (the query from the issue works without it). After looking at this for a while, I think I see what's going on. Normally, the column expressions for a group by have indices that correspond to the schema of the input operation. But for the case of a partial aggregation, these indices need to be updated to correspond to the schema of the partial aggregation instead of the input.
This make sense to me, and it fixes the query, but this is the first time I've looked at the Physical optimizer so someone who's more familiar with that side of things should definitely take a look before merging this.
# Are these changes tested?
I added a test case based on the query reported in the issue.
--
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 #4878: Fix column indices in EnforceDistribution optimizer in Partial AggregateMode
Posted by GitBox <gi...@apache.org>.
alamb commented on code in PR #4878:
URL: https://github.com/apache/arrow-datafusion/pull/4878#discussion_r1068729877
##########
datafusion/core/src/physical_optimizer/dist_enforcement.rs:
##########
@@ -431,9 +431,22 @@ fn reorder_aggregate_keys(
None
};
if let Some(partial_agg) = new_partial_agg {
+ // Build new group expressions that correspond to the schema of partial_agg
let mut new_group_exprs = vec![];
- for idx in positions.into_iter() {
- new_group_exprs.push(group_by.expr()[idx].clone());
+ for (idx, position) in positions.into_iter().enumerate() {
+ let (group_expr, name) = group_by.expr()[position].clone();
+
+ // Update the index of columns so that they correspond to the schema of partial_agg
+ // rather than input_schema.
+ let group_expr = if let Some(group_col) =
+ group_expr.as_any().downcast_ref::<Column>()
+ {
+ Arc::new(Column::new(group_col.name(), idx))
+ as Arc<dyn PhysicalExpr>
Review Comment:
I think you can do something like this to get the rust compiler to do the right cast for you:
```suggestion
as _
```
However the rest of this module is in the same `as Arc<...>` style so no need to change it in this PR
##########
datafusion/core/tests/sql/joins.rs:
##########
@@ -2810,3 +2810,61 @@ async fn type_coercion_join_with_filter_and_equi_expr() -> Result<()> {
Ok(())
}
+
+#[tokio::test]
+async fn test_cross_join_to_groupby_with_different_key_ordering() -> Result<()> {
Review Comment:
I verified that this test does indeed panic without the test code
```
---- sql::joins::test_cross_join_to_groupby_with_different_key_ordering stdout ----
thread 'sql::joins::test_cross_join_to_groupby_with_different_key_ordering' panicked at 'called `Option::unwrap()` on a `None` value', datafusion/core/src/physical_plan/joins/hash_join.rs:923:17
stack backtrace:
```
--
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] mingmwang commented on a diff in pull request #4878: Fix column indices in EnforceDistribution optimizer in Partial AggregateMode
Posted by GitBox <gi...@apache.org>.
mingmwang commented on code in PR #4878:
URL: https://github.com/apache/arrow-datafusion/pull/4878#discussion_r1069156078
##########
datafusion/core/src/physical_optimizer/dist_enforcement.rs:
##########
@@ -431,9 +431,22 @@ fn reorder_aggregate_keys(
None
};
if let Some(partial_agg) = new_partial_agg {
+ // Build new group expressions that correspond to the schema of partial_agg
let mut new_group_exprs = vec![];
- for idx in positions.into_iter() {
- new_group_exprs.push(group_by.expr()[idx].clone());
+ for (idx, position) in positions.into_iter().enumerate() {
+ let (group_expr, name) = group_by.expr()[position].clone();
+
+ // Update the index of columns so that they correspond to the schema of partial_agg
+ // rather than input_schema.
+ let group_expr = if let Some(group_col) =
+ group_expr.as_any().downcast_ref::<Column>()
+ {
+ Arc::new(Column::new(group_col.name(), idx))
+ as Arc<dyn PhysicalExpr>
Review Comment:
Good catch!! It is a bug.
--
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] metesynnada commented on pull request #4878: Fix column indices in EnforceDistribution optimizer in Partial AggregateMode
Posted by GitBox <gi...@apache.org>.
metesynnada commented on PR #4878:
URL: https://github.com/apache/arrow-datafusion/pull/4878#issuecomment-1382624799
LGTM, good work 😀
--
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] mingmwang commented on a diff in pull request #4878: Fix column indices in EnforceDistribution optimizer in Partial AggregateMode
Posted by GitBox <gi...@apache.org>.
mingmwang commented on code in PR #4878:
URL: https://github.com/apache/arrow-datafusion/pull/4878#discussion_r1069156078
##########
datafusion/core/src/physical_optimizer/dist_enforcement.rs:
##########
@@ -431,9 +431,22 @@ fn reorder_aggregate_keys(
None
};
if let Some(partial_agg) = new_partial_agg {
+ // Build new group expressions that correspond to the schema of partial_agg
let mut new_group_exprs = vec![];
- for idx in positions.into_iter() {
- new_group_exprs.push(group_by.expr()[idx].clone());
+ for (idx, position) in positions.into_iter().enumerate() {
+ let (group_expr, name) = group_by.expr()[position].clone();
+
+ // Update the index of columns so that they correspond to the schema of partial_agg
+ // rather than input_schema.
+ let group_expr = if let Some(group_col) =
+ group_expr.as_any().downcast_ref::<Column>()
+ {
+ Arc::new(Column::new(group_col.name(), idx))
+ as Arc<dyn PhysicalExpr>
Review Comment:
Good catch!! It is a bug.
Regarding the fix, can we call this method to get the new `new_group_exprs` ?
`let new_group_exprs: Vec<Arc<dyn PhysicalExpr>> = partial_agg.output_group_expr();`
--
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] jonmmease commented on pull request #4878: Fix column indices in EnforceDistribution optimizer in Partial AggregateMode
Posted by GitBox <gi...@apache.org>.
jonmmease commented on PR #4878:
URL: https://github.com/apache/arrow-datafusion/pull/4878#issuecomment-1381775464
Thanks for taking a look @alamb @mingmwang @metesynnada! I made the simplification @mingmwang suggested in [f32a8d9](https://github.com/apache/arrow-datafusion/pull/4878/commits/f32a8d922cc300ebafb8b1eab000a3fd3b82632c).
--
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 #4878: Fix column indices in EnforceDistribution optimizer in Partial AggregateMode
Posted by GitBox <gi...@apache.org>.
ursabot commented on PR #4878:
URL: https://github.com/apache/arrow-datafusion/pull/4878#issuecomment-1382720054
Benchmark runs are scheduled for baseline = a9ddcd3a7558437361835120659b946b903468e1 and contender = dee0dd8be6745f6cb798ba56dca6c1b936d90fd6. dee0dd8be6745f6cb798ba56dca6c1b936d90fd6 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/48ac5ff24bcc4068b9a468ebe020a594...5729b521c86247fd92ea0dcbf643fd9a/)
[Skipped :warning: Benchmarking of arrow-datafusion-commits is not supported on test-mac-arm] [test-mac-arm](https://conbench.ursa.dev/compare/runs/c802596350e04ba99aae30b7526840b7...532d2f38758d4532bad65577b5f5e2ed/)
[Skipped :warning: Benchmarking of arrow-datafusion-commits is not supported on ursa-i9-9960x] [ursa-i9-9960x](https://conbench.ursa.dev/compare/runs/904f6fddd4db4c55a25bb62fbc0c3676...f5537282ca60457da3cbf429dde80959/)
[Skipped :warning: Benchmarking of arrow-datafusion-commits is not supported on ursa-thinkcentre-m75q] [ursa-thinkcentre-m75q](https://conbench.ursa.dev/compare/runs/90b8241546494027a2197d5a0c601209...1e9ea20281fd469c98a106eefdaab8b1/)
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
[GitHub] [arrow-datafusion] alamb merged pull request #4878: Fix column indices in EnforceDistribution optimizer in Partial AggregateMode
Posted by GitBox <gi...@apache.org>.
alamb merged PR #4878:
URL: https://github.com/apache/arrow-datafusion/pull/4878
--
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 pull request #4878: Fix column indices in EnforceDistribution optimizer in Partial AggregateMode
Posted by GitBox <gi...@apache.org>.
alamb commented on PR #4878:
URL: https://github.com/apache/arrow-datafusion/pull/4878#issuecomment-1382718536
Thank you everyone for your help!
--
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] mingmwang commented on pull request #4878: Fix column indices in EnforceDistribution optimizer in Partial AggregateMode
Posted by GitBox <gi...@apache.org>.
mingmwang commented on PR #4878:
URL: https://github.com/apache/arrow-datafusion/pull/4878#issuecomment-1381620794
Regarding the fix, I think you can call below methods to simply the logic. I had test it on my local and it works.
```rust
// Build new group expressions that correspond to the output of partial_agg
let new_final_group: Vec<Arc<dyn PhysicalExpr>> =
partial_agg.output_group_expr();
let new_group_by= PhysicalGroupBy::new_single(
new_final_group
.iter()
.enumerate()
.map(|(i, expr)| (expr.clone(), partial_agg.group_expr().expr()[i].1.clone()))
.collect(),
);
```
--
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] mingmwang commented on pull request #4878: Fix column indices in EnforceDistribution optimizer in Partial AggregateMode
Posted by GitBox <gi...@apache.org>.
mingmwang commented on PR #4878:
URL: https://github.com/apache/arrow-datafusion/pull/4878#issuecomment-1381532449
The Column Index in the physical plan is confusing and error prone, I will take a closer look at this PR.
--
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