hsyuan commented on a change in pull request #2006:
URL: https://github.com/apache/calcite/pull/2006#discussion_r437685863
##########
File path:
core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableMergeJoin.java
##########
@@ -131,8 +160,35 @@ public static boolean isMergeJoinSupported(JoinRelType
joinType) {
required, ImmutableList.of(
required.replace(leftCollation),
required.replace(rightCollation)));
+ } else if (isSubset(reqKeys, rightKeys)) {
+ // if sort keys are subset of right join keys, we can extend collations
to make sure all join
+ // keys are sorted.
+ collation = extendCollation(collation, rightKeys);
+ RelCollation rightCollation = RelCollations.shift(collation,
+ -left.getRowType().getFieldCount());
+ Mappings.TargetMapping invMapping = mapping.inverse();
+ RelCollation leftCollation = RexUtil.apply(invMapping, rightCollation);
+ return Pair.of(
+ required, ImmutableList.of(
+ required.replace(leftCollation),
+ required.replace(rightCollation)));
+ } else if (isPrefixOrderingNotRequired(rightKeys, reqKeys)
+ && allElementsGe(reqKeys, getLeft().getRowType().getFieldCount())) {
Review comment:
can we use `reqKeys.stream().allMatch()`?
##########
File path:
core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableMergeJoin.java
##########
@@ -131,8 +160,35 @@ public static boolean isMergeJoinSupported(JoinRelType
joinType) {
required, ImmutableList.of(
required.replace(leftCollation),
required.replace(rightCollation)));
+ } else if (isSubset(reqKeys, rightKeys)) {
+ // if sort keys are subset of right join keys, we can extend collations
to make sure all join
+ // keys are sorted.
+ collation = extendCollation(collation, rightKeys);
+ RelCollation rightCollation = RelCollations.shift(collation,
+ -left.getRowType().getFieldCount());
+ Mappings.TargetMapping invMapping = mapping.inverse();
+ RelCollation leftCollation = RexUtil.apply(invMapping, rightCollation);
+ return Pair.of(
+ required, ImmutableList.of(
+ required.replace(leftCollation),
+ required.replace(rightCollation)));
+ } else if (isPrefixOrderingNotRequired(rightKeys, reqKeys)
+ && allElementsGe(reqKeys, getLeft().getRowType().getFieldCount())) {
+ // if sort keys are superset of right join keys, and right join keys is
prefix of sort keys
+ // (order not matter), also sort keys are all from right join input.
+ RelCollation rightCollation = RelCollations.shift(collation,
+ -left.getRowType().getFieldCount());
Review comment:
let's use a var to store `left.getRowType().getFieldCount()`.
----------------------------------------------------------------
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]