AngersZhuuuu commented on a change in pull request #29692:
URL: https://github.com/apache/spark/pull/29692#discussion_r486141595



##########
File path: 
sql/core/src/test/scala/org/apache/spark/sql/execution/adaptive/AdaptiveQueryExecSuite.scala
##########
@@ -739,6 +745,67 @@ class AdaptiveQueryExecSuite
     }
   }
 
+  test("SPARK-32830: Optimize Skewed BroadcastNestedLoopJoin") {
+    withSQLConf(SQLConf.ADAPTIVE_EXECUTION_ENABLED.key -> "true",
+      SQLConf.SHUFFLE_TARGET_POSTSHUFFLE_INPUT_SIZE.key -> "1k",
+      SQLConf.SKEW_JOIN_SKEWED_PARTITION_THRESHOLD.key -> "5k",
+      SQLConf.SKEW_JOIN_SKEWED_PARTITION_FACTOR.key -> "3") {
+      withTempView("skewData1", "skewData2") {
+        spark
+          .range(0, 10000, 1, 50)
+          .select(
+            when('id > 1000, 100)
+              .when('id <= 1000, 'id % 10)
+              .otherwise('id).as("key1"),
+            'id as "value1", ('id + "str").as("str"))
+          .createOrReplaceTempView("skewData1")
+        spark
+          .range(5000, 10000, 1, 10)
+          .select(('id % 10).as("key2"),
+            'id as "value2", ('id + "str").as("str"))
+          .createOrReplaceTempView("skewData2")
+
+        def checkSkewJoin(
+            joins: Seq[BroadcastNestedLoopJoinExec],
+            leftSkewNum: Int,
+            rightSkewNum: Int): Unit = {
+          assert(joins.size == 1 && joins.head.isSkewJoin)
+          if (leftSkewNum > 0) {
+            assert(joins.head.left.collect {
+              case r: CustomShuffleReaderExec => r
+            }.head.partitionSpecs.collect {
+              case p: PartialReducerPartitionSpec => p.reducerIndex
+            }.distinct.length == leftSkewNum)
+          }
+          if (rightSkewNum > 0) {
+            assert(joins.head.right.collect {
+              case r: CustomShuffleReaderExec => r
+            }.head.partitionSpecs.collect {
+              case p: PartialReducerPartitionSpec => p.reducerIndex
+            }.distinct.length == rightSkewNum)
+          }
+        }
+
+        val (_, adaptivePlan1) = runAdaptiveAndVerifyResult(
+          """
+             |SELECT * FROM (SELECT /*+ REPARTITION(key1) */ * FROM skewData1) 
skewData1
+             |JOIN skewData2 ON key1 < key2

Review comment:
       > I think we need to add more test cases for the other join types, e.g., 
left-outer, right-outer..
   
   Yea, update later




----------------------------------------------------------------
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:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to