hsyuan commented on a change in pull request #1102: [CALCITE-1515] RelBuilder
supports creating TableFunctionScan
URL: https://github.com/apache/calcite/pull/1102#discussion_r264853138
##########
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:
You don't need to add make immutable copy. The RexCall constructor will do.
----------------------------------------------------------------
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