zabetak commented on a change in pull request #1020: [CALCITE-2812] Add algebraic operators to allow expressing recursive queries (Ruben Quesada Lopez) URL: https://github.com/apache/calcite/pull/1020#discussion_r276293033
########## File path: core/src/main/java/org/apache/calcite/tools/RelBuilder.java ########## @@ -1705,6 +1711,61 @@ public RelBuilder minus(boolean all, int n) { return setOp(all, SqlKind.EXCEPT, n); } + /** + * Creates a {@link LogicalTableScan} on a {@link TransientTable} (used e.g. to accumulate + * results in repeat union operation), using as its row type the top of the stack's row type. + * Returns this builder. + */ + @Experimental + public RelBuilder transientScan(String tableName) { + return this.transientScan(tableName, this.peek().getRowType()); + } + + /** + * Creates a {@link LogicalTableScan} on a {@link TransientTable} (used e.g. to accumulate + * results in repeat union operation). + * Returns this builder. + * @param tableName table name + * @param rowType row type of the table + */ + @Experimental + public RelBuilder transientScan(String tableName, RelDataType rowType) { + TransientTable transientTable = new TransientTable(tableName, rowType); + RelOptTable relOptTable = RelOptTableImpl.create( + relOptSchema, + rowType, + transientTable, + ImmutableList.of(tableName)); + RelNode scan = scanFactory.createScan(cluster, relOptTable); + push(scan); + rename(rowType.getFieldNames()); + return this; + } + + /** + * Creates a {@link LogicalRepeatUnion} with no maxRep, i.e. repeatUnion(tableName, -1). + * @param tableName transient table name associated to the repeat union + */ + @Experimental + public RelBuilder repeatUnion(String tableName) { + return this.repeatUnion(tableName, -1); + } + + /** + * Creates a {@link LogicalRepeatUnion} of the two most recent relational expressions + * on the stack. Warning: if these relational expressions are not correctly defined, + * this operation might lead to an infinite loop. + * Returns this builder. + * @param tableName transient table name associated to the repeat union + * @param maxRep maximum number of iterations, -1 means no limit + */ + @Experimental + public RelBuilder repeatUnion(String tableName, int maxRep) { + RelNode iter = LogicalTableSpool.create(build(), Spool.Type.LAZY, Spool.Type.LAZY, tableName); Review comment: Plus instead of using directly the create method it would be preferable to use factories that are passed through the context to the builder as it is done for the other operators. ---------------------------------------------------------------- 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: us...@infra.apache.org With regards, Apache Git Services