rubenada commented on code in PR #2848:
URL: https://github.com/apache/calcite/pull/2848#discussion_r913569721


##########
core/src/main/java/org/apache/calcite/rel/rules/SemiJoinRule.java:
##########
@@ -232,6 +237,79 @@ default JoinToSemiJoinRuleConfig 
withOperandFor(Class<Join> joinClass,
     }
   }
 
+  /**
+   * SemiJoinRule that matches a Join with a RelNode which is unique
+   * for Join's right keys.
+   *
+   * @see CoreRules#JOIN_ON_UNIQUE_TO_SEMI_JOIN */
+  public static class JoinOnUniqueToSemiJoinRule extends SemiJoinRule {
+
+    /** Creates a JoinOnUniqueToSemiJoinRule. */
+    protected JoinOnUniqueToSemiJoinRule(JoinOnUniqueToSemiJoinRuleConfig 
config) {
+      super(config);
+    }
+
+    @Override public void onMatch(RelOptRuleCall call) {
+      final Project project = call.rel(0);
+      final Join join = call.rel(1);
+      final RelNode left = call.rel(2);
+      final RelNode right = call.rel(3);
+
+      // return if right's fields are used.
+      final ImmutableBitSet bits =
+          RelOptUtil.InputFinder.bits(project.getProjects(), null);
+      final ImmutableBitSet rightBits =
+          ImmutableBitSet.range(left.getRowType().getFieldCount(),
+              join.getRowType().getFieldCount());
+      if (bits.intersects(rightBits)) {

Review Comment:
   Shall we move the applicability conditions (`!bits.intersects(rightBits)` 
and `unique != null && unique`) to the `matches` method instead of `onMatch` ?



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

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to