Repository: hive
Updated Branches:
  refs/heads/master fafa953ff -> 99c0cafe5


HIVE-16947: Semijoin Reduction : Task cycle created due to multiple semijoins 
in conjunction with hashjoin (Deepak Jaiswal, reviewed by Jason Dere)


Project: http://git-wip-us.apache.org/repos/asf/hive/repo
Commit: http://git-wip-us.apache.org/repos/asf/hive/commit/99c0cafe
Tree: http://git-wip-us.apache.org/repos/asf/hive/tree/99c0cafe
Diff: http://git-wip-us.apache.org/repos/asf/hive/diff/99c0cafe

Branch: refs/heads/master
Commit: 99c0cafe5e40092fc4cf19074c9d5739b9ba6a49
Parents: fafa953
Author: Jason Dere <jd...@hortonworks.com>
Authored: Wed Jun 28 10:58:57 2017 -0700
Committer: Jason Dere <jd...@hortonworks.com>
Committed: Wed Jun 28 10:58:57 2017 -0700

----------------------------------------------------------------------
 .../hive/ql/optimizer/ConvertJoinMapJoin.java   | 34 +++++++++++++-------
 1 file changed, 23 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hive/blob/99c0cafe/ql/src/java/org/apache/hadoop/hive/ql/optimizer/ConvertJoinMapJoin.java
----------------------------------------------------------------------
diff --git 
a/ql/src/java/org/apache/hadoop/hive/ql/optimizer/ConvertJoinMapJoin.java 
b/ql/src/java/org/apache/hadoop/hive/ql/optimizer/ConvertJoinMapJoin.java
index 98fec77..21d0053 100644
--- a/ql/src/java/org/apache/hadoop/hive/ql/optimizer/ConvertJoinMapJoin.java
+++ b/ql/src/java/org/apache/hadoop/hive/ql/optimizer/ConvertJoinMapJoin.java
@@ -888,19 +888,31 @@ public class ConvertJoinMapJoin implements NodeProcessor {
       }
 
       // Found a semijoin branch.
-      for (Operator<?> parent : mapjoinOp.getParentOperators()) {
-        if (!(parent instanceof ReduceSinkOperator)) {
-          continue;
-        }
+      // There can be more than one semijoin branch coming from the parent
+      // GBY Operator of the RS Operator.
+      Operator<?> parentGB = op.getParentOperators().get(0);
+      for (Operator<?> childRS : parentGB.getChildOperators()) {
+        // Get the RS and TS for this branch
+        rs = (ReduceSinkOperator) childRS;
+        ts = parseContext.getRsToSemiJoinBranchInfo().get(rs).getTsOp();
+        assert ts != null;
+        for (Operator<?> parent : mapjoinOp.getParentOperators()) {
+          if (!(parent instanceof ReduceSinkOperator)) {
+            continue;
+          }
 
-        Set<TableScanOperator> tsOps = 
OperatorUtils.findOperatorsUpstream(parent,
-                TableScanOperator.class);
-        for (TableScanOperator parentTS : tsOps) {
-          // If the parent is same as the ts, then we have a cycle.
-          if (ts == parentTS) {
-            semiJoinMap.put(rs, ts);
-            break;
+          Set<TableScanOperator> tsOps = 
OperatorUtils.findOperatorsUpstream(parent,
+                  TableScanOperator.class);
+          boolean found = false;
+          for (TableScanOperator parentTS : tsOps) {
+            // If the parent is same as the ts, then we have a cycle.
+            if (ts == parentTS) {
+              semiJoinMap.put(rs, ts);
+              found = true;
+              break;
+            }
           }
+          if (found) break;
         }
       }
     }

Reply via email to