amaliujia commented on a change in pull request #1995:
URL: https://github.com/apache/calcite/pull/1995#discussion_r435018987



##########
File path: 
core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableHashJoin.java
##########
@@ -100,6 +106,53 @@ public static EnumerableHashJoin create(
         condition, variablesSet, joinType);
   }
 
+  @Override public Pair<RelTraitSet, List<RelTraitSet>> passThroughTraits(
+      final RelTraitSet required) {
+    RelCollation collation = required.getCollation();
+    if (collation == null || collation == RelCollations.EMPTY) {
+      return null;
+    }
+
+    List<Integer> requiredKeys = RelCollations.ordinals(collation);
+    ImmutableBitSet requiredKeySet = ImmutableBitSet.of(requiredKeys);
+
+    ImmutableBitSet leftKeySet = ImmutableBitSet.of(joinInfo.leftKeys);
+    ImmutableBitSet rightKeySet = ImmutableBitSet.of(joinInfo.rightKeys)
+        .shift(left.getRowType().getFieldCount());
+
+    // HashJoin traits passdown shall only consider left/right outer join.
+    // It is because for a hash-based implementation, only non-hashed side can
+    // preserve ordering, thus only for left/right outer join, we are sure 
which
+    // side is non-hashed side (the outer child).
+    if (joinType == JoinRelType.LEFT) {
+      // Only consider exact key match for now
+      if (requiredKeySet.equals(leftKeySet)) {
+        return Pair.of(
+            required,
+            ImmutableList.of(
+                required,
+                required.replace(RelCollations.EMPTY)));
+      }
+    } else if (joinType == JoinRelType.RIGHT) {
+      // Only consider exact key match for now
+      if (requiredKeySet.equals(rightKeySet)) {
+        RelCollation rightCollation = RelCollations.shift(collation,
+            -left.getRowType().getFieldCount());
+        return Pair.of(
+            required,
+            ImmutableList.of(
+                required.replace(RelCollations.EMPTY),
+                required.replace(rightCollation)));
+      }
+    }
+
+    return null;
+  }
+
+//  @Override public DeriveMode getDeriveMode() {
+//    return DeriveMode.BOTH;

Review comment:
       I confirmed that indeed EnumerableHashJoin always builds hash table on 
right side. 
   
   For right/full outer join, to make result right, the implementation keeps a 
set of keys from right side. During probing it also removes keys from that set. 
At the end it will know how many keys from right side does not have a match 
with left side, thus it can produces null with right tuples. 
   
   
   So I will prohibit traits propogation for right/full outer join.




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


Reply via email to