cloud-fan commented on a change in pull request #26289: 
[SPARK-28560][SQL][followup] support the build side to local shuffle reader as 
far as possible in BroadcastHashJoin
URL: https://github.com/apache/spark/pull/26289#discussion_r340982068
 
 

 ##########
 File path: 
sql/core/src/main/scala/org/apache/spark/sql/execution/adaptive/OptimizeLocalShuffleReader.scala
 ##########
 @@ -24,48 +24,85 @@ import 
org.apache.spark.sql.catalyst.plans.physical.{Partitioning, UnknownPartit
 import org.apache.spark.sql.catalyst.rules.Rule
 import org.apache.spark.sql.execution.{SparkPlan, UnaryExecNode}
 import org.apache.spark.sql.execution.exchange.{EnsureRequirements, 
ShuffleExchangeExec}
-import org.apache.spark.sql.execution.joins.{BroadcastHashJoinExec, BuildLeft, 
BuildRight}
+import org.apache.spark.sql.execution.joins.{BroadcastHashJoinExec, BuildLeft, 
BuildRight, BuildSide}
 import org.apache.spark.sql.internal.SQLConf
 
+object BroadcastJoinWithShuffleLeft {
+  def unapply(plan: SparkPlan): Option[(QueryStageExec, BuildSide)] = plan 
match {
+    case join: BroadcastHashJoinExec if 
ShuffleQueryStageExec.isShuffleQueryStageExec(join.left) =>
+      Some((join.left.asInstanceOf[QueryStageExec], join.buildSide))
+    case _ => None
+  }
+}
+
+object BroadcastJoinWithShuffleRight {
+  def unapply(plan: SparkPlan): Option[(QueryStageExec, BuildSide)] = plan 
match {
+    case join: BroadcastHashJoinExec if 
ShuffleQueryStageExec.isShuffleQueryStageExec(join.right) =>
+      Some((join.right.asInstanceOf[QueryStageExec], join.buildSide))
+    case _ => None
+  }
+}
+
+/**
+ * A rule to optimize the shuffle reader to local reader as far as possible
+ * when converting the 'SortMergeJoinExec' to 'BroadcastHashJoinExec' in 
runtime.
+ *
+ * This rule can be divided into two steps:
+ * Step1: Add the local reader in probe side and then check whether additional
+ *       shuffle introduced. If introduced, we will revert all the local
+ *       reader in probe side.
+ * Step2: Add the local reader in build side and will not check whether
+ *        additional shuffle introduced. Because the build side will not 
introduce
+ *        additional shuffle.
+ */
 case class OptimizeLocalShuffleReader(conf: SQLConf) extends Rule[SparkPlan] {
 
-  def canUseLocalShuffleReaderLeft(join: BroadcastHashJoinExec): Boolean = {
+  def canUseLocalShuffleReaderProbeLeft(join: BroadcastHashJoinExec): Boolean 
= {
 
 Review comment:
   We can remove it now

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


With regards,
Apache Git Services

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

Reply via email to