Kikyou1997 commented on code in PR #19934:
URL: https://github.com/apache/doris/pull/19934#discussion_r1206201943


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/CascadesContext.java:
##########
@@ -454,4 +484,98 @@ public void close() {
             }
         }
     }
+
+    public void putCTEIdToCTEClosure(int cteId, Callable<LogicalPlan> 
cteClosure) {
+        this.cteIdToCTEClosure.put(cteId, cteClosure);
+    }
+
+    public void putCTEIdToCTEClosure(Map<Integer, Callable<LogicalPlan>> 
cteConsumers) {
+        this.cteIdToCTEClosure.putAll(cteConsumers);
+    }
+
+    public void putCTEIdToConsumer(LogicalCTEConsumer cteConsumer) {
+        Set<LogicalCTEConsumer> consumers =
+                this.cteIdToConsumer.computeIfAbsent(cteConsumer.getCteId(), k 
-> new HashSet<>());
+        consumers.add(cteConsumer);
+    }
+
+    public void putCTEIdToConsumer(Map<Integer, Set<LogicalCTEConsumer>> 
cteConsumers) {
+        this.cteIdToConsumer.putAll(cteConsumers);
+    }
+
+    public void putCTEIdToFilter(int cteId, Expression f) {
+        Set<Expression> filters = this.cteIdToFilter.computeIfAbsent(cteId, k 
-> new HashSet<>());
+        filters.add(f);
+    }
+
+    public void putCTEIdToProject(int cteId, Expression p) {
+        Set<Expression> projects = this.cteIdToProject.computeIfAbsent(cteId, 
k -> new HashSet<>());
+        projects.add(p);
+    }
+
+    public Set<Expression> findProjectForProducer(int cteId) {
+        return this.cteIdToProject.get(cteId);
+    }
+
+    /**
+     * Fork for rewritten child tree of CTEProducer.
+     */
+    public CascadesContext forkForCTEProducer(Plan plan) {
+        CascadesContext cascadesContext = new CascadesContext(plan, memo, 
statementContext, PhysicalProperties.ANY);
+        cascadesContext.cteIdToConsumer = cteIdToConsumer;
+        cascadesContext.cteIdToFilter = cteIdToFilter;
+        cascadesContext.cteIdToProject = cteIdToProject;
+        cascadesContext.cteContext = cteContext;
+        cascadesContext.cteIdToCTEClosure = cteIdToCTEClosure;
+        cascadesContext.consumerIdToFilter = consumerIdToFilter;
+        return cascadesContext;
+    }
+
+    public int cteReferencedCount(int cteId) {
+        Set<LogicalCTEConsumer> cteConsumer = cteIdToConsumer.get(cteId);
+        if (cteConsumer == null) {
+            return 0;
+        }
+        return cteIdToConsumer.get(cteId).size();
+    }
+
+    public Map<Integer, Set<LogicalCTEConsumer>> getCteIdToConsumer() {
+        return cteIdToConsumer;
+    }
+
+    public Map<Integer, Callable<LogicalPlan>> getCteIdToCTEClosure() {
+        return cteIdToCTEClosure;
+    }
+
+    public LogicalPlan findCTEPlanForInline(int cteId) {
+        try {
+            return cteIdToCTEClosure.get(cteId).call();
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    public void putConsumerIdToFilter(int id, Expression filter) {
+        Set<Expression> filters = this.consumerIdToFilter.computeIfAbsent(id, 
k -> new HashSet<>());
+        filters.add(filter);
+    }
+
+    public Set<Expression> findFiltersForConsumer(int id) {
+        return this.consumerIdToFilter.get(id);
+    }
+
+    public Map<Integer, Set<Expression>> getConsumerIdToFilter() {
+        return consumerIdToFilter;
+    }
+
+    public void markConsumerUnderProject(LogicalCTEConsumer cteConsumer) {
+        Set<Integer> consumerIds =
+                
this.cteIdToConsumerUnderProject.computeIfAbsent(cteConsumer.getCteId(), k -> 
new HashSet<>());
+        consumerIds.add(cteConsumer.getConsumerId());
+    }

Review Comment:
   You missed something.



-- 
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: commits-unsubscr...@doris.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to