zml1206 commented on code in PR #48300:
URL: https://github.com/apache/spark/pull/48300#discussion_r1796483876


##########
sql/core/src/test/scala/org/apache/spark/sql/execution/adaptive/AdaptiveQueryExecSuite.scala:
##########
@@ -2829,6 +2829,38 @@ class AdaptiveQueryExecSuite
       assert(findTopLevelBroadcastNestedLoopJoin(adaptivePlan).size == 1)
       assert(findTopLevelUnion(adaptivePlan).size == 0)
     }
+
+    withSQLConf(
+      SQLConf.AUTO_BROADCASTJOIN_THRESHOLD.key -> "100") {
+      withTempView("t1", "t2", "t3", "t4") {
+        Seq(1).toDF().createOrReplaceTempView("t1")
+        spark.range(100).createOrReplaceTempView("t2")
+        spark.range(2).createOrReplaceTempView("t3")
+        spark.range(2).createOrReplaceTempView("t4")
+        val (_, adaptivePlan) = runAdaptiveAndVerifyResult(
+          """
+            |SELECT tt2.value
+            |FROM (
+            |  SELECT value
+            |  FROM t1
+            |  WHERE NOT EXISTS (
+            |      SELECT 1
+            |      FROM (
+            |        SELECT t2.id
+            |        FROM t2
+            |          JOIN t3 ON t2.id = t3.id
+            |        AND t2.id > 100
+            |      ) tt
+            |      WHERE t1.value = tt.id
+            |    )
+            |    AND t1.value = 1
+            |) tt2
+            |  LEFT JOIN t4 ON tt2.value = t4.id
+            |""".stripMargin
+        )
+        assert(findTopLevelBroadcastNestedLoopJoin(adaptivePlan).size == 1)

Review Comment:
   Before pr, throw error: 
   `java.lang.IllegalArgumentException: HashJoin should not take LeftOuter as 
the JoinType with building left side`
   current plan is 
   ```
   BroadcastHashJoin [cast(value#219 as bigint)], [id#227L], LeftOuter, 
BuildLeft, false
   :- BroadcastExchange HashedRelationBroadcastMode(List(cast(input[0, int, 
false] as bigint)),false), [plan_id=184]
   :  +- BroadcastQueryStage 0
   :     +- BroadcastExchange IdentityBroadcastMode, [plan_id=149]
   :        +- *(1) Filter (value#219 = 1)
   :           +- *(1) LocalTableScan [value#219]
   +- BroadcastQueryStage 2
      +- BroadcastExchange HashedRelationBroadcastMode(List(input[0, bigint, 
false]),false), [plan_id=169]
         +- *(3) Range (0, 2, step=1, splits=2)
   ```
   After pr
   ```
   == Physical Plan ==
   * Project (16)
   +- * BroadcastHashJoin LeftOuter BuildRight (15)
      :- BroadcastNestedLoopJoin LeftAnti BuildLeft (12)
      :  :- BroadcastExchange (3)
      :  :  +- * Filter (2)
      :  :     +- * LocalTableScan (1)
      :  +- * LocalLimit (11)
      :     +- * Project (10)
      :        +- * BroadcastHashJoin Inner BuildRight (9)
      :           :- * Filter (5)
      :           :  +- * Range (4)
      :           +- BroadcastExchange (8)
      :              +- * Filter (7)
      :                 +- * Range (6)
      +- BroadcastExchange (14)
         +- * Range (13)
   ```
   



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

Reply via email to