ulysses-you commented on code in PR #6093:
URL: https://github.com/apache/incubator-gluten/pull/6093#discussion_r1642586414


##########
gluten-core/src/main/scala/org/apache/gluten/execution/JoinExecTransformer.scala:
##########
@@ -370,6 +371,66 @@ abstract class ShuffledHashJoinExecTransformerBase(
   }
 }
 
+object ShuffledHashJoinExecTransformerBase {
+
+  private def getBuildSide(sj: ShuffledJoin, buildSide: BuildSide = null): 
BuildSide = {
+    val leftBuildable =
+      
BackendsApiManager.getSettings.supportHashBuildJoinTypeOnLeft(sj.joinType)
+    val rightBuildable =
+      
BackendsApiManager.getSettings.supportHashBuildJoinTypeOnRight(sj.joinType)
+    if (!leftBuildable) {
+      BuildRight
+    } else if (!rightBuildable) {
+      BuildLeft
+    } else {
+      sj.logicalLink match {
+        case Some(join: Join) =>
+          val leftSize = join.left.stats.sizeInBytes
+          val rightSize = join.right.stats.sizeInBytes
+          if (rightSize <= leftSize) BuildRight else BuildLeft
+        // Only the ShuffledHashJoinExec generated directly in some spark 
tests is not link
+        // logical plan, such as OuterJoinSuite.
+        case _ => Option(buildSide).getOrElse(BuildRight)
+      }
+    }
+  }
+
+  private def dropPartialSort(plan: SparkPlan): SparkPlan = plan match {
+    case sort: SortExecTransformer if !sort.global =>
+      sort.child
+    case sort: SortExec if !sort.global =>
+      sort.child
+    case _ => plan
+  }
+
+  def from(shj: ShuffledHashJoinExec): ShuffledHashJoinExecTransformerBase = {
+    BackendsApiManager.getSparkPlanExecApiInstance
+      .genShuffledHashJoinExecTransformer(
+        shj.leftKeys,
+        shj.rightKeys,
+        shj.joinType,
+        getBuildSide(shj, shj.buildSide),
+        shj.condition,
+        shj.left,
+        shj.right,
+        shj.isSkewJoin)
+  }
+
+  def from(smj: SortMergeJoinExec): ShuffledHashJoinExecTransformerBase = {
+    BackendsApiManager.getSparkPlanExecApiInstance
+      .genShuffledHashJoinExecTransformer(
+        smj.leftKeys,
+        smj.rightKeys,
+        smj.joinType,
+        getBuildSide(smj),
+        smj.condition,
+        dropPartialSort(smj.left),

Review Comment:
   Strip local sort is a bit conflict with pull out project, there is a 
pre-project leak if we pull out expr from sort first but the sort is stripped 
later. Before the smj can never happen since we plan join at strategy side.



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