julianhyde commented on a change in pull request #1102: [CALCITE-1515]
RelBuilder supports creating TableFunctionScan
URL: https://github.com/apache/calcite/pull/1102#discussion_r265401364
##########
File path: core/src/main/java/org/apache/calcite/tools/RelBuilder.java
##########
@@ -1045,6 +1053,66 @@ 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 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));
+ }
+
Review comment:
Currently the cursor function accesses the `ordinal`th element from the top
of the stack. So, if we create a table function with two inputs, the left input
will be cursor(1) and the right input will be cursor(0).
But we actually want them to be the other way around.
I suggest that you add an `inputCount` parameter (see: `field(inputCount,
inputOrdinal, fieldOrdinal)`). Thus the left input would be `cursor(2, 0)`, and
the right input would be `cursor(2, 1)`.
By the way, it is correct to call `peek` here. But `functionScan` should
call pop for each input.
----------------------------------------------------------------
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