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



##########
File path: 
core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableMergeJoin.java
##########
@@ -134,31 +137,83 @@ public static boolean isMergeJoinSupported(JoinRelType 
joinType) {
       final RelTraitSet required) {
     // Required collation keys can be subset or superset of merge join keys.
     RelCollation collation = required.getCollation();
+    int leftInputFieldCount = left.getRowType().getFieldCount();
+
     List<Integer> reqKeys = RelCollations.ordinals(collation);
-    ImmutableBitSet reqKeySet = ImmutableBitSet.of(reqKeys);
+    List<Integer> leftKeys = joinInfo.leftKeys.toIntegerList();
+    List<Integer> rightKeys =
+        joinInfo.rightKeys.incr(leftInputFieldCount).toIntegerList();
+    List<Integer> rightKeysNotShifted = joinInfo.rightKeys.toIntegerList();

Review comment:
       To this specific case, `toIntegerList` to get a list of key indexes (not 
shifted, so index from 0). Then, later, in superset cases, we can use this list 
to remove collations that are not on keys. Use this query as an example:
   `select * from foo join bar on foo.a=bar.a and foo.b=bar.b order by bar.a, 
bar.b, bar.c;
   `
   
   we can push
   `collation a b to left`
   `collation a, b, c to right`
   Thus the output of join should still be sorted by a, b, c.
   
   
   Then, the `toIntegerList` helps to to that only `a, b` needs to pushed to 
left.  It works along with 
   ```
   RelCollation rightCollation = RelCollations.shift(collation, 
-leftInputFieldCount);
   Mappings.TargetMapping mapping = buildMapping(false);
   RelCollation leftCollation =
             RexUtil.apply(
                 mapping,
                 removeCollationFieldsNotOnJoinKey(rightCollation, 
rightKeysNotShifted));
   ```




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