diff --git a/gluten-substrait/src/main/scala/org/apache/gluten/execution/BroadcastNestedLoopJoinExecTransformer.scala b/gluten-substrait/src/main/scala/org/apache/gluten/execution/BroadcastNestedLoopJoinExecTransformer.scala index 6c0398fff8f3..b7be3d90ca34 100644 --- a/gluten-substrait/src/main/scala/org/apache/gluten/execution/BroadcastNestedLoopJoinExecTransformer.scala +++ b/gluten-substrait/src/main/scala/org/apache/gluten/execution/BroadcastNestedLoopJoinExecTransformer.scala @@ -49,9 +49,9 @@ abstract class BroadcastNestedLoopJoinExecTransformer( override def rightKeys: Seq[Expression] = Nil private lazy val substraitJoinType: CrossRel.JoinType = - SubstraitUtil.toCrossRelSubstrait(joinType, buildSide) + SubstraitUtil.toCrossRelSubstrait(joinType, needSwitchChildren) - // Unique ID for builded table + // Unique ID for built table. lazy val buildBroadcastTableId: String = "BuiltBNLJBroadcastTable-" + buildPlan.id // Hint substrait to switch the left and right, diff --git a/gluten-substrait/src/main/scala/org/apache/gluten/utils/SubstraitUtil.scala b/gluten-substrait/src/main/scala/org/apache/gluten/utils/SubstraitUtil.scala index 6aeda9cd1e6e..6a678014ebcd 100644 --- a/gluten-substrait/src/main/scala/org/apache/gluten/utils/SubstraitUtil.scala +++ b/gluten-substrait/src/main/scala/org/apache/gluten/utils/SubstraitUtil.scala @@ -23,7 +23,6 @@ import org.apache.gluten.substrait.SubstraitContext import org.apache.gluten.substrait.expression.ExpressionNode import org.apache.spark.sql.catalyst.expressions.{Attribute, Expression} -import org.apache.spark.sql.catalyst.optimizer.{BuildLeft, BuildRight, BuildSide} import org.apache.spark.sql.catalyst.plans.{FullOuter, InnerLike, JoinType, LeftAnti, LeftOuter, LeftSemi, RightOuter} import io.substrait.proto.{CrossRel, JoinRel} @@ -50,7 +49,7 @@ object SubstraitUtil { JoinRel.JoinType.UNRECOGNIZED } - def toCrossRelSubstrait(sparkJoin: JoinType, buildSide: BuildSide): CrossRel.JoinType = + def toCrossRelSubstrait(sparkJoin: JoinType, needSwitchChildren: Boolean): CrossRel.JoinType = sparkJoin match { case _: InnerLike => CrossRel.JoinType.JOIN_TYPE_INNER @@ -58,14 +57,16 @@ object SubstraitUtil { // since we always assume build right side in substrait, // the left and right relations are exchanged and the // join type is reverted. - buildSide match { - case BuildLeft => CrossRel.JoinType.JOIN_TYPE_RIGHT - case BuildRight => CrossRel.JoinType.JOIN_TYPE_LEFT + if (needSwitchChildren) { + CrossRel.JoinType.JOIN_TYPE_RIGHT + } else { + CrossRel.JoinType.JOIN_TYPE_LEFT } case RightOuter => - buildSide match { - case BuildRight => CrossRel.JoinType.JOIN_TYPE_RIGHT - case BuildLeft => CrossRel.JoinType.JOIN_TYPE_LEFT + if (needSwitchChildren) { + CrossRel.JoinType.JOIN_TYPE_LEFT + } else { + CrossRel.JoinType.JOIN_TYPE_RIGHT } case LeftSemi => CrossRel.JoinType.JOIN_TYPE_LEFT_SEMI