julianhyde commented on a change in pull request #1334: [CALCITE-3111] Allow 
custom implementations of Correlate in RelDecorr…
URL: https://github.com/apache/calcite/pull/1334#discussion_r310861684
 
 

 ##########
 File path: core/src/main/java/org/apache/calcite/tools/RelBuilder.java
 ##########
 @@ -1978,6 +1978,21 @@ public RelBuilder join(JoinRelType joinType, RexNode 
condition,
     return this;
   }
 
+  /** Creates a {@link org.apache.calcite.rel.core.Correlate}
+   * with correlateId and requiredColumns. */
+  public RelBuilder correlate(JoinRelType joinType,
+      CorrelationId correlationId, ImmutableBitSet requiredColumns) {
+    Frame right = stack.pop();
+    final Frame left = stack.pop();
+    final RelNode join = correlateFactory
+        .createCorrelate(left.rel, right.rel, correlationId, requiredColumns, 
joinType);
+    final ImmutableList.Builder<Field> fields = ImmutableList.builder();
+    fields.addAll(left.fields);
+    fields.addAll(right.fields);
+    stack.push(new Frame(join, fields.build()));
+    return this;
+  }
+
 
 Review comment:
   The test you added is
   ```
   RelNode root = builder.scan("EMP")
           .variable(v)
           .scan("DEPT")
           .filter(
               builder.equals(builder.field(0),
                   builder.field(v.get(), "DEPTNO")))
           .correlate(JoinRelType.LEFT, v.get().id,
               Lists.newArrayList(
                   SqlTypeUtil.findField(builder.peek(1).getRowType(), 
"DEPTNO")))
           .build();
   ```
   
   I think that the test should be
   ```
   RelNode root = builder.scan("EMP")
           .variable(v)
           .scan("DEPT")
           .filter(
               builder.equals(builder.field(0),
                   builder.field(v.get(), "DEPTNO")))
           .correlate(JoinRelType.LEFT, v.get().id, builder.field(2, 0, 
"DEPTNO"))
           .build();
   ```
   
   That's to say, the signature should be
   ```
   public RelBuilder correlate(JoinRelType joinType,
         CorrelationId correlationId, RexNode... requiredFields)
   ```
   and also, the overloaded method
   ```
   public RelBuilder correlate(JoinRelType joinType,
         CorrelationId correlationId, Iterable<? extends RexNode> 
requiredFields)
   ```
   
   Normally, as in this case, `requiredFields` is one `RexInputRef`. But it 
might be several expressions, and if so, `correlate` should create an extra 
`Project`. (See how `aggregate(GroupKey, Iterable<AggCall>)` uses a `Registrar` 
to project extra expressions. You should probably use a `Registrar` too.)

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


With regards,
Apache Git Services

Reply via email to