vldpyatkov commented on code in PR #13479:
URL: https://github.com/apache/ignite/pull/13479#discussion_r3926434272


##########
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/rule/RecursiveCteUtils.java:
##########
@@ -0,0 +1,214 @@
+/*
+ * 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.ignite.internal.processors.query.calcite.rule;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.calcite.plan.RelOptPlanner;
+import org.apache.calcite.plan.RelOptTable;
+import org.apache.calcite.plan.RelOptUtil;
+import org.apache.calcite.plan.RelTraitSet;
+import org.apache.calcite.plan.volcano.RelSubset;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.rel.SingleRel;
+import org.apache.calcite.rel.core.Aggregate;
+import org.apache.calcite.rel.core.AggregateCall;
+import org.apache.calcite.rel.core.TableScan;
+import org.apache.calcite.rex.RexCall;
+import org.apache.calcite.rex.RexNode;
+import org.apache.calcite.rex.RexShuttle;
+import org.apache.calcite.rex.RexSubQuery;
+import org.apache.calcite.schema.TransientTable;
+import org.apache.calcite.sql.validate.SqlUserDefinedFunction;
+import 
org.apache.ignite.internal.processors.query.calcite.exec.exp.IgniteScalarFunction;
+import 
org.apache.ignite.internal.processors.query.calcite.prepare.BaseQueryContext;
+
+/** Utilities shared by recursive CTE converter rules. */
+final class RecursiveCteUtils {
+    /** */
+    private RecursiveCteUtils() {
+        // No-op.
+    }
+
+    /** Returns whether the table is Calcite's query-local transient table. */
+    static boolean isTransient(RelOptTable table) {
+        return table != null && table.unwrap(TransientTable.class) != null;
+    }
+
+    /** Stable identifier preserved in the serialized physical plan. */
+    static String stateId(RelOptPlanner planner, RelOptTable table) {
+        BaseQueryContext ctx = 
planner.getContext().unwrap(BaseQueryContext.class);
+
+        assert ctx != null;
+
+        return ctx.recursiveCteStateId(table);
+    }
+
+    /** Counts scans of the recursive transient table. */
+    static int referenceCount(RelNode rel, RelOptTable table) {
+        rel = original(rel);
+
+        int cnt = isRecursiveScan(rel, table) ? 1 : 0;
+
+        for (RelNode input : rel.getInputs())
+            cnt += referenceCount(input, table);
+
+        return cnt;
+    }
+
+    /** Marks maximal inputs that do not depend on the current delta for 
coordinator-local rewindable conversion. */
+    static RelNode markStaticInputs(RelNode rel, RelOptTable table) {
+        rel = original(rel);
+
+        if (isRecursiveScan(rel, table))
+            return rel;
+
+        List<RelNode> inputs = rel.getInputs();
+
+        if (inputs.isEmpty())
+            return rel;
+
+        List<RelNode> newInputs = new ArrayList<>(inputs.size());
+
+        for (RelNode input : inputs) {
+            if (referenceCount(input, table) == 0 && isInvariant(input))
+                newInputs.add(new StaticInput(input));

Review Comment:
   Yes. StaticInput is currently only a marker used to defer a special trait 
conversion.
   I converted inputs immediately in RepeatUnionConverterRule and removed both 
the marker node and RecursiveStaticInputConverterRule.



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to