YangShaw commented on code in PR #14534:
URL: https://github.com/apache/doris/pull/14534#discussion_r1031152377


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/CTEContext.java:
##########
@@ -17,48 +17,89 @@
 
 package org.apache.doris.nereids.rules.analysis;
 
+import org.apache.doris.nereids.exceptions.AnalysisException;
+import org.apache.doris.nereids.trees.plans.Plan;
 import org.apache.doris.nereids.trees.plans.logical.LogicalPlan;
+import org.apache.doris.nereids.trees.plans.logical.LogicalSubQueryAlias;
+
+import com.google.common.collect.ImmutableMap;
 
-import java.util.HashMap;
 import java.util.Map;
+import java.util.Optional;
+import java.util.function.Function;
+import javax.annotation.Nullable;
 
 /**
  * Context used for CTE analysis and register
  */
 public class CTEContext {
+    private Map<String, CTEContext> cteContextMap;
 
-    // store CTE name and both initial and analyzed LogicalPlan of with query;
-    // The initial LogicalPlan is used to inline a CTE if it is referenced by 
another CTE,
-    // and the analyzed LogicalPlan will be  if it is referenced by the main 
query.
-    private Map<String, LogicalPlan> initialCtePlans;
-    private Map<String, LogicalPlan> analyzedCtePlans;
+    private String name;
+    private LogicalSubQueryAlias<Plan> parsedPlan;
+    // this cache only use once
+    private LogicalPlan analyzedPlanCacheOnce;
+    private Function<Plan, LogicalPlan> analyzePlanBuilder;
 
+    /* build head CTEContext */
     public CTEContext() {
-        initialCtePlans = new HashMap<>();
-        analyzedCtePlans = new HashMap<>();
+        this(null, null);
+    }
+
+    /** CTEContext */
+    public CTEContext(@Nullable LogicalSubQueryAlias<Plan> parsedPlan, 
@Nullable CTEContext previousCteContext) {
+        if ((parsedPlan == null && previousCteContext != null) || (parsedPlan 
!= null && previousCteContext == null)) {
+            throw new AnalysisException("Only first CteContext can contains 
null cte plan or previousCteContext");
+        }
+        this.parsedPlan = parsedPlan;
+        this.name = parsedPlan == null ? null : parsedPlan.getAlias();
+        this.cteContextMap = previousCteContext == null
+                ? ImmutableMap.of()
+                : ImmutableMap.<String, CTEContext>builder()
+                        .putAll(previousCteContext.cteContextMap)
+                        .put(name, this)
+                        .build();
+    }
+
+    public void setAnalyzedPlanCacheOnce(LogicalPlan initialPlan) {
+        this.analyzedPlanCacheOnce = initialPlan;

Review Comment:
   maybe it is more clear to add “analyzed” to the argument's name? like 
"initialAnalyzedPlan" or "analyzedPlan"



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