-
Notifications
You must be signed in to change notification settings - Fork 28.3k
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-32056][SQL] Coalesce partitions for repartition by expressions when AQE is enabled #28900
Closed
Closed
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
0a9223f
Coalesce partitions for repartition by key when AQE is enabled.
viirya 43c4726
Address comments.
viirya 8e39ed7
Add test.
viirya 4b9b0e8
For comments.
viirya 7ceaebc
For comments.
viirya df6a035
Refine test cases.
viirya 1ae1a87
Modify test name.
viirya File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,7 +28,7 @@ import org.apache.spark.sql.catalyst.optimizer.{BuildLeft, BuildRight} | |
import org.apache.spark.sql.catalyst.plans.logical.{Aggregate, LogicalPlan} | ||
import org.apache.spark.sql.execution.{PartialReducerPartitionSpec, ReusedSubqueryExec, ShuffledRowRDD, SparkPlan} | ||
import org.apache.spark.sql.execution.command.DataWritingCommandExec | ||
import org.apache.spark.sql.execution.exchange.{BroadcastExchangeExec, Exchange, ReusedExchangeExec} | ||
import org.apache.spark.sql.execution.exchange.{BroadcastExchangeExec, Exchange, ReusedExchangeExec, ShuffleExchangeExec} | ||
import org.apache.spark.sql.execution.joins.{BroadcastHashJoinExec, SortMergeJoinExec} | ||
import org.apache.spark.sql.execution.ui.SparkListenerSQLAdaptiveExecutionUpdate | ||
import org.apache.spark.sql.functions._ | ||
|
@@ -1026,13 +1026,79 @@ class AdaptiveQueryExecSuite | |
Seq(true, false).foreach { enableAQE => | ||
withSQLConf( | ||
SQLConf.ADAPTIVE_EXECUTION_ENABLED.key -> enableAQE.toString, | ||
SQLConf.COALESCE_PARTITIONS_ENABLED.key -> "true", | ||
SQLConf.SHUFFLE_PARTITIONS.key -> "6", | ||
SQLConf.COALESCE_PARTITIONS_INITIAL_PARTITION_NUM.key -> "7") { | ||
val partitionsNum = spark.range(10).repartition($"id").rdd.collectPartitions().length | ||
val df1 = spark.range(10).repartition($"id") | ||
val df2 = spark.range(10).repartition(10, $"id") | ||
val df3 = spark.range(10).repartition(10) | ||
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.
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. Added it. |
||
val df4 = spark.range(10).repartitionByRange(10, $"id".asc) | ||
|
||
val partitionsNum1 = df1.rdd.collectPartitions().length | ||
if (enableAQE) { | ||
assert(partitionsNum1 < 6) | ||
|
||
val plan = df1.queryExecution.executedPlan | ||
assert(plan.isInstanceOf[AdaptiveSparkPlanExec]) | ||
val shuffle = plan.asInstanceOf[AdaptiveSparkPlanExec].executedPlan.collect { | ||
case s: ShuffleExchangeExec => s | ||
} | ||
assert(shuffle.size == 1) | ||
assert(shuffle(0).outputPartitioning.numPartitions == 7) | ||
} else { | ||
assert(partitionsNum1 === 6) | ||
} | ||
|
||
assert(df2.rdd.collectPartitions().length == 10) | ||
assert(df3.rdd.collectPartitions().length == 10) | ||
assert(df4.rdd.collectPartitions().length == 10) | ||
} | ||
} | ||
} | ||
|
||
test("SPARK-32056 coalesce partitions for repartition by expressions when AQE is enabled") { | ||
cloud-fan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Seq(true, false).foreach { enableAQE => | ||
withSQLConf( | ||
SQLConf.ADAPTIVE_EXECUTION_ENABLED.key -> enableAQE.toString, | ||
SQLConf.COALESCE_PARTITIONS_ENABLED.key -> "true", | ||
SQLConf.COALESCE_PARTITIONS_INITIAL_PARTITION_NUM.key -> "50", | ||
SQLConf.SHUFFLE_PARTITIONS.key -> "10") { | ||
|
||
val partitionsNum1 = (1 to 10).toDF.repartition($"value") | ||
cloud-fan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
.rdd.collectPartitions().length | ||
val partitionsNum2 = (1 to 10).toDF.repartition($"value" + 1) | ||
.rdd.collectPartitions().length | ||
|
||
if (enableAQE) { | ||
assert(partitionsNum1 < 10) | ||
assert(partitionsNum2 < 10) | ||
} else { | ||
assert(partitionsNum1 === 10) | ||
assert(partitionsNum2 === 10) | ||
} | ||
} | ||
} | ||
} | ||
|
||
test("SPARK-32056 coalesce partitions for repartition by range when AQE is enabled") { | ||
Seq(true, false).foreach { enableAQE => | ||
withSQLConf( | ||
SQLConf.ADAPTIVE_EXECUTION_ENABLED.key -> enableAQE.toString, | ||
SQLConf.COALESCE_PARTITIONS_ENABLED.key -> "true", | ||
SQLConf.COALESCE_PARTITIONS_INITIAL_PARTITION_NUM.key -> "50", | ||
SQLConf.SHUFFLE_PARTITIONS.key -> "10") { | ||
|
||
val partitionsNum1 = (1 to 10).toDF.repartitionByRange($"value".asc) | ||
.rdd.collectPartitions().length | ||
val partitionsNum2 = (1 to 10).toDF.repartitionByRange(($"value" + 1).asc) | ||
.rdd.collectPartitions().length | ||
|
||
if (enableAQE) { | ||
assert(partitionsNum === 7) | ||
assert(partitionsNum1 < 10) | ||
cloud-fan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
assert(partitionsNum2 < 10) | ||
} else { | ||
assert(partitionsNum === 6) | ||
assert(partitionsNum1 === 10) | ||
assert(partitionsNum2 === 10) | ||
} | ||
} | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
we can merge this test case to your two newly added test cases.
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.e. one test to test
repartition
, and it verifies both the initial partition number and the coalesced partition number. The other test tests the same thing but forrepartitionByRange
.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.
Yeah, merged them.