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/03/29 10:31:18 UTC

[GitHub] [spark] ulysses-you opened a new pull request #31994: [SPARK-34899][SQL] Use origin plan if we can not coalesce shuffle partition

ulysses-you opened a new pull request #31994:
URL: https://github.com/apache/spark/pull/31994


   <!--
   Thanks for sending a pull request!  Here are some tips for you:
     1. If this is your first time, please read our contributor guidelines: https://spark.apache.org/contributing.html
     2. Ensure you have added or run the appropriate tests for your PR: https://spark.apache.org/developer-tools.html
     3. If the PR is unfinished, add '[WIP]' in your PR title, e.g., '[WIP][SPARK-XXXX] Your PR title ...'.
     4. Be sure to keep the PR description updated to reflect all changes.
     5. Please write your PR title to summarize what this PR proposes.
     6. If possible, provide a concise example to reproduce the issue for a faster review.
     7. If you want to add a new configuration, please read the guideline first for naming configurations in
        'core/src/main/scala/org/apache/spark/internal/config/ConfigEntry.scala'.
   -->
   
   ### What changes were proposed in this pull request?
   <!--
   Please clarify what changes you are proposing. The purpose of this section is to outline the changes and how this PR fixes the issue. 
   If possible, please consider writing useful notes for better and faster reviews in your PR. See the examples below.
     1. If you refactor some codes with changing classes, showing the class hierarchy will help reviewers.
     2. If you fix some SQL features, you can provide some references of other DBMSes.
     3. If there is design documentation, please add the link.
     4. If there is a discussion in the mailing list, please add the link.
   -->
   Add check if `CoalesceShufflePartitions` really coalesce shuffle partition number.
   
   ### Why are the changes needed?
   <!--
   Please clarify why the changes are needed. For instance,
     1. If you propose a new API, clarify the use case for a new API.
     2. If you fix a bug, you can clarify why it is a bug.
   -->
   The `CoalesceShufflePartitions` can not coalesce such case if the total shuffle partitions size of mappers are big enough. Then it's confused to use `CustomShuffleReaderExec` which marked as `coalesced` but has no affect with partition number.
   
   
   ### Does this PR introduce _any_ user-facing change?
   <!--
   Note that it means *any* user-facing change including all aspects such as the documentation fix.
   If yes, please clarify the previous behavior and the change this PR proposes - provide the console output, description and/or an example to show the behavior difference if possible.
   If possible, please also clarify if this is a user-facing change compared to the released Spark versions or within the unreleased branches such as master.
   If no, write 'No'.
   -->
   Probably yes, the plan changed.
   
   ### How was this patch tested?
   <!--
   If tests were added, say they were added here. Please make sure to add some test cases that check the changes thoroughly including negative and positive cases if possible.
   If it was tested in a way different from regular unit tests, please clarify how you tested step by step, ideally copy and paste-able, so that other reviewers can test and check, and descendants can verify in the future.
   If tests were not added, please describe why they were not added and/or why it was difficult to add.
   -->
   Add 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.

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 #31994: [SPARK-34899][SQL] Use origin plan if we can not coalesce shuffle partition

Posted by GitBox <gi...@apache.org>.
AmplabJenkins removed a comment on pull request #31994:
URL: https://github.com/apache/spark/pull/31994#issuecomment-810125201


   
   Refer to this link for build results (access rights to CI server needed): 
   https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/136702/
   


-- 
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.

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] JkSelf commented on a change in pull request #31994: [SPARK-34899][SQL] Use origin plan if we can not coalesce shuffle partition

Posted by GitBox <gi...@apache.org>.
JkSelf commented on a change in pull request #31994:
URL: https://github.com/apache/spark/pull/31994#discussion_r603817326



##########
File path: sql/core/src/test/scala/org/apache/spark/sql/execution/adaptive/AdaptiveQueryExecSuite.scala
##########
@@ -1543,4 +1543,27 @@ class AdaptiveQueryExecSuite
     assert(materializeLogs(0).startsWith("Materialize query stage BroadcastQueryStageExec"))
     assert(materializeLogs(1).startsWith("Materialize query stage ShuffleQueryStageExec"))
   }
+
+  test("SPARK-34899: Use origin plan if we can not coalesce shuffle partition") {
+    def check(ds: Dataset[Row], origin: ShuffleOrigin): Unit = {
+      ds.collect()
+      val plan = ds.queryExecution.executedPlan.asInstanceOf[AdaptiveSparkPlanExec].executedPlan
+      assert(collect(plan) {
+        case c: CustomShuffleReaderExec => c
+      }.isEmpty)
+      assert(collect(plan) {
+        case s: ShuffleExchangeExec if s.shuffleOrigin == origin && s.numPartitions == 3 => s
+      }.size == 1)
+      checkAnswer(ds, testData)
+    }
+
+    withSQLConf(SQLConf.ADAPTIVE_EXECUTION_ENABLED.key -> "true",
+      SQLConf.COALESCE_PARTITIONS_ENABLED.key -> "true",
+      SQLConf.ADVISORY_PARTITION_SIZE_IN_BYTES.key -> "10",
+      SQLConf.COALESCE_PARTITIONS_MIN_PARTITION_NUM.key -> "1",
+      SQLConf.SHUFFLE_PARTITIONS.key -> "3") {
+      check(testData.repartition(), REPARTITION)

Review comment:
       The partition size is stored in `ShuffleQueryStageExec#mapStats#bytesByPartitionId`. You can traverse the `bytesByPartitionId `value of each `mapStats `in [validMetrics ](https://github.com/apache/spark/blob/1237124062a541082922c650d1f1766b691f47bb/sql/core/src/main/scala/org/apache/spark/sql/execution/adaptive/CoalesceShufflePartitions.scala#L59).
   




-- 
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.

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 #31994: [SPARK-34899][SQL] Use origin plan if we can not coalesce shuffle partition

Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #31994:
URL: https://github.com/apache/spark/pull/31994#issuecomment-809987717


   Kubernetes integration test starting
   URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/41277/
   


-- 
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.

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 #31994: [SPARK-34899][SQL] Use origin plan if we can not coalesce shuffle partition

Posted by GitBox <gi...@apache.org>.
AmplabJenkins commented on pull request #31994:
URL: https://github.com/apache/spark/pull/31994#issuecomment-810125201


   
   Refer to this link for build results (access rights to CI server needed): 
   https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/136702/
   


-- 
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.

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 #31994: [SPARK-34899][SQL] Use origin plan if we can not coalesce shuffle partition

Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #31994:
URL: https://github.com/apache/spark/pull/31994#issuecomment-809954889


   **[Test build #136695 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/136695/testReport)** for PR 31994 at commit [`753e711`](https://github.com/apache/spark/commit/753e711af98ac42031a5f2c372c30e75311ac3f9).


-- 
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.

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 #31994: [SPARK-34899][SQL] Use origin plan if we can not coalesce shuffle partition

Posted by GitBox <gi...@apache.org>.
AmplabJenkins commented on pull request #31994:
URL: https://github.com/apache/spark/pull/31994#issuecomment-809992959


   
   Refer to this link for build results (access rights to CI server needed): 
   https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder-K8s/41277/
   


-- 
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.

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 #31994: [SPARK-34899][SQL] Use origin plan if we can not coalesce shuffle partition

Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #31994:
URL: https://github.com/apache/spark/pull/31994#issuecomment-810069620


   **[Test build #136695 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/136695/testReport)** for PR 31994 at commit [`753e711`](https://github.com/apache/spark/commit/753e711af98ac42031a5f2c372c30e75311ac3f9).
    * This patch **fails Spark unit 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.

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] JkSelf commented on a change in pull request #31994: [SPARK-34899][SQL] Use origin plan if we can not coalesce shuffle partition

Posted by GitBox <gi...@apache.org>.
JkSelf commented on a change in pull request #31994:
URL: https://github.com/apache/spark/pull/31994#discussion_r603801610



##########
File path: sql/core/src/test/scala/org/apache/spark/sql/execution/adaptive/AdaptiveQueryExecSuite.scala
##########
@@ -1543,4 +1543,27 @@ class AdaptiveQueryExecSuite
     assert(materializeLogs(0).startsWith("Materialize query stage BroadcastQueryStageExec"))
     assert(materializeLogs(1).startsWith("Materialize query stage ShuffleQueryStageExec"))
   }
+
+  test("SPARK-34899: Use origin plan if we can not coalesce shuffle partition") {
+    def check(ds: Dataset[Row], origin: ShuffleOrigin): Unit = {
+      ds.collect()
+      val plan = ds.queryExecution.executedPlan.asInstanceOf[AdaptiveSparkPlanExec].executedPlan
+      assert(collect(plan) {
+        case c: CustomShuffleReaderExec => c
+      }.isEmpty)
+      assert(collect(plan) {
+        case s: ShuffleExchangeExec if s.shuffleOrigin == origin && s.numPartitions == 3 => s
+      }.size == 1)
+      checkAnswer(ds, testData)
+    }
+
+    withSQLConf(SQLConf.ADAPTIVE_EXECUTION_ENABLED.key -> "true",
+      SQLConf.COALESCE_PARTITIONS_ENABLED.key -> "true",
+      SQLConf.ADVISORY_PARTITION_SIZE_IN_BYTES.key -> "10",
+      SQLConf.COALESCE_PARTITIONS_MIN_PARTITION_NUM.key -> "1",
+      SQLConf.SHUFFLE_PARTITIONS.key -> "3") {
+      check(testData.repartition(), REPARTITION)

Review comment:
       It is better to add the partition size of each partition in the 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.

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 #31994: [SPARK-34899][SQL] Use origin plan if we can not coalesce shuffle partition

Posted by GitBox <gi...@apache.org>.
SparkQA removed a comment on pull request #31994:
URL: https://github.com/apache/spark/pull/31994#issuecomment-809954889


   **[Test build #136695 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/136695/testReport)** for PR 31994 at commit [`753e711`](https://github.com/apache/spark/commit/753e711af98ac42031a5f2c372c30e75311ac3f9).


-- 
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.

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 #31994: [SPARK-34899][SQL] Use origin plan if we can not coalesce shuffle partition

Posted by GitBox <gi...@apache.org>.
AmplabJenkins removed a comment on pull request #31994:
URL: https://github.com/apache/spark/pull/31994#issuecomment-810267084


   
   Refer to this link for build results (access rights to CI server needed): 
   https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/136707/
   


-- 
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.

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 #31994: [SPARK-34899][SQL] Use origin plan if we can not coalesce shuffle partition

Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #31994:
URL: https://github.com/apache/spark/pull/31994#issuecomment-809272349


   **[Test build #136647 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/136647/testReport)** for PR 31994 at commit [`d9ffcf3`](https://github.com/apache/spark/commit/d9ffcf38f9caf1c63cb8c2522487cf4386c0718e).


-- 
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.

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] ulysses-you commented on a change in pull request #31994: [SPARK-34899][SQL] Use origin plan if we can not coalesce shuffle partition

Posted by GitBox <gi...@apache.org>.
ulysses-you commented on a change in pull request #31994:
URL: https://github.com/apache/spark/pull/31994#discussion_r603808998



##########
File path: sql/core/src/main/scala/org/apache/spark/sql/execution/adaptive/CoalesceShufflePartitions.scala
##########
@@ -72,14 +72,20 @@ case class CoalesceShufflePartitions(session: SparkSession) extends CustomShuffl
           validMetrics.toArray,
           advisoryTargetSize = conf.getConf(SQLConf.ADVISORY_PARTITION_SIZE_IN_BYTES),
           minNumPartitions = minPartitionNum)
-        // This transformation adds new nodes, so we must use `transformUp` here.
-        val stageIds = shuffleStages.map(_.id).toSet
-        plan.transformUp {
-          // even for shuffle exchange whose input RDD has 0 partition, we should still update its
-          // `partitionStartIndices`, so that all the leaf shuffles in a stage have the same
-          // number of output partitions.
-          case stage: ShuffleQueryStageExec if stageIds.contains(stage.id) =>
-            CustomShuffleReaderExec(stage, partitionSpecs)
+        // We can never extend the shuffle partition number, so if we get the same number here,
+        // that means we can not coalesce shuffle partition. Just return the origin plan.
+        if (partitionSpecs.length == validMetrics.head.bytesByPartitionId.length) {

Review comment:
       Updated.




-- 
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.

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 #31994: [SPARK-34899][SQL] Use origin plan if we can not coalesce shuffle partition

Posted by GitBox <gi...@apache.org>.
AmplabJenkins removed a comment on pull request #31994:
URL: https://github.com/apache/spark/pull/31994#issuecomment-810074102






-- 
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.

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 #31994: [SPARK-34899][SQL] Use origin plan if we can not coalesce shuffle partition

Posted by GitBox <gi...@apache.org>.
SparkQA removed a comment on pull request #31994:
URL: https://github.com/apache/spark/pull/31994#issuecomment-810003934


   **[Test build #136702 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/136702/testReport)** for PR 31994 at commit [`1154e18`](https://github.com/apache/spark/commit/1154e186bd34cadde0995e06bb1a6480a8d26db5).


-- 
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.

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 #31994: [SPARK-34899][SQL] Use origin plan if we can not coalesce shuffle partition

Posted by GitBox <gi...@apache.org>.
AmplabJenkins commented on pull request #31994:
URL: https://github.com/apache/spark/pull/31994#issuecomment-810114348


   
   Refer to this link for build results (access rights to CI server needed): 
   https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder-K8s/41289/
   


-- 
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.

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 #31994: [SPARK-34899][SQL] Use origin plan if we can not coalesce shuffle partition

Posted by GitBox <gi...@apache.org>.
cloud-fan commented on pull request #31994:
URL: https://github.com/apache/spark/pull/31994#issuecomment-810267146


   thanks, merging to master!


-- 
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.

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 #31994: [SPARK-34899][SQL] Use origin plan if we can not coalesce shuffle partition

Posted by GitBox <gi...@apache.org>.
AmplabJenkins commented on pull request #31994:
URL: https://github.com/apache/spark/pull/31994#issuecomment-809479808






-- 
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.

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] maropu commented on a change in pull request #31994: [SPARK-34899][SQL] Use origin plan if we can not coalesce shuffle partition

Posted by GitBox <gi...@apache.org>.
maropu commented on a change in pull request #31994:
URL: https://github.com/apache/spark/pull/31994#discussion_r603743739



##########
File path: sql/core/src/test/scala/org/apache/spark/sql/execution/adaptive/AdaptiveQueryExecSuite.scala
##########
@@ -1543,4 +1543,27 @@ class AdaptiveQueryExecSuite
     assert(materializeLogs(0).startsWith("Materialize query stage BroadcastQueryStageExec"))
     assert(materializeLogs(1).startsWith("Materialize query stage ShuffleQueryStageExec"))
   }
+
+  test("SPARK-34899: Use origin plan if we can not coalesce shuffle partition") {
+    def check(ds: Dataset[Row], origin: ShuffleOrigin): Unit = {

Review comment:
       Also, how about checking the initial partition num, too?




-- 
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.

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] ulysses-you commented on a change in pull request #31994: [SPARK-34899][SQL] Use origin plan if we can not coalesce shuffle partition

Posted by GitBox <gi...@apache.org>.
ulysses-you commented on a change in pull request #31994:
URL: https://github.com/apache/spark/pull/31994#discussion_r603820907



##########
File path: sql/core/src/test/scala/org/apache/spark/sql/execution/adaptive/AdaptiveQueryExecSuite.scala
##########
@@ -1543,4 +1543,27 @@ class AdaptiveQueryExecSuite
     assert(materializeLogs(0).startsWith("Materialize query stage BroadcastQueryStageExec"))
     assert(materializeLogs(1).startsWith("Materialize query stage ShuffleQueryStageExec"))
   }
+
+  test("SPARK-34899: Use origin plan if we can not coalesce shuffle partition") {
+    def check(ds: Dataset[Row], origin: ShuffleOrigin): Unit = {
+      ds.collect()
+      val plan = ds.queryExecution.executedPlan.asInstanceOf[AdaptiveSparkPlanExec].executedPlan
+      assert(collect(plan) {
+        case c: CustomShuffleReaderExec => c
+      }.isEmpty)
+      assert(collect(plan) {
+        case s: ShuffleExchangeExec if s.shuffleOrigin == origin && s.numPartitions == 3 => s
+      }.size == 1)
+      checkAnswer(ds, testData)
+    }
+
+    withSQLConf(SQLConf.ADAPTIVE_EXECUTION_ENABLED.key -> "true",
+      SQLConf.COALESCE_PARTITIONS_ENABLED.key -> "true",
+      SQLConf.ADVISORY_PARTITION_SIZE_IN_BYTES.key -> "10",
+      SQLConf.COALESCE_PARTITIONS_MIN_PARTITION_NUM.key -> "1",
+      SQLConf.SHUFFLE_PARTITIONS.key -> "3") {
+      check(testData.repartition(), REPARTITION)

Review comment:
       I see it, but want to find a way can estimate the size manual without that code ..




-- 
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.

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 #31994: [SPARK-34899][SQL] Use origin plan if we can not coalesce shuffle partition

Posted by GitBox <gi...@apache.org>.
AmplabJenkins commented on pull request #31994:
URL: https://github.com/apache/spark/pull/31994#issuecomment-810074104






-- 
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.

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] ulysses-you commented on a change in pull request #31994: [SPARK-34899][SQL] Use origin plan if we can not coalesce shuffle partition

Posted by GitBox <gi...@apache.org>.
ulysses-you commented on a change in pull request #31994:
URL: https://github.com/apache/spark/pull/31994#discussion_r603808961



##########
File path: sql/core/src/test/scala/org/apache/spark/sql/execution/adaptive/AdaptiveQueryExecSuite.scala
##########
@@ -1543,4 +1543,27 @@ class AdaptiveQueryExecSuite
     assert(materializeLogs(0).startsWith("Materialize query stage BroadcastQueryStageExec"))
     assert(materializeLogs(1).startsWith("Materialize query stage ShuffleQueryStageExec"))
   }
+
+  test("SPARK-34899: Use origin plan if we can not coalesce shuffle partition") {
+    def check(ds: Dataset[Row], origin: ShuffleOrigin): Unit = {
+      ds.collect()
+      val plan = ds.queryExecution.executedPlan.asInstanceOf[AdaptiveSparkPlanExec].executedPlan
+      assert(collect(plan) {
+        case c: CustomShuffleReaderExec => c
+      }.isEmpty)
+      assert(collect(plan) {
+        case s: ShuffleExchangeExec if s.shuffleOrigin == origin && s.numPartitions == 3 => s
+      }.size == 1)
+      checkAnswer(ds, testData)
+    }
+
+    withSQLConf(SQLConf.ADAPTIVE_EXECUTION_ENABLED.key -> "true",
+      SQLConf.COALESCE_PARTITIONS_ENABLED.key -> "true",
+      SQLConf.ADVISORY_PARTITION_SIZE_IN_BYTES.key -> "10",
+      SQLConf.COALESCE_PARTITIONS_MIN_PARTITION_NUM.key -> "1",
+      SQLConf.SHUFFLE_PARTITIONS.key -> "3") {
+      check(testData.repartition(), REPARTITION)

Review comment:
       Just a question, is there a way to estimate the partition size quickly or just the type of jvm size ? Let's say we have one rows with one int column, and the map and reduce partition number are 1, then after shuffle the partition size is always 4.




-- 
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.

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 #31994: [SPARK-34899][SQL] Use origin plan if we can not coalesce shuffle partition

Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #31994:
URL: https://github.com/apache/spark/pull/31994#issuecomment-810003934


   **[Test build #136702 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/136702/testReport)** for PR 31994 at commit [`1154e18`](https://github.com/apache/spark/commit/1154e186bd34cadde0995e06bb1a6480a8d26db5).


-- 
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.

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 #31994: [SPARK-34899][SQL] Use origin plan if we can not coalesce shuffle partition

Posted by GitBox <gi...@apache.org>.
cloud-fan commented on a change in pull request #31994:
URL: https://github.com/apache/spark/pull/31994#discussion_r603753304



##########
File path: sql/core/src/test/scala/org/apache/spark/sql/execution/adaptive/AdaptiveQueryExecSuite.scala
##########
@@ -1543,4 +1543,27 @@ class AdaptiveQueryExecSuite
     assert(materializeLogs(0).startsWith("Materialize query stage BroadcastQueryStageExec"))
     assert(materializeLogs(1).startsWith("Materialize query stage ShuffleQueryStageExec"))
   }
+
+  test("SPARK-34899: Use origin plan if we can not coalesce shuffle partition") {
+    def check(ds: Dataset[Row], origin: ShuffleOrigin): Unit = {
+      ds.collect()
+      val plan = ds.queryExecution.executedPlan.asInstanceOf[AdaptiveSparkPlanExec].executedPlan
+      assert(collect(plan) {
+        case c: CustomShuffleReaderExec => c
+      }.isEmpty)
+      assert(collect(plan) {
+        case s: ShuffleExchangeExec if s.shuffleOrigin == origin && s.numPartitions == 3 => s
+      }.size == 1)
+      checkAnswer(ds, testData)
+    }
+
+    withSQLConf(SQLConf.ADAPTIVE_EXECUTION_ENABLED.key -> "true",
+      SQLConf.COALESCE_PARTITIONS_ENABLED.key -> "true",
+      SQLConf.ADVISORY_PARTITION_SIZE_IN_BYTES.key -> "10",
+      SQLConf.COALESCE_PARTITIONS_MIN_PARTITION_NUM.key -> "1",
+      SQLConf.SHUFFLE_PARTITIONS.key -> "3") {
+      check(testData.repartition(), REPARTITION)

Review comment:
       Can we create a new dataframe for testing here? It's unclear how many partitions `testData` has and what's the size for each partition.




-- 
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.

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 #31994: [SPARK-34899][SQL] Use origin plan if we can not coalesce shuffle partition

Posted by GitBox <gi...@apache.org>.
AmplabJenkins removed a comment on pull request #31994:
URL: https://github.com/apache/spark/pull/31994#issuecomment-810114348


   
   Refer to this link for build results (access rights to CI server needed): 
   https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder-K8s/41289/
   


-- 
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.

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] maropu commented on pull request #31994: [SPARK-34899][SQL] Use origin plan if we can not coalesce shuffle partition

Posted by GitBox <gi...@apache.org>.
maropu commented on pull request #31994:
URL: https://github.com/apache/spark/pull/31994#issuecomment-809865219


   also cc: @maryannxue


-- 
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.

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 #31994: [SPARK-34899][SQL] Use origin plan if we can not coalesce shuffle partition

Posted by GitBox <gi...@apache.org>.
SparkQA removed a comment on pull request #31994:
URL: https://github.com/apache/spark/pull/31994#issuecomment-809272349


   **[Test build #136647 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/136647/testReport)** for PR 31994 at commit [`d9ffcf3`](https://github.com/apache/spark/commit/d9ffcf38f9caf1c63cb8c2522487cf4386c0718e).


-- 
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.

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] ulysses-you commented on pull request #31994: [SPARK-34899][SQL] Use origin plan if we can not coalesce shuffle partition

Posted by GitBox <gi...@apache.org>.
ulysses-you commented on pull request #31994:
URL: https://github.com/apache/spark/pull/31994#issuecomment-809845264


   We encounter this case during using aqe, but seems it is an expect behavior in previous test. Do you have any thought about this ? @maropu @cloud-fan @JkSelf 


-- 
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.

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 #31994: [SPARK-34899][SQL] Use origin plan if we can not coalesce shuffle partition

Posted by GitBox <gi...@apache.org>.
SparkQA removed a comment on pull request #31994:
URL: https://github.com/apache/spark/pull/31994#issuecomment-810075847


   **[Test build #136707 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/136707/testReport)** for PR 31994 at commit [`3908d32`](https://github.com/apache/spark/commit/3908d322bb50a8f5d8a01db12f1693dd82eaf144).


-- 
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.

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] maropu commented on a change in pull request #31994: [SPARK-34899][SQL] Use origin plan if we can not coalesce shuffle partition

Posted by GitBox <gi...@apache.org>.
maropu commented on a change in pull request #31994:
URL: https://github.com/apache/spark/pull/31994#discussion_r603743803



##########
File path: sql/core/src/main/scala/org/apache/spark/sql/execution/adaptive/CoalesceShufflePartitions.scala
##########
@@ -72,14 +72,20 @@ case class CoalesceShufflePartitions(session: SparkSession) extends CustomShuffl
           validMetrics.toArray,
           advisoryTargetSize = conf.getConf(SQLConf.ADVISORY_PARTITION_SIZE_IN_BYTES),
           minNumPartitions = minPartitionNum)
-        // This transformation adds new nodes, so we must use `transformUp` here.
-        val stageIds = shuffleStages.map(_.id).toSet
-        plan.transformUp {
-          // even for shuffle exchange whose input RDD has 0 partition, we should still update its
-          // `partitionStartIndices`, so that all the leaf shuffles in a stage have the same
-          // number of output partitions.
-          case stage: ShuffleQueryStageExec if stageIds.contains(stage.id) =>
-            CustomShuffleReaderExec(stage, partitionSpecs)
+        // We can never extend the shuffle partition number, so if we get the same number here,
+        // that means we can not coalesce shuffle partition. Just return the origin plan.
+        if (partitionSpecs.length == validMetrics.head.bytesByPartitionId.length) {

Review comment:
       The fix itself seems fine.




-- 
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.

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 #31994: [SPARK-34899][SQL] Use origin plan if we can not coalesce shuffle partition

Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #31994:
URL: https://github.com/apache/spark/pull/31994#issuecomment-810124232


   **[Test build #136702 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/136702/testReport)** for PR 31994 at commit [`1154e18`](https://github.com/apache/spark/commit/1154e186bd34cadde0995e06bb1a6480a8d26db5).
    * This patch **fails Spark unit 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.

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] yaooqinn commented on pull request #31994: [SPARK-34899][SQL] Use origin plan if we can not coalesce shuffle partition

Posted by GitBox <gi...@apache.org>.
yaooqinn commented on pull request #31994:
URL: https://github.com/apache/spark/pull/31994#issuecomment-810328060


   late +1


-- 
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.

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] maropu commented on a change in pull request #31994: [SPARK-34899][SQL] Use origin plan if we can not coalesce shuffle partition

Posted by GitBox <gi...@apache.org>.
maropu commented on a change in pull request #31994:
URL: https://github.com/apache/spark/pull/31994#discussion_r603743658



##########
File path: sql/core/src/test/scala/org/apache/spark/sql/execution/adaptive/AdaptiveQueryExecSuite.scala
##########
@@ -1543,4 +1543,27 @@ class AdaptiveQueryExecSuite
     assert(materializeLogs(0).startsWith("Materialize query stage BroadcastQueryStageExec"))
     assert(materializeLogs(1).startsWith("Materialize query stage ShuffleQueryStageExec"))
   }
+
+  test("SPARK-34899: Use origin plan if we can not coalesce shuffle partition") {
+    def check(ds: Dataset[Row], origin: ShuffleOrigin): Unit = {

Review comment:
       `check` -> `checkNoCoalescePartitions`?




-- 
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.

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 #31994: [SPARK-34899][SQL] Use origin plan if we can not coalesce shuffle partition

Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #31994:
URL: https://github.com/apache/spark/pull/31994#issuecomment-810106080






-- 
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.

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 #31994: [SPARK-34899][SQL] Use origin plan if we can not coalesce shuffle partition

Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #31994:
URL: https://github.com/apache/spark/pull/31994#issuecomment-809992938


   Kubernetes integration test status failure
   URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/41277/
   


-- 
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.

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 #31994: [SPARK-34899][SQL] Use origin plan if we can not coalesce shuffle partition

Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #31994:
URL: https://github.com/apache/spark/pull/31994#issuecomment-810264692


   **[Test build #136707 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/136707/testReport)** for PR 31994 at commit [`3908d32`](https://github.com/apache/spark/commit/3908d322bb50a8f5d8a01db12f1693dd82eaf144).
    * 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.

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 #31994: [SPARK-34899][SQL] Use origin plan if we can not coalesce shuffle partition

Posted by GitBox <gi...@apache.org>.
AmplabJenkins removed a comment on pull request #31994:
URL: https://github.com/apache/spark/pull/31994#issuecomment-809992959


   
   Refer to this link for build results (access rights to CI server needed): 
   https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder-K8s/41277/
   


-- 
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.

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 #31994: [SPARK-34899][SQL] Use origin plan if we can not coalesce shuffle partition

Posted by GitBox <gi...@apache.org>.
AmplabJenkins removed a comment on pull request #31994:
URL: https://github.com/apache/spark/pull/31994#issuecomment-809479808






-- 
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.

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 #31994: [SPARK-34899][SQL] Use origin plan if we can not coalesce shuffle partition

Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #31994:
URL: https://github.com/apache/spark/pull/31994#issuecomment-809452746


   Kubernetes integration test starting
   URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/41229/
   


-- 
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.

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 #31994: [SPARK-34899][SQL] Use origin plan if we can not coalesce shuffle partition

Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #31994:
URL: https://github.com/apache/spark/pull/31994#issuecomment-809450976


   **[Test build #136647 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/136647/testReport)** for PR 31994 at commit [`d9ffcf3`](https://github.com/apache/spark/commit/d9ffcf38f9caf1c63cb8c2522487cf4386c0718e).
    * This patch **fails Spark unit 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.

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] JkSelf commented on a change in pull request #31994: [SPARK-34899][SQL] Use origin plan if we can not coalesce shuffle partition

Posted by GitBox <gi...@apache.org>.
JkSelf commented on a change in pull request #31994:
URL: https://github.com/apache/spark/pull/31994#discussion_r603823927



##########
File path: sql/core/src/test/scala/org/apache/spark/sql/execution/adaptive/AdaptiveQueryExecSuite.scala
##########
@@ -1543,4 +1543,27 @@ class AdaptiveQueryExecSuite
     assert(materializeLogs(0).startsWith("Materialize query stage BroadcastQueryStageExec"))
     assert(materializeLogs(1).startsWith("Materialize query stage ShuffleQueryStageExec"))
   }
+
+  test("SPARK-34899: Use origin plan if we can not coalesce shuffle partition") {
+    def check(ds: Dataset[Row], origin: ShuffleOrigin): Unit = {
+      ds.collect()
+      val plan = ds.queryExecution.executedPlan.asInstanceOf[AdaptiveSparkPlanExec].executedPlan
+      assert(collect(plan) {
+        case c: CustomShuffleReaderExec => c
+      }.isEmpty)
+      assert(collect(plan) {
+        case s: ShuffleExchangeExec if s.shuffleOrigin == origin && s.numPartitions == 3 => s
+      }.size == 1)
+      checkAnswer(ds, testData)
+    }
+
+    withSQLConf(SQLConf.ADAPTIVE_EXECUTION_ENABLED.key -> "true",
+      SQLConf.COALESCE_PARTITIONS_ENABLED.key -> "true",
+      SQLConf.ADVISORY_PARTITION_SIZE_IN_BYTES.key -> "10",
+      SQLConf.COALESCE_PARTITIONS_MIN_PARTITION_NUM.key -> "1",
+      SQLConf.SHUFFLE_PARTITIONS.key -> "3") {
+      check(testData.repartition(), REPARTITION)

Review comment:
       `CoalesceShufflePartitions` rule depend on the map output statistics to coalesce the shuffle partitions. I think this size is more meaningful here.




-- 
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.

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 #31994: [SPARK-34899][SQL] Use origin plan if we can not coalesce shuffle partition

Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #31994:
URL: https://github.com/apache/spark/pull/31994#issuecomment-810075847


   **[Test build #136707 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/136707/testReport)** for PR 31994 at commit [`3908d32`](https://github.com/apache/spark/commit/3908d322bb50a8f5d8a01db12f1693dd82eaf144).


-- 
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.

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] ulysses-you commented on a change in pull request #31994: [SPARK-34899][SQL] Use origin plan if we can not coalesce shuffle partition

Posted by GitBox <gi...@apache.org>.
ulysses-you commented on a change in pull request #31994:
URL: https://github.com/apache/spark/pull/31994#discussion_r603809075



##########
File path: sql/core/src/test/scala/org/apache/spark/sql/execution/adaptive/AdaptiveQueryExecSuite.scala
##########
@@ -1543,4 +1543,27 @@ class AdaptiveQueryExecSuite
     assert(materializeLogs(0).startsWith("Materialize query stage BroadcastQueryStageExec"))
     assert(materializeLogs(1).startsWith("Materialize query stage ShuffleQueryStageExec"))
   }
+
+  test("SPARK-34899: Use origin plan if we can not coalesce shuffle partition") {
+    def check(ds: Dataset[Row], origin: ShuffleOrigin): Unit = {

Review comment:
       Added the 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.

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 #31994: [SPARK-34899][SQL] Use origin plan if we can not coalesce shuffle partition

Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #31994:
URL: https://github.com/apache/spark/pull/31994#issuecomment-810065285


   Kubernetes integration test unable to build dist.
   
   exiting with code: 1
   URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/41284/
   


-- 
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.

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] maropu commented on a change in pull request #31994: [SPARK-34899][SQL] Use origin plan if we can not coalesce shuffle partition

Posted by GitBox <gi...@apache.org>.
maropu commented on a change in pull request #31994:
URL: https://github.com/apache/spark/pull/31994#discussion_r603743258



##########
File path: sql/core/src/main/scala/org/apache/spark/sql/execution/adaptive/CoalesceShufflePartitions.scala
##########
@@ -72,14 +72,20 @@ case class CoalesceShufflePartitions(session: SparkSession) extends CustomShuffl
           validMetrics.toArray,
           advisoryTargetSize = conf.getConf(SQLConf.ADVISORY_PARTITION_SIZE_IN_BYTES),
           minNumPartitions = minPartitionNum)
-        // This transformation adds new nodes, so we must use `transformUp` here.
-        val stageIds = shuffleStages.map(_.id).toSet
-        plan.transformUp {
-          // even for shuffle exchange whose input RDD has 0 partition, we should still update its
-          // `partitionStartIndices`, so that all the leaf shuffles in a stage have the same
-          // number of output partitions.
-          case stage: ShuffleQueryStageExec if stageIds.contains(stage.id) =>
-            CustomShuffleReaderExec(stage, partitionSpecs)
+        // We can never extend the shuffle partition number, so if we get the same number here,
+        // that means we can not coalesce shuffle partition. Just return the origin plan.
+        if (partitionSpecs.length == validMetrics.head.bytesByPartitionId.length) {

Review comment:
       `validMetrics.head.bytesByPartitionId.length` -> `distinctNumPreShufflePartitions.head`




-- 
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.

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] ulysses-you commented on a change in pull request #31994: [SPARK-34899][SQL] Use origin plan if we can not coalesce shuffle partition

Posted by GitBox <gi...@apache.org>.
ulysses-you commented on a change in pull request #31994:
URL: https://github.com/apache/spark/pull/31994#discussion_r603867565



##########
File path: sql/core/src/test/scala/org/apache/spark/sql/execution/adaptive/AdaptiveQueryExecSuite.scala
##########
@@ -1543,4 +1543,27 @@ class AdaptiveQueryExecSuite
     assert(materializeLogs(0).startsWith("Materialize query stage BroadcastQueryStageExec"))
     assert(materializeLogs(1).startsWith("Materialize query stage ShuffleQueryStageExec"))
   }
+
+  test("SPARK-34899: Use origin plan if we can not coalesce shuffle partition") {
+    def check(ds: Dataset[Row], origin: ShuffleOrigin): Unit = {
+      ds.collect()
+      val plan = ds.queryExecution.executedPlan.asInstanceOf[AdaptiveSparkPlanExec].executedPlan
+      assert(collect(plan) {
+        case c: CustomShuffleReaderExec => c
+      }.isEmpty)
+      assert(collect(plan) {
+        case s: ShuffleExchangeExec if s.shuffleOrigin == origin && s.numPartitions == 3 => s
+      }.size == 1)
+      checkAnswer(ds, testData)
+    }
+
+    withSQLConf(SQLConf.ADAPTIVE_EXECUTION_ENABLED.key -> "true",
+      SQLConf.COALESCE_PARTITIONS_ENABLED.key -> "true",
+      SQLConf.ADVISORY_PARTITION_SIZE_IN_BYTES.key -> "10",
+      SQLConf.COALESCE_PARTITIONS_MIN_PARTITION_NUM.key -> "1",
+      SQLConf.SHUFFLE_PARTITIONS.key -> "3") {
+      check(testData.repartition(), REPARTITION)

Review comment:
       Aggre that specify the partition size explicitly is better, added the partition size 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.

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 closed pull request #31994: [SPARK-34899][SQL] Use origin plan if we can not coalesce shuffle partition

Posted by GitBox <gi...@apache.org>.
cloud-fan closed pull request #31994:
URL: https://github.com/apache/spark/pull/31994


   


-- 
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.

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 #31994: [SPARK-34899][SQL] Use origin plan if we can not coalesce shuffle partition

Posted by GitBox <gi...@apache.org>.
AmplabJenkins commented on pull request #31994:
URL: https://github.com/apache/spark/pull/31994#issuecomment-810267084


   
   Refer to this link for build results (access rights to CI server needed): 
   https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/136707/
   


-- 
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.

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] ulysses-you commented on pull request #31994: [SPARK-34899][SQL] Use origin plan if we can not coalesce shuffle partition

Posted by GitBox <gi...@apache.org>.
ulysses-you commented on pull request #31994:
URL: https://github.com/apache/spark/pull/31994#issuecomment-810309416


   thanks for merging !


-- 
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.

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