morrySnow commented on code in PR #11035:
URL: https://github.com/apache/doris/pull/11035#discussion_r929852592


##########
fe/fe-core/pom.xml:
##########
@@ -668,6 +668,12 @@ under the License.
             <artifactId>maven-compiler-plugin</artifactId>
             <version>3.10.1</version>
         </dependency>
+<!--        <dependency>-->

Review Comment:
   revert these changes



##########
docs/zh-CN/developer/developer-guide/fe-idea-dev.md:
##########
@@ -32,6 +32,15 @@ under the License.
 
 安装 JDK1.8+ ,使用 IntelliJ IDEA 打开 FE.
 
+#### MacOS下载

Review Comment:
   revert these changes



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/memo/Memo.java:
##########
@@ -131,11 +172,16 @@ private Plan groupToTreeNode(Group group) {
      */
     private GroupExpression insertOrRewriteGroupExpression(GroupExpression 
groupExpression, Group target,
             boolean rewrite, LogicalProperties logicalProperties) {
-        GroupExpression existedGroupExpression = 
groupExpressions.get(groupExpression);
-        if (existedGroupExpression != null) {
+        GroupExpressionAdapter adapter = new 
GroupExpressionAdapter(groupExpression);
+        // GroupExpression existedGroupExpression = 
groupExpressions.get(groupExpression);

Review Comment:
   remove useless code directly



##########
fe/fe-core/src/test/java/org/apache/doris/nereids/util/AnalyzeSubQueryTest.java:
##########
@@ -0,0 +1,261 @@
+// 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.doris.nereids.util;
+
+import org.apache.doris.common.AnalysisException;
+import org.apache.doris.nereids.NereidsPlanner;
+import org.apache.doris.nereids.PlannerContext;
+import org.apache.doris.nereids.analyzer.Unbound;
+import org.apache.doris.nereids.jobs.JobContext;
+import org.apache.doris.nereids.jobs.batch.FinalizeAnalyzeJob;
+import org.apache.doris.nereids.jobs.rewrite.RewriteBottomUpJob;
+import org.apache.doris.nereids.memo.Group;
+import org.apache.doris.nereids.memo.Memo;
+import org.apache.doris.nereids.parser.NereidsParser;
+import org.apache.doris.nereids.properties.PhysicalProperties;
+import org.apache.doris.nereids.rules.RuleFactory;
+import org.apache.doris.nereids.rules.analysis.BindFunction;
+import org.apache.doris.nereids.rules.analysis.BindRelation;
+import org.apache.doris.nereids.rules.analysis.BindSlotReference;
+import org.apache.doris.nereids.rules.analysis.BindSubQueryAlias;
+import org.apache.doris.nereids.rules.analysis.ProjectToGlobalAggregate;
+import org.apache.doris.nereids.trees.expressions.Expression;
+import org.apache.doris.nereids.trees.plans.Plan;
+import org.apache.doris.nereids.trees.plans.logical.LogicalPlan;
+import org.apache.doris.qe.ConnectContext;
+import org.apache.doris.utframe.TestWithFeService;
+
+import com.google.common.collect.Lists;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+import java.util.List;
+
+public class AnalyzeSubQueryTest extends TestWithFeService {
+    private final NereidsParser parser = new NereidsParser();
+
+    private final List<String> testSql = Lists.newArrayList(
+            "SELECT * FROM T1",
+            "SELECT * FROM T1 ORDER BY ID",
+            "SELECT * FROM T1 JOIN T2 ON T1.ID = T2.ID",
+            "SELECT * FROM T1 T",
+            "SELECT T.ID FROM T1 T",
+            "SELECT * FROM (SELECT * FROM T1 T) T2",
+            "SELECT T1.ID ID FROM T1",
+            "SELECT T.ID FROM T1 T",
+            "SELECT A.ID, B.SCORE FROM T1 A, T2 B WHERE A.ID = B.ID GROUP BY 
A.ID ORDER BY A.ID",
+            "SELECT X.ID FROM (SELECT * FROM T1 A JOIN (SELECT ID ID1 FROM T1) 
AS B ON A.ID = B.ID1) X WHERE X.SCORE < 20",
+            "SELECT X.ID + X.SCORE FROM (SELECT * FROM T1 A JOIN (SELECT 
SUM(ID + 1) ID1 FROM T1 T GROUP BY ID) AS B ON A.ID = B.ID1 ORDER BY A.ID DESC) 
X WHERE X.ID - X.SCORE < 20"
+    );
+
+    @Override
+    protected void runBeforeAll() throws Exception {
+        createDatabase("test");
+        connectContext.setDatabase("default_cluster:test");
+
+        createTables(
+                "CREATE TABLE IF NOT EXISTS T1 (\n"
+                        + "    id bigint,\n"
+                        + "    score bigint\n"
+                        + ")\n"
+                        + "DUPLICATE KEY(id)\n"
+                        + "DISTRIBUTED BY HASH(id) BUCKETS 1\n"
+                        + "PROPERTIES (\n"
+                        + "  \"replication_num\" = \"1\"\n"
+                        + ")\n",
+                "CREATE TABLE IF NOT EXISTS T2 (\n"
+                        + "    id bigint,\n"
+                        + "    score bigint\n"
+                        + ")\n"
+                        + "DUPLICATE KEY(id)\n"
+                        + "DISTRIBUTED BY HASH(id) BUCKETS 1\n"
+                        + "PROPERTIES (\n"
+                        + "  \"replication_num\" = \"1\"\n"
+                        + ")\n"
+        );
+    }
+
+    /**
+     * TODO: check bound plan and expression details.
+     */
+    @Test
+    public void testAnalyzeAllCase() {
+        for (String sql : testSql) {
+            System.out.println("*****\nStart test: " + sql + "\n*****\n");
+            checkAnalyze(sql);
+        }
+    }
+
+    @Test
+    public void testAnalyze() {
+        checkAnalyze(testSql.get(10));
+    }
+
+    @Test
+    public void testParse() {
+        for (String sql : testSql) {
+            System.out.println(parser.parseSingle(sql).treeString());
+        }
+    }
+
+    @Test
+    public void testFinalizeAnalyze() {
+        finalizeAnalyze(testSql.get(10));
+    }
+
+    @Test
+    public void testFinalizeAnalyzeAllCase() {
+        for (String sql : testSql) {
+            System.out.println("*****\nStart test: " + sql + "\n*****\n");
+            finalizeAnalyze(sql);
+        }
+    }
+
+    @Test
+    public void testPlan() throws AnalysisException {
+        System.out.println(new NereidsPlanner(connectContext).plan(
+                parser.parseSingle(testSql.get(10)),
+                new PhysicalProperties(),
+                connectContext
+        ).treeString());
+    }
+
+    @Test
+    public void testPlanAllCase() throws AnalysisException {
+        for (String sql : testSql) {
+            System.out.println("*****\nStart test: " + sql + "\n*****\n");
+            System.out.println(new NereidsPlanner(connectContext).plan(
+                    parser.parseSingle(sql),
+                    new PhysicalProperties(),
+                    connectContext
+            ).treeString());
+        }
+    }
+
+    private void checkAnalyze(String sql) {
+        LogicalPlan analyzed = analyze(sql);
+        System.out.println(analyzed.treeString());
+        Assertions.assertTrue(checkBound(analyzed));
+    }
+
+    private void finalizeAnalyze(String sql) {
+        Memo memo = new Memo(parser.parseSingle(sql));
+        PlannerContext plannerContext = new PlannerContext(memo, 
connectContext);
+        JobContext jobContext = new JobContext(plannerContext, new 
PhysicalProperties(), Double.MAX_VALUE);
+        plannerContext.setCurrentJobContext(jobContext);
+
+        executeRewriteBottomUpJob(plannerContext,
+                new BindFunction(),
+                new BindRelation(),
+                new BindSubQueryAlias(),
+                new BindSlotReference(),
+                new ProjectToGlobalAggregate());
+        System.out.println(memo.copyOut().treeString());
+        new FinalizeAnalyzeJob(plannerContext).execute();
+        System.out.println(memo.copyOut().treeString());
+    }
+
+    private LogicalPlan analyze(String sql) {
+        try {
+            LogicalPlan parsed = parser.parseSingle(sql);
+            System.out.println(parsed.treeString());
+            return analyze(parsed, connectContext);
+        } catch (Throwable t) {
+            throw new IllegalStateException("Analyze failed", t);
+        }
+    }
+
+    private LogicalPlan analyze(LogicalPlan inputPlan, ConnectContext 
connectContext) {
+        Memo memo = new Memo(inputPlan);
+
+        PlannerContext plannerContext = new PlannerContext(memo, 
connectContext);
+        JobContext jobContext = new JobContext(plannerContext, new 
PhysicalProperties(), Double.MAX_VALUE);
+        plannerContext.setCurrentJobContext(jobContext);
+
+        executeRewriteBottomUpJob(plannerContext,
+                new BindFunction(),
+                new BindRelation(),
+                new BindSubQueryAlias(),
+                new BindSlotReference(),
+                new ProjectToGlobalAggregate());
+        return (LogicalPlan) memo.copyOut();
+    }
+
+    private void executeRewriteBottomUpJob(PlannerContext plannerContext, 
RuleFactory... ruleFactory) {
+        Group rootGroup = plannerContext.getMemo().getRoot();
+        RewriteBottomUpJob job = new RewriteBottomUpJob(rootGroup,
+                plannerContext.getCurrentJobContext(), 
Lists.newArrayList(ruleFactory));
+        plannerContext.pushJob(job);
+        plannerContext.getJobScheduler().executeJobPool(plannerContext);
+    }
+
+    /**
+     * PlanNode and its expressions are all bound.
+     */
+    private boolean checkBound(LogicalPlan plan) {
+        if (plan instanceof Unbound) {
+            return false;
+        }
+
+        List<Plan> children = plan.children();
+        for (Plan child : children) {
+            if (!checkBound((LogicalPlan) child)) {
+                return false;
+            }
+        }
+
+        List<Expression> expressions = plan.getExpressions();
+        return expressions.stream().allMatch(this::checkExpressionBound);
+    }
+
+    private boolean checkExpressionBound(Expression expr) {
+        if (expr instanceof Unbound) {
+            return false;
+        }
+
+        List<Expression> children = expr.children();
+        for (Expression child : children) {
+            if (!checkExpressionBound(child)) {
+                return false;
+            }
+        }
+        return true;
+    }
+}
+
+/*

Review Comment:
   remove these



##########
fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisLexer.tokens:
##########
@@ -0,0 +1,620 @@
+SEMICOLON=1

Review Comment:
   this file should not add to source



##########
fe/fe-core/src/main/java/org/apache/doris/catalog/PrimitiveType.java:
##########
@@ -92,6 +92,7 @@ public enum PrimitiveType {
     }
 
     private static ImmutableSetMultimap<PrimitiveType, PrimitiveType> 
implicitCastMap;
+

Review Comment:
   revert these changes



##########
fe/fe-core/src/main/java/org/apache/doris/catalog/View.java:
##########
@@ -45,7 +45,7 @@
  * Table metadata representing a catalog view or a local view from a WITH 
clause.
  * Most methods inherited from Table are not supposed to be called on this 
class because
  * views are substituted with their underlying definition during analysis of a 
statement.
- *
+ * <p>

Review Comment:
   revert these changes



##########
fe/fe-core/src/main/java/org/apache/doris/mysql/MysqlCommand.java:
##########
@@ -51,6 +51,7 @@ public enum MysqlCommand {
     COM_RESET_CONNECTION("COM_RESET_CONNECTION", 31);
 
     private static Map<Integer, MysqlCommand> codeMap = Maps.newHashMap();
+

Review Comment:
   revert these changes



##########
fe/fe-core/src/main/java/org/apache/doris/analysis/SchemaTableType.java:
##########
@@ -68,6 +68,7 @@ public enum SchemaTableType {
     SCH_INVALID("NULL", "NULL", TSchemaTableType.SCH_INVALID);
     private static final String dbName = "INFORMATION_SCHEMA";
     private static SelectList fullSelectLists;
+

Review Comment:
   revert these changes



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/NereidsPlanner.java:
##########
@@ -124,6 +125,10 @@ private void analyze() {
         new AnalyzeRulesJob(plannerContext).execute();
     }
 
+    private void finalizeAnalyze() {
+

Review Comment:
   still empty?



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