You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by GitBox <gi...@apache.org> on 2019/03/13 02:47:13 UTC

[GitHub] [calcite] chunweilei commented on a change in pull request #1102: [CALCITE-1515] RelBuilder supports creating TableFunctionScan

chunweilei commented on a change in pull request #1102: [CALCITE-1515] RelBuilder supports creating TableFunctionScan
URL: https://github.com/apache/calcite/pull/1102#discussion_r264957611
 
 

 ##########
 File path: core/src/main/java/org/apache/calcite/tools/RelBuilder.java
 ##########
 @@ -1045,6 +1053,69 @@ public RelBuilder snapshot(RexNode period) {
     return this;
   }
 
+
+  /**
+   * Gets column mappings of the operator.
+   *
+   * @param op operator instance
+   * @return column mappings associated with this function
+   */
+  private Set<RelColumnMapping> getColumnMappings(SqlOperator op) {
+    SqlReturnTypeInference inference = op.getReturnTypeInference();
+    if (inference == null) {
+      return null;
+    }
+    if (inference instanceof TableFunctionReturnTypeInference) {
+      return ((TableFunctionReturnTypeInference) inference).getColumnMappings();
+    } else {
+      return null;
+    }
+  }
+
+  /**
+   * Create a RexCall to the CURSOR function by ordinal.
+   *
+   * @param ordinal the reference to the relational input
+   * @return RexCall to CURSOR function
+   */
+  public RexNode cursor(int ordinal) {
+    return getRexBuilder().makeCall(SqlStdOperatorTable.CURSOR, getRexBuilder()
+        .makeInputRef(peek(stack.size() - ordinal - 1).getRowType(), ordinal));
+  }
+
+  /**
+   * Creates a {@link TableFunctionScan}.
+   *
+   */
+  public RelBuilder functionScan(SqlOperator operator,
+      Iterable<? extends RexNode> operands) {
+    List<RelNode> inputs = new ArrayList<>();
+    int total = stack.size();
+
+    // Get inputs from operands.
+    for (RexNode operand : operands) {
+      if (operand instanceof RexCall) {
+        if (operand.getKind() == SqlKind.CURSOR) {
+          RexNode node = ((RexCall) operand).getOperands().get(0);
+          assert node instanceof RexInputRef;
+          inputs.add(peek(total - ((RexInputRef) node).getIndex() - 1));
+        }
+      }
+    }
+
+    RexNode call = getRexBuilder()
+        .makeCall(operator, ImmutableList.copyOf(operands));
 
 Review comment:
   It do not target to make immutable copy. It converts operands whose type is Iterable<? extends RexNode> to List using ImmutableList#copyOf. 

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services