yashmayya commented on code in PR #2848: URL: https://github.com/apache/calcite/pull/2848#discussion_r1613307615
########## core/src/main/java/org/apache/calcite/rel/rules/SemiJoinRule.java: ########## @@ -232,6 +234,84 @@ default JoinToSemiJoinRuleConfig withOperandFor(Class<Join> joinClass, } } + /** + * SemiJoinRule that matches a Project on top of 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 boolean matches(RelOptRuleCall call) { + final Project project = call.rel(0); + final Join join = call.rel(1); + final RelNode left = call.rel(2); + + final ImmutableBitSet bits = + RelOptUtil.InputFinder.bits(project.getProjects(), null); + final ImmutableBitSet rightBits = + ImmutableBitSet.range(left.getRowType().getFieldCount(), + join.getRowType().getFieldCount()); + return !bits.intersects(rightBits); + } + + @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); + + final JoinInfo joinInfo = join.analyzeCondition(); + final RelOptCluster cluster = join.getCluster(); + final RelMetadataQuery mq = cluster.getMetadataQuery(); + final Boolean unique = mq.areColumnsUnique(right, joinInfo.rightSet()); Review Comment: This doesn't take into account any `nonEquiConditions` on the join? We also aren't verifying beforehand whether the join is an equi-join as is being done for the other two semi-join rules `ProjectToSemiJoinRule` and `JoinToSemiJoinRule` here - https://github.com/apache/calcite/blob/4def07066b6cb370e37739985b19f6e6b408addb/core/src/main/java/org/apache/calcite/rel/rules/SemiJoinRule.java#L96-L98 @libenchao do you think this is a potential bug in the `JoinOnUniqueToSemiJoinRule`? -- 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: commits-unsubscr...@calcite.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org