zabetak commented on a change in pull request #884: [CALCITE-2621] New rule: 
SemiJoinToCorrelateRule (SemiJoin => LogicalCorrelate) (Ruben Quesada Lopez)
URL: https://github.com/apache/calcite/pull/884#discussion_r261641280
 
 

 ##########
 File path: 
core/src/main/java/org/apache/calcite/rel/rules/JoinToCorrelateRule.java
 ##########
 @@ -56,31 +60,57 @@
  *
  * <p>would require emitting a NULL emp row if a certain department contained 
no
  * employees, and Correlator cannot do that.</p>
+ *
+ * <p>There is a constructor parameterized to allow any sub-class of
+ * {@link org.apache.calcite.rel.core.Join}, not just
+ * {@link org.apache.calcite.rel.logical.LogicalJoin}.</p>
  */
 public class JoinToCorrelateRule extends RelOptRule {
+
+  private final Function<Join, SemiJoinType> semiJoinTypeFunction;
+
   //~ Static fields/initializers ---------------------------------------------
 
   public static final JoinToCorrelateRule INSTANCE =
       new JoinToCorrelateRule(RelFactories.LOGICAL_BUILDER);
 
+  /**
+   * Rule that converts a {@link org.apache.calcite.rel.core.SemiJoin}
+   * into a {@link org.apache.calcite.rel.logical.LogicalCorrelate}
+   */
+  public static final JoinToCorrelateRule SEMI =
+      new JoinToCorrelateRule(SemiJoin.class,
+              RelFactories.LOGICAL_BUILDER, join -> SemiJoinType.SEMI);
+
   //~ Constructors -----------------------------------------------------------
 
   /**
    * Creates a JoinToCorrelateRule.
    */
   public JoinToCorrelateRule(RelBuilderFactory relBuilderFactory) {
-    super(operand(LogicalJoin.class, any()), relBuilderFactory, null);
+    this(LogicalJoin.class, relBuilderFactory, join -> 
SemiJoinType.of(join.getJoinType()));
   }
 
   @Deprecated // to be removed before 2.0
   protected JoinToCorrelateRule(RelFactories.FilterFactory filterFactory) {
     this(RelBuilder.proto(Contexts.of(filterFactory)));
   }
 
+  /**
+   * Creates a JoinToCorrelateRule for a certain sub-class of
+   * {@link org.apache.calcite.rel.core.Join}
+   */
+  public JoinToCorrelateRule(Class<? extends Join> clazz,
+                             RelBuilderFactory relBuilderFactory,
+                             Function<Join, SemiJoinType> 
semiJoinTypeFunction) {
 
 Review comment:
   (Minor suggestion) Maybe rename the `semiJoinTypeFunction` to something 
better illustrating what does it do. Something like `semiJoinTypeExtractor`, 
`semiJoinTypeMapper`, etc.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to