amaliujia commented on a change in pull request #2006:
URL: https://github.com/apache/calcite/pull/2006#discussion_r439791483
##########
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();
+ ImmutableBitSet reqKeySet = ImmutableBitSet.of(reqKeys);
ImmutableBitSet leftKeySet = ImmutableBitSet.of(joinInfo.leftKeys);
ImmutableBitSet rightKeySet = ImmutableBitSet.of(joinInfo.rightKeys)
- .shift(left.getRowType().getFieldCount());
+ .shift(leftInputFieldCount);
- // Only consider exact key match for now
if (reqKeySet.equals(leftKeySet)) {
+ // if sort keys equal to left join keys, we can pass through all
collations directly.
Mappings.TargetMapping mapping = buildMapping(true);
RelCollation rightCollation = collation.apply(mapping);
return Pair.of(
required, ImmutableList.of(required,
required.replace(rightCollation)));
+ } else if (containsOrderless(collation, leftKeys)) {
Review comment:
yeah I guess I have made this wrong.
The current MergeJoin implementation construct key comparator just by sort
key. If keep code here unchanged, I think I need to update at least this line:
https://github.com/apache/calcite/blob/master/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableMergeJoin.java#L310
Basically if there are collations defined (on join keys), the key comparator
(and key selector) will need to be constructed on collations's ordering.
----------------------------------------------------------------
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]