caican00 commented on code in PR #42003:
URL: https://github.com/apache/spark/pull/42003#discussion_r1271791289
##########
sql/core/src/test/scala/org/apache/spark/sql/execution/adaptive/AdaptiveQueryExecSuite.scala:
##########
@@ -874,6 +875,81 @@ class AdaptiveQueryExecSuite
}
}
+ test("SPARK-44426: Optimize adaptive skew join for ExistenceJoin") {
+ withSQLConf(
+ SQLConf.AUTO_BROADCASTJOIN_THRESHOLD.key -> "-1",
+ SQLConf.COALESCE_PARTITIONS_MIN_PARTITION_NUM.key -> "1",
+ SQLConf.SHUFFLE_PARTITIONS.key -> "100",
+ SQLConf.SKEW_JOIN_SKEWED_PARTITION_THRESHOLD.key -> "800",
+ SQLConf.ADVISORY_PARTITION_SIZE_IN_BYTES.key -> "800") {
+ withTempView("skewData1", "skewData2") {
Review Comment:
@ulysses-you Thanks,Updated.
##########
sql/core/src/test/scala/org/apache/spark/sql/execution/adaptive/AdaptiveQueryExecSuite.scala:
##########
@@ -874,6 +875,81 @@ class AdaptiveQueryExecSuite
}
}
+ test("SPARK-44426: Optimize adaptive skew join for ExistenceJoin") {
+ withSQLConf(
+ SQLConf.AUTO_BROADCASTJOIN_THRESHOLD.key -> "-1",
+ SQLConf.COALESCE_PARTITIONS_MIN_PARTITION_NUM.key -> "1",
+ SQLConf.SHUFFLE_PARTITIONS.key -> "100",
+ SQLConf.SKEW_JOIN_SKEWED_PARTITION_THRESHOLD.key -> "800",
+ SQLConf.ADVISORY_PARTITION_SIZE_IN_BYTES.key -> "800") {
+ withTempView("skewData1", "skewData2") {
+ // skewData1
+ spark
+ .range(0, 1000, 1, 10)
+ .select(
+ when('id < 250, 249)
+ .when('id >= 750, 1000)
+ .otherwise('id).as("key1"),
+ 'id as "value1")
+ .createOrReplaceTempView("skewData1")
+ // skewData2
+ spark
+ .range(0, 1000, 1, 10)
+ .select(
+ 'id as "key2",
+ 'id as "value2")
+ .createOrReplaceTempView("skewData2")
+
+ def checkSkewJoin(
+ joins: Seq[SortMergeJoinExec],
+ leftSkewNum: Int,
+ rightSkewNum: Int): Unit = {
+ assert(joins.size == 2 && joins.last.isSkewJoin)
+ assert(joins.last.left.collect {
+ case r: AQEShuffleReadExec => r
+ }.head.partitionSpecs.collect {
+ case p: PartialReducerPartitionSpec => p.reducerIndex
+ }.distinct.length == leftSkewNum)
+ assert(joins.last.right.collect {
+ case r: AQEShuffleReadExec => r
+ }.head.partitionSpecs.collect {
+ case p: PartialReducerPartitionSpec => p.reducerIndex
+ }.distinct.length == rightSkewNum)
+ }
+
+ // skewed ExistenceJoin optimization for left side
+ val (_, existenceAdaptivePlanForLeft) = runAdaptiveAndVerifyResult(
+ s"""
+ |SELECT * FROM skewData1
+ |where
+ |(key1 in (select key2 from skewData2)
+ |or value1 in (select value2 from skewData2)
+ |)""".stripMargin)
+ val existenceSmjForLeft =
findTopLevelSortMergeJoin(existenceAdaptivePlanForLeft)
+ assert(existenceSmjForLeft.nonEmpty &&
+ existenceSmjForLeft.last.joinType.isInstanceOf[ExistenceJoin])
+ checkSkewJoin(existenceSmjForLeft, 2, 0)
+
+ // forbid skewed ExistenceJoin optimization for right side
+ val (_, existenceAdaptivePlanForRight) = runAdaptiveAndVerifyResult(
+ s"""
+ |SELECT * FROM skewData2
+ |where
+ |(key2 in (select key1 from skewData1)
+ |or value2 in (select value1 from skewData1)
+ |)""".stripMargin)
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]