maropu commented on a change in pull request #29035:
URL: https://github.com/apache/spark/pull/29035#discussion_r452549562



##########
File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/EliminateResolvedHint.scala
##########
@@ -43,6 +43,22 @@ object EliminateResolvedHint extends Rule[LogicalPlan] {
       case h: ResolvedHint =>
         hintErrorHandler.joinNotFoundForJoinHint(h.hints)
         h.child
+      case join: Join if join.condition.isDefined =>
+        join.copy(
+          hint = join.hint.copy(
+            leftHint = removeCartesianProductJoinHint(join.hint.leftHint),
+            rightHint = removeCartesianProductJoinHint(join.hint.rightHint)))
+    }
+  }
+
+  def removeCartesianProductJoinHint(hint: Option[HintInfo]): Option[HintInfo] 
= {

Review comment:
       It seems the spark strategy incrrectly removes `a#0 = a#2`; 
   ```
   == Optimized Logical Plan ==
   Sort [a#0 ASC NULLS FIRST], true
   +- Join Inner, (a#0 = a#2), leftHint=(strategy=shuffle_replicate_nl)
      :- Filter isnotnull(a#0)
      :  +- Relation[a#0,b#1] parquet
      +- Filter isnotnull(a#2)
         +- Relation[a#2,b#3] parquet
   
   == Physical Plan ==
   *(3) Sort [a#0 ASC NULLS FIRST], true, 0
   +- Exchange rangepartitioning(a#0 ASC NULLS FIRST, 200), true, [id=#87]
      +- CartesianProduct
         :- *(1) Project [a#0, b#1]
         :  +- *(1) Filter isnotnull(a#0)
         :     +- *(1) ColumnarToRow
         :        +- FileScan parquet default.test4[a#0,b#1] Batched: true, 
DataFilters: ...
         +- *(2) Project [a#2, b#3]
            +- *(2) Filter isnotnull(a#2)
               +- *(2) ColumnarToRow
                  +- FileScan parquet default.test5[a#2,b#3] Batched: true, 
DataFilters: ...
   ```




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