You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2021/08/02 03:13:34 UTC
[GitHub] [spark] wangyum opened a new pull request #33603: [SPARK-36376][SQL] Collapse repartitions if there is a project between them
wangyum opened a new pull request #33603:
URL: https://github.com/apache/spark/pull/33603
### What changes were proposed in this pull request?
Collapse repartitions if there is a project between them. For example:
```scala
sql("SELECT a FROM (SELECT id AS a, id AS b FROM range(10) DISTRIBUTE BY a, b) t DISTRIBUTE BY a").explain(true)
```
Before this pr:
```
== Physical Plan ==
AdaptiveSparkPlan isFinalPlan=false
+- Exchange hashpartitioning(a#0L, 5), REPARTITION_BY_COL, [id=#18]
+- Project [a#0L]
+- Exchange hashpartitioning(a#0L, b#1L, 5), REPARTITION_BY_COL, [id=#16]
+- Project [id#2L AS a#0L, id#2L AS b#1L]
+- Range (0, 10, step=1, splits=2)
```
After this pr:
```
== Physical Plan ==
AdaptiveSparkPlan isFinalPlan=false
+- Exchange hashpartitioning(a#0L, 5), REPARTITION_BY_COL, [id=#10]
+- Project [id#2L AS a#0L]
+- Range (0, 10, step=1, splits=2)
```
### Why are the changes needed?
Reduce shuffle to improve query performance.
### Does this PR introduce _any_ user-facing change?
No.
### How was this patch tested?
Unit test.
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] wangyum edited a comment on pull request #33603: [SPARK-36376][SQL] Collapse repartitions if there is a project between them
Posted by GitBox <gi...@apache.org>.
wangyum edited a comment on pull request #33603:
URL: https://github.com/apache/spark/pull/33603#issuecomment-916129725
Close it because it is not a very common case.
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] AmplabJenkins commented on pull request #33603: [SPARK-36376][SQL] Collapse repartitions if there is a project between them
Posted by GitBox <gi...@apache.org>.
AmplabJenkins commented on pull request #33603:
URL: https://github.com/apache/spark/pull/33603#issuecomment-890844774
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/141936/
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] wangyum commented on pull request #33603: [SPARK-36376][SQL] Collapse repartitions if there is a project between them
Posted by GitBox <gi...@apache.org>.
wangyum commented on pull request #33603:
URL: https://github.com/apache/spark/pull/33603#issuecomment-892524996
It seems this is the last rule needs to be considered the `Project`.
These rules may include `Project`: `RemoveRedundantAggregates`, `CombineFilters` and `PushPredicateThroughJoin`, but they will all be optimized by other rules. For example:
```sql
create table t1(a int, b int, c int) using parquet;
create table t2(x int, y int, z int) using parquet;
```
```
select x, y from (select a as x, b as y, c as z from t1 group by a, b, c) t group by x, y
=== Applying Rule org.apache.spark.sql.catalyst.optimizer.CollapseProject ===
Aggregate [x#5, y#6], [x#5, y#6] Aggregate [x#5, y#6], [x#5, y#6]
!+- Project [x#5, y#6] +- Aggregate [a#0, b#1, c#2], [a#0 AS x#5, b#1 AS y#6]
! +- Aggregate [a#0, b#1, c#2], [a#0 AS x#5, b#1 AS y#6] +- Relation default.t1[a#0,b#1,c#2] parquet
! +- Relation default.t1[a#0,b#1,c#2] parquet
```
```
select x, y from (select a as x, b as y, c as z from t1 where a > 1) t where y > 1
=== Applying Rule org.apache.spark.sql.catalyst.optimizer.PushDownPredicates ===
Project [x#0, y#1] Project [x#0, y#1]
!+- Filter (y#1 > 1) +- Project [a#3 AS x#0, b#4 AS y#1, c#5 AS z#2]
! +- Project [a#3 AS x#0, b#4 AS y#1, c#5 AS z#2] +- Filter ((a#3 > 1) AND (b#4 > 1))
! +- Filter (a#3 > 1) +- Relation default.t1[a#3,b#4,c#5] parquet
! +- Relation default.t1[a#3,b#4,c#5] parquet
```
```
select a2 from (select a as a2, x as x2 from t1 join t2 on t1.a = t2.x) t where a2 = 1
=== Applying Rule org.apache.spark.sql.catalyst.optimizer.PushDownPredicates ===
Project [a2#8] Project [a2#8]
!+- Filter (a2#8 = 1) +- Project [a#3 AS a2#8, x#10 AS x2#9]
! +- Project [a#3 AS a2#8, x#10 AS x2#9] +- Join Inner, (a#3 = x#10)
! +- Join Inner, (a#3 = x#10) :- Filter (a#3 = 1)
! :- Relation default.t1[a#3,b#4,c#5] parquet : +- Relation default.t1[a#3,b#4,c#5] parquet
! +- Relation default.t2[x#10,y#11,z#12] parquet +- Relation default.t2[x#10,y#11,z#12] parquet
```
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] SparkQA commented on pull request #33603: [SPARK-36376][SQL] Collapse repartitions if there is a project between them
Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #33603:
URL: https://github.com/apache/spark/pull/33603#issuecomment-890827358
**[Test build #141936 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/141936/testReport)** for PR 33603 at commit [`ca0b1eb`](https://github.com/apache/spark/commit/ca0b1eb7a3dbcf49068a9b70bc702cfb2808f70d).
* This patch passes all tests.
* This patch merges cleanly.
* This patch adds no public classes.
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] wangyum closed pull request #33603: [SPARK-36376][SQL] Collapse repartitions if there is a project between them
Posted by GitBox <gi...@apache.org>.
wangyum closed pull request #33603:
URL: https://github.com/apache/spark/pull/33603
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] AmplabJenkins commented on pull request #33603: [SPARK-36376][SQL] Collapse repartitions if there is a project between them
Posted by GitBox <gi...@apache.org>.
AmplabJenkins commented on pull request #33603:
URL: https://github.com/apache/spark/pull/33603#issuecomment-890733287
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder-K8s/46446/
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] SparkQA commented on pull request #33603: [SPARK-36376][SQL] Collapse repartitions if there is a project between them
Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #33603:
URL: https://github.com/apache/spark/pull/33603#issuecomment-890716700
Kubernetes integration test status success
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/46446/
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] SparkQA commented on pull request #33603: [SPARK-36376][SQL] Collapse repartitions if there is a project between them
Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #33603:
URL: https://github.com/apache/spark/pull/33603#issuecomment-890689156
**[Test build #141936 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/141936/testReport)** for PR 33603 at commit [`ca0b1eb`](https://github.com/apache/spark/commit/ca0b1eb7a3dbcf49068a9b70bc702cfb2808f70d).
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] wangyum commented on a change in pull request #33603: [SPARK-36376][SQL] Collapse repartitions if there is a project between them
Posted by GitBox <gi...@apache.org>.
wangyum commented on a change in pull request #33603:
URL: https://github.com/apache/spark/pull/33603#discussion_r684877019
##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala
##########
@@ -913,10 +913,17 @@ object CollapseRepartition extends Rule[LogicalPlan] {
case (false, true) => if (r.numPartitions >= child.numPartitions) child else r
case _ => r.copy(child = child.child)
}
+ case r @ Repartition(_, _, p @ Project(_, child: RepartitionOperation)) =>
Review comment:
Not all `RepartitionOperation` can be removed. Sometimes repartition before joining and filtering to increase parallelism, especially before `BroadcastNestedLoopJoin`.
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] AmplabJenkins removed a comment on pull request #33603: [SPARK-36376][SQL] Collapse repartitions if there is a project between them
Posted by GitBox <gi...@apache.org>.
AmplabJenkins removed a comment on pull request #33603:
URL: https://github.com/apache/spark/pull/33603#issuecomment-890733287
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder-K8s/46446/
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] cloud-fan commented on pull request #33603: [SPARK-36376][SQL] Collapse repartitions if there is a project between them
Posted by GitBox <gi...@apache.org>.
cloud-fan commented on pull request #33603:
URL: https://github.com/apache/spark/pull/33603#issuecomment-891144792
can we come up with a general solution? or do we have a list of operators that can have `Project` between them but we can still collapse?
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] wangyum commented on pull request #33603: [SPARK-36376][SQL] Collapse repartitions if there is a project between them
Posted by GitBox <gi...@apache.org>.
wangyum commented on pull request #33603:
URL: https://github.com/apache/spark/pull/33603#issuecomment-892524996
It seems this is the last rule needs to be considered the `Project`.
These rules may include `Project`: `RemoveRedundantAggregates`, `CombineFilters` and `PushPredicateThroughJoin`, but they will all be optimized by other rules. For example:
```sql
create table t1(a int, b int, c int) using parquet;
create table t2(x int, y int, z int) using parquet;
```
```
select x, y from (select a as x, b as y, c as z from t1 group by a, b, c) t group by x, y
=== Applying Rule org.apache.spark.sql.catalyst.optimizer.CollapseProject ===
Aggregate [x#5, y#6], [x#5, y#6] Aggregate [x#5, y#6], [x#5, y#6]
!+- Project [x#5, y#6] +- Aggregate [a#0, b#1, c#2], [a#0 AS x#5, b#1 AS y#6]
! +- Aggregate [a#0, b#1, c#2], [a#0 AS x#5, b#1 AS y#6] +- Relation default.t1[a#0,b#1,c#2] parquet
! +- Relation default.t1[a#0,b#1,c#2] parquet
```
```
select x, y from (select a as x, b as y, c as z from t1 where a > 1) t where y > 1
=== Applying Rule org.apache.spark.sql.catalyst.optimizer.PushDownPredicates ===
Project [x#0, y#1] Project [x#0, y#1]
!+- Filter (y#1 > 1) +- Project [a#3 AS x#0, b#4 AS y#1, c#5 AS z#2]
! +- Project [a#3 AS x#0, b#4 AS y#1, c#5 AS z#2] +- Filter ((a#3 > 1) AND (b#4 > 1))
! +- Filter (a#3 > 1) +- Relation default.t1[a#3,b#4,c#5] parquet
! +- Relation default.t1[a#3,b#4,c#5] parquet
```
```
select a2 from (select a as a2, x as x2 from t1 join t2 on t1.a = t2.x) t where a2 = 1
=== Applying Rule org.apache.spark.sql.catalyst.optimizer.PushDownPredicates ===
Project [a2#8] Project [a2#8]
!+- Filter (a2#8 = 1) +- Project [a#3 AS a2#8, x#10 AS x2#9]
! +- Project [a#3 AS a2#8, x#10 AS x2#9] +- Join Inner, (a#3 = x#10)
! +- Join Inner, (a#3 = x#10) :- Filter (a#3 = 1)
! :- Relation default.t1[a#3,b#4,c#5] parquet : +- Relation default.t1[a#3,b#4,c#5] parquet
! +- Relation default.t2[x#10,y#11,z#12] parquet +- Relation default.t2[x#10,y#11,z#12] parquet
```
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] SparkQA commented on pull request #33603: [SPARK-36376][SQL] Collapse repartitions if there is a project between them
Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #33603:
URL: https://github.com/apache/spark/pull/33603#issuecomment-890704744
Kubernetes integration test starting
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/46446/
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] cloud-fan commented on a change in pull request #33603: [SPARK-36376][SQL] Collapse repartitions if there is a project between them
Posted by GitBox <gi...@apache.org>.
cloud-fan commented on a change in pull request #33603:
URL: https://github.com/apache/spark/pull/33603#discussion_r683378320
##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala
##########
@@ -913,10 +913,17 @@ object CollapseRepartition extends Rule[LogicalPlan] {
case (false, true) => if (r.numPartitions >= child.numPartitions) child else r
case _ => r.copy(child = child.child)
}
+ case r @ Repartition(_, _, p @ Project(_, child: RepartitionOperation)) =>
Review comment:
Is `Project` the only node to deal with? how about `Filter`/`Union`?
##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala
##########
@@ -913,10 +913,17 @@ object CollapseRepartition extends Rule[LogicalPlan] {
case (false, true) => if (r.numPartitions >= child.numPartitions) child else r
case _ => r.copy(child = child.child)
}
+ case r @ Repartition(_, _, p @ Project(_, child: RepartitionOperation)) =>
Review comment:
This reminds me of `EliminateSorts`
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] wangyum commented on pull request #33603: [SPARK-36376][SQL] Collapse repartitions if there is a project between them
Posted by GitBox <gi...@apache.org>.
wangyum commented on pull request #33603:
URL: https://github.com/apache/spark/pull/33603#issuecomment-916129725
Close it because it is not a very common case
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] cloud-fan commented on a change in pull request #33603: [SPARK-36376][SQL] Collapse repartitions if there is a project between them
Posted by GitBox <gi...@apache.org>.
cloud-fan commented on a change in pull request #33603:
URL: https://github.com/apache/spark/pull/33603#discussion_r701642221
##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala
##########
@@ -913,10 +913,17 @@ object CollapseRepartition extends Rule[LogicalPlan] {
case (false, true) => if (r.numPartitions >= child.numPartitions) child else r
case _ => r.copy(child = child.child)
}
+ case r @ Repartition(_, _, p @ Project(_, child: RepartitionOperation)) =>
Review comment:
`Project` can also contain expensive computation (e.g. UDF), why it's safe to remove repartition before `Project`?
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] AmplabJenkins removed a comment on pull request #33603: [SPARK-36376][SQL] Collapse repartitions if there is a project between them
Posted by GitBox <gi...@apache.org>.
AmplabJenkins removed a comment on pull request #33603:
URL: https://github.com/apache/spark/pull/33603#issuecomment-890844774
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/141936/
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] SparkQA removed a comment on pull request #33603: [SPARK-36376][SQL] Collapse repartitions if there is a project between them
Posted by GitBox <gi...@apache.org>.
SparkQA removed a comment on pull request #33603:
URL: https://github.com/apache/spark/pull/33603#issuecomment-890689156
**[Test build #141936 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/141936/testReport)** for PR 33603 at commit [`ca0b1eb`](https://github.com/apache/spark/commit/ca0b1eb7a3dbcf49068a9b70bc702cfb2808f70d).
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org