-
Notifications
You must be signed in to change notification settings - Fork 29.3k
[SPARK-28356][SQL] Do not reduce the number of partitions for repartition in adaptive execution #25121
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SPARK-28356][SQL] Do not reduce the number of partitions for repartition in adaptive execution #25121
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -140,6 +140,8 @@ case class ShuffleQueryStageExec( | |
| case _ => | ||
| } | ||
| } | ||
|
|
||
| def supportAdaptive: Boolean = plan.supportAdaptive | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. :nit -> |
||
| } | ||
|
|
||
| /** | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -43,7 +43,8 @@ import org.apache.spark.util.collection.unsafe.sort.{PrefixComparators, RecordCo | |
| */ | ||
| case class ShuffleExchangeExec( | ||
| override val outputPartitioning: Partitioning, | ||
| child: SparkPlan) extends Exchange { | ||
| child: SparkPlan, | ||
| supportAdaptive: Boolean = true) extends Exchange { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if we remove the config, I'd probably call this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 |
||
|
|
||
| // NOTE: coordinator can be null after serialization/deserialization, | ||
| // e.g. it can be null on the Executor side | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -576,6 +576,7 @@ class ReduceNumShufflePartitionsSuite extends SparkFunSuite with BeforeAndAfterA | |
|
|
||
| test("Union two datasets with different pre-shuffle partition number") { | ||
| val test: SparkSession => Unit = { spark: SparkSession => | ||
| spark.conf.set(SQLConf.REDUCE_POST_SHUFFLE_PARTITIONS_FOR_REPARTITION.key, "true") | ||
| val dataset1 = spark.range(3) | ||
| val dataset2 = spark.range(3) | ||
|
|
||
|
|
@@ -592,4 +593,40 @@ class ReduceNumShufflePartitionsSuite extends SparkFunSuite with BeforeAndAfterA | |
| } | ||
| withSparkSession(test, 100, None) | ||
| } | ||
|
|
||
| test("Do not reduce the number of shuffle partition for repartition") { | ||
| val test: SparkSession => Unit = { spark: SparkSession => | ||
| spark.conf.set(SQLConf.REDUCE_POST_SHUFFLE_PARTITIONS_FOR_REPARTITION.key, "false") | ||
| val ds = spark.range(3) | ||
| val resultDf = ds.repartition(2, ds.col("id")).toDF() | ||
|
|
||
| checkAnswer(resultDf, | ||
| Seq((0), (1), (2)).map(i => Row(i))) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is just
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. True. Good catch. |
||
| val finalPlan = resultDf.queryExecution.executedPlan | ||
| .asInstanceOf[AdaptiveSparkPlanExec].executedPlan | ||
| assert(finalPlan.collect { case p: CoalescedShuffleReaderExec => p }.length == 0) | ||
| } | ||
| withSparkSession(test, 200, None) | ||
| } | ||
|
|
||
| test("Reduce the number of shuffle partition for repartition") { | ||
| val test: SparkSession => Unit = { spark: SparkSession => | ||
| spark.conf.set(SQLConf.REDUCE_POST_SHUFFLE_PARTITIONS_FOR_REPARTITION.key, "true") | ||
| val ds = spark.range(3) | ||
| val resultDf = ds.repartition(2, ds.col("id")).toDF() | ||
|
|
||
| checkAnswer(resultDf, | ||
| Seq((0), (1), (2)).map(i => Row(i))) | ||
| val finalPlan = resultDf.queryExecution.executedPlan | ||
| .asInstanceOf[AdaptiveSparkPlanExec].executedPlan | ||
| val shuffleReaders = finalPlan.collect { | ||
| case reader: CoalescedShuffleReaderExec => reader | ||
| } | ||
| assert(shuffleReaders.length === 1) | ||
| shuffleReaders.foreach { reader => | ||
| assert(reader.outputPartitioning.numPartitions === 1) | ||
| } | ||
| } | ||
| withSparkSession(test, 200, None) | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I probably won't add this config. If users call
Dataset#repartition, we have to respect it and not change it.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I initially didn't add this config. Later I found with that change, the
test("Union two datasets with different pre-shuffle partition number")won't test what we want to test, because it was written using repartition. Probably I can rewrite that test without using repartition.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can remove that test. Excluding repartition, the pre-shuffle num partitions are always the same (200 by default).
We do need to have a test for repartition though.