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_r258445389
########## File path: core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableRecursiveUnion.java ########## @@ -0,0 +1,137 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.calcite.adapter.enumerable; + +import org.apache.calcite.linq4j.tree.BlockBuilder; +import org.apache.calcite.linq4j.tree.DeclarationStatement; +import org.apache.calcite.linq4j.tree.Expression; +import org.apache.calcite.linq4j.tree.Expressions; +import org.apache.calcite.linq4j.tree.ParameterExpression; +import org.apache.calcite.plan.RelOptCluster; +import org.apache.calcite.plan.RelTraitSet; +import org.apache.calcite.rel.RelNode; +import org.apache.calcite.rel.RelWriter; +import org.apache.calcite.rel.core.SetOp; +import org.apache.calcite.rel.core.Union; +import org.apache.calcite.schema.Table; +import org.apache.calcite.schema.impl.TransientTable; +import org.apache.calcite.util.BuiltInMethod; + +import java.util.List; + + +/** + * Implementation of Recursive Union in + * {@link EnumerableConvention enumerable calling convention}. + */ +public class EnumerableRecursiveUnion extends Union implements EnumerableRel { Review comment: As @vlsi said earlier I am not sure if this new operator (which is a bit particular) should extend Union since there is a risk that existing rules may match when they shouldn't. Apart from that I can identify two main functionalities in this operator: 1. Iterative calls to the subplan till a certain number is reached or untill there are no more results. 2. Buffer and write to a side table/collection at certain intervals (i.e., end of iteration). I think we could try to isolate these functionalities in separate logical/physical operators with clear semantics and responsibilities which could improve encapsulation and reutilization of these operators in other use cases. I propose something along the following lines. For 1, we could have a Logical/EnumerableIterate operator while for 2, we could have a Logical/EnumerableSpool (maybe relevant to look at CALCITE-481) that takes care of buffering and writting to the side table. Then to satisfy the use cases so far the two operators should be combined the one on top of the other (Iterate[Spool[Subplan]]). Last thing that is missing is the seed which could be placed somwhere in the subplan and we should ensure somehow that is executed only once (using a filter?). @rubenada If what I am proposing appears very complicated, useless, or out of context please let me know. In any case the work so far is great :) ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on 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
