EmmyMiao87 commented on code in PR #10304:
URL: https://github.com/apache/doris/pull/10304#discussion_r905781337


##########
fe/fe-core/src/main/java/org/apache/doris/planner/Planner.java:
##########
@@ -6,430 +6,47 @@
 // "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
+//  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.
-// This file is copied from
-// 
https://github.com/apache/impala/blob/branch-2.9.0/fe/src/main/java/org/apache/impala/Planner.java
-// and modified by Doris
 
 package org.apache.doris.planner;
 
-import org.apache.doris.analysis.Analyzer;
 import org.apache.doris.analysis.ExplainOptions;
-import org.apache.doris.analysis.Expr;
-import org.apache.doris.analysis.InsertStmt;
-import org.apache.doris.analysis.QueryStmt;
-import org.apache.doris.analysis.SelectStmt;
-import org.apache.doris.analysis.SlotDescriptor;
-import org.apache.doris.analysis.SlotId;
 import org.apache.doris.analysis.StatementBase;
-import org.apache.doris.analysis.StorageBackend;
-import org.apache.doris.analysis.TupleDescriptor;
-import org.apache.doris.catalog.PrimitiveType;
-import org.apache.doris.catalog.ScalarType;
 import org.apache.doris.common.UserException;
-import org.apache.doris.common.profile.PlanTreeBuilder;
-import org.apache.doris.common.profile.PlanTreePrinter;
-import org.apache.doris.common.util.VectorizedUtil;
-import org.apache.doris.qe.ConnectContext;
-import org.apache.doris.rewrite.mvrewrite.MVSelectFailedException;
-import org.apache.doris.thrift.TExplainLevel;
-import org.apache.doris.thrift.TQueryOptions;
-import org.apache.doris.thrift.TRuntimeFilterMode;
 
-import com.google.common.base.Preconditions;
 import com.google.common.collect.Lists;
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
 
 import java.util.ArrayList;
-import java.util.Collections;
 import java.util.List;
 
-/**
- * The planner is responsible for turning parse trees into plan fragments that 
can be shipped off to backends for
- * execution.
- */
-public class Planner {
-    private static final Logger LOG = LogManager.getLogger(Planner.class);
-
-    private boolean isBlockQuery = false;
+public abstract class Planner {
 
     protected ArrayList<PlanFragment> fragments = Lists.newArrayList();
 
-    private PlannerContext plannerContext;
-    private SingleNodePlanner singleNodePlanner;
-    private DistributedPlanner distributedPlanner;
+    protected boolean isBlockQuery = false;
 
-    public boolean isBlockQuery() {
-        return isBlockQuery;
-    }
+    public abstract List<ScanNode> getScanNodes();
 
-    public List<PlanFragment> getFragments() {
-        return fragments;
-    }
-
-    public PlannerContext getPlannerContext() {
-        return plannerContext;
-    }
-
-    public List<ScanNode> getScanNodes() {
-        if (singleNodePlanner == null) {
-            return Lists.newArrayList();
-        }
-        return singleNodePlanner.getScanNodes();
-    }
-
-    public void plan(StatementBase queryStmt, Analyzer analyzer, TQueryOptions 
queryOptions)
-            throws UserException {
-        createPlanFragments(queryStmt, analyzer, queryOptions);
-    }
+    public abstract void plan(StatementBase queryStmt,
+            org.apache.doris.thrift.TQueryOptions queryOptions) throws 
UserException;
 
-    /**
-     */
-    private void setResultExprScale(Analyzer analyzer, ArrayList<Expr> 
outputExprs) {
-        for (TupleDescriptor tupleDesc : 
analyzer.getDescTbl().getTupleDescs()) {
-            for (SlotDescriptor slotDesc : tupleDesc.getSlots()) {
-                for (Expr expr : outputExprs) {
-                    List<SlotId> slotList = Lists.newArrayList();
-                    expr.getIds(null, slotList);
-                    if (PrimitiveType.DECIMALV2 != 
expr.getType().getPrimitiveType()) {
-                        continue;
-                    }
-
-                    if (PrimitiveType.DECIMALV2 != 
slotDesc.getType().getPrimitiveType()) {
-                        continue;
-                    }
-
-                    if (slotList.contains(slotDesc.getId()) && null != 
slotDesc.getColumn()) {
-                        int outputScale = slotDesc.getColumn().getScale();
-                        if (outputScale >= 0) {
-                            if (outputScale > expr.getOutputScale()) {
-                                expr.setOutputScale(outputScale);
-                            }
-                        }
-                    }
-                }
-            }
-        }
-    }
-
-    /**
-     * Return combined explain string for all plan fragments.
-     */
     public String getExplainString(List<PlanFragment> fragments, 
ExplainOptions explainOptions) {

Review Comment:
   ```suggestion
       public String getExplainString(ExplainOptions explainOptions) {
           // use fragments directly
       }
   ```



##########
fe/fe-core/src/main/java/org/apache/doris/planner/Planner.java:
##########
@@ -6,430 +6,47 @@
 // "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
+//  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.
-// This file is copied from
-// 
https://github.com/apache/impala/blob/branch-2.9.0/fe/src/main/java/org/apache/impala/Planner.java
-// and modified by Doris
 
 package org.apache.doris.planner;
 
-import org.apache.doris.analysis.Analyzer;
 import org.apache.doris.analysis.ExplainOptions;
-import org.apache.doris.analysis.Expr;
-import org.apache.doris.analysis.InsertStmt;
-import org.apache.doris.analysis.QueryStmt;
-import org.apache.doris.analysis.SelectStmt;
-import org.apache.doris.analysis.SlotDescriptor;
-import org.apache.doris.analysis.SlotId;
 import org.apache.doris.analysis.StatementBase;
-import org.apache.doris.analysis.StorageBackend;
-import org.apache.doris.analysis.TupleDescriptor;
-import org.apache.doris.catalog.PrimitiveType;
-import org.apache.doris.catalog.ScalarType;
 import org.apache.doris.common.UserException;
-import org.apache.doris.common.profile.PlanTreeBuilder;
-import org.apache.doris.common.profile.PlanTreePrinter;
-import org.apache.doris.common.util.VectorizedUtil;
-import org.apache.doris.qe.ConnectContext;
-import org.apache.doris.rewrite.mvrewrite.MVSelectFailedException;
-import org.apache.doris.thrift.TExplainLevel;
-import org.apache.doris.thrift.TQueryOptions;
-import org.apache.doris.thrift.TRuntimeFilterMode;
 
-import com.google.common.base.Preconditions;
 import com.google.common.collect.Lists;
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
 
 import java.util.ArrayList;
-import java.util.Collections;
 import java.util.List;
 
-/**
- * The planner is responsible for turning parse trees into plan fragments that 
can be shipped off to backends for
- * execution.
- */
-public class Planner {
-    private static final Logger LOG = LogManager.getLogger(Planner.class);
-
-    private boolean isBlockQuery = false;
+public abstract class Planner {
 
     protected ArrayList<PlanFragment> fragments = Lists.newArrayList();
 
-    private PlannerContext plannerContext;
-    private SingleNodePlanner singleNodePlanner;
-    private DistributedPlanner distributedPlanner;
+    protected boolean isBlockQuery = false;
 
-    public boolean isBlockQuery() {
-        return isBlockQuery;
-    }
+    public abstract List<ScanNode> getScanNodes();
 
-    public List<PlanFragment> getFragments() {
-        return fragments;
-    }
-
-    public PlannerContext getPlannerContext() {
-        return plannerContext;
-    }
-
-    public List<ScanNode> getScanNodes() {
-        if (singleNodePlanner == null) {
-            return Lists.newArrayList();
-        }
-        return singleNodePlanner.getScanNodes();
-    }
-
-    public void plan(StatementBase queryStmt, Analyzer analyzer, TQueryOptions 
queryOptions)
-            throws UserException {
-        createPlanFragments(queryStmt, analyzer, queryOptions);
-    }
+    public abstract void plan(StatementBase queryStmt,
+            org.apache.doris.thrift.TQueryOptions queryOptions) throws 
UserException;
 
-    /**
-     */
-    private void setResultExprScale(Analyzer analyzer, ArrayList<Expr> 
outputExprs) {
-        for (TupleDescriptor tupleDesc : 
analyzer.getDescTbl().getTupleDescs()) {
-            for (SlotDescriptor slotDesc : tupleDesc.getSlots()) {
-                for (Expr expr : outputExprs) {
-                    List<SlotId> slotList = Lists.newArrayList();
-                    expr.getIds(null, slotList);
-                    if (PrimitiveType.DECIMALV2 != 
expr.getType().getPrimitiveType()) {
-                        continue;
-                    }
-
-                    if (PrimitiveType.DECIMALV2 != 
slotDesc.getType().getPrimitiveType()) {
-                        continue;
-                    }
-
-                    if (slotList.contains(slotDesc.getId()) && null != 
slotDesc.getColumn()) {
-                        int outputScale = slotDesc.getColumn().getScale();
-                        if (outputScale >= 0) {
-                            if (outputScale > expr.getOutputScale()) {
-                                expr.setOutputScale(outputScale);
-                            }
-                        }
-                    }
-                }
-            }
-        }
-    }
-
-    /**
-     * Return combined explain string for all plan fragments.
-     */
     public String getExplainString(List<PlanFragment> fragments, 
ExplainOptions explainOptions) {
-        Preconditions.checkNotNull(explainOptions);
-        if (explainOptions.isGraph()) {
-            // print the plan graph
-            PlanTreeBuilder builder = new PlanTreeBuilder(fragments);
-            try {
-                builder.build();
-            } catch (UserException e) {
-                LOG.warn("Failed to build explain plan tree", e);
-                return e.getMessage();
-            }
-            return PlanTreePrinter.printPlanExplanation(builder.getTreeRoot());
-        }
-
-        // print text plan
-        TExplainLevel explainLevel = explainOptions.isVerbose() ? 
TExplainLevel.VERBOSE : TExplainLevel.NORMAL;
-        StringBuilder str = new StringBuilder();
-        for (int i = 0; i < fragments.size(); ++i) {
-            PlanFragment fragment = fragments.get(i);
-            if (i > 0) {
-                // a blank line between plan fragments
-                str.append("\n");
-            }
-            str.append("PLAN FRAGMENT " + i + "\n");
-            str.append(fragment.getExplainString(explainLevel));
-        }
-        if (explainLevel == TExplainLevel.VERBOSE) {
-            
str.append(plannerContext.getRootAnalyzer().getDescTbl().getExplainString());
-        }
-        return str.toString();
+        return "Not implemented yet";

Review Comment:
   Since the `getExplainString` function only needs to use the fragments 
variable, the `getExplainString` implementation of the old and new optimizers 
can be unified in the abstract class



##########
fe/fe-core/src/main/java/org/apache/doris/planner/Planner.java:
##########
@@ -6,430 +6,47 @@
 // "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
+//  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.
-// This file is copied from
-// 
https://github.com/apache/impala/blob/branch-2.9.0/fe/src/main/java/org/apache/impala/Planner.java
-// and modified by Doris
 
 package org.apache.doris.planner;
 
-import org.apache.doris.analysis.Analyzer;
 import org.apache.doris.analysis.ExplainOptions;
-import org.apache.doris.analysis.Expr;
-import org.apache.doris.analysis.InsertStmt;
-import org.apache.doris.analysis.QueryStmt;
-import org.apache.doris.analysis.SelectStmt;
-import org.apache.doris.analysis.SlotDescriptor;
-import org.apache.doris.analysis.SlotId;
 import org.apache.doris.analysis.StatementBase;
-import org.apache.doris.analysis.StorageBackend;
-import org.apache.doris.analysis.TupleDescriptor;
-import org.apache.doris.catalog.PrimitiveType;
-import org.apache.doris.catalog.ScalarType;
 import org.apache.doris.common.UserException;
-import org.apache.doris.common.profile.PlanTreeBuilder;
-import org.apache.doris.common.profile.PlanTreePrinter;
-import org.apache.doris.common.util.VectorizedUtil;
-import org.apache.doris.qe.ConnectContext;
-import org.apache.doris.rewrite.mvrewrite.MVSelectFailedException;
-import org.apache.doris.thrift.TExplainLevel;
-import org.apache.doris.thrift.TQueryOptions;
-import org.apache.doris.thrift.TRuntimeFilterMode;
 
-import com.google.common.base.Preconditions;
 import com.google.common.collect.Lists;
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
 
 import java.util.ArrayList;
-import java.util.Collections;
 import java.util.List;
 
-/**
- * The planner is responsible for turning parse trees into plan fragments that 
can be shipped off to backends for
- * execution.
- */
-public class Planner {
-    private static final Logger LOG = LogManager.getLogger(Planner.class);
-
-    private boolean isBlockQuery = false;
+public abstract class Planner {
 
     protected ArrayList<PlanFragment> fragments = Lists.newArrayList();
 
-    private PlannerContext plannerContext;
-    private SingleNodePlanner singleNodePlanner;
-    private DistributedPlanner distributedPlanner;
+    protected boolean isBlockQuery = false;
 
-    public boolean isBlockQuery() {
-        return isBlockQuery;
-    }
+    public abstract List<ScanNode> getScanNodes();
 
-    public List<PlanFragment> getFragments() {
-        return fragments;
-    }
-
-    public PlannerContext getPlannerContext() {
-        return plannerContext;
-    }
-
-    public List<ScanNode> getScanNodes() {
-        if (singleNodePlanner == null) {
-            return Lists.newArrayList();
-        }
-        return singleNodePlanner.getScanNodes();
-    }
-
-    public void plan(StatementBase queryStmt, Analyzer analyzer, TQueryOptions 
queryOptions)
-            throws UserException {
-        createPlanFragments(queryStmt, analyzer, queryOptions);
-    }
+    public abstract void plan(StatementBase queryStmt,
+            org.apache.doris.thrift.TQueryOptions queryOptions) throws 
UserException;

Review Comment:
   ```suggestion
               TQueryOptions queryOptions) throws UserException;
   ```



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