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



##########
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 am a little bit skeptical about it. It shouldn't work that way. If 
there isn't a match, it should generate nulls on left, but building hash table 
on right side will make it impossible. Can you write a query and execute it?




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