You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@doris.apache.org by GitBox <gi...@apache.org> on 2018/11/05 07:36:42 UTC

[GitHub] chenhao7253886 closed pull request #251: Fix InsertStmt reAnalyze bug

chenhao7253886 closed pull request #251: Fix InsertStmt reAnalyze bug
URL: https://github.com/apache/incubator-doris/pull/251
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/fe/src/main/java/org/apache/doris/analysis/InsertStmt.java b/fe/src/main/java/org/apache/doris/analysis/InsertStmt.java
index e11442ba..823c8215 100644
--- a/fe/src/main/java/org/apache/doris/analysis/InsertStmt.java
+++ b/fe/src/main/java/org/apache/doris/analysis/InsertStmt.java
@@ -17,6 +17,7 @@
 
 package org.apache.doris.analysis;
 
+import com.google.common.base.Preconditions;
 import org.apache.doris.catalog.BrokerTable;
 import org.apache.doris.catalog.Catalog;
 import org.apache.doris.catalog.Column;
@@ -38,6 +39,7 @@
 import org.apache.doris.planner.ExportSink;
 import org.apache.doris.planner.OlapTableSink;
 import org.apache.doris.qe.ConnectContext;
+import org.apache.doris.rewrite.ExprRewriter;
 import org.apache.doris.thrift.TUniqueId;
 import org.apache.doris.transaction.TransactionState.LoadJobSourceType;
 
@@ -169,6 +171,18 @@ public QueryStmt getQueryStmt() {
         return queryStmt;
     }
 
+
+    @Override
+    public void rewriteExprs(ExprRewriter rewriter) throws AnalysisException {
+        Preconditions.checkState(isAnalyzed());
+        queryStmt.rewriteExprs(rewriter);
+    }
+
+    @Override
+    public boolean isExplain() {
+        return queryStmt.isExplain();
+    }
+
     public boolean isStreaming() {
         return isStreaming;
     }
diff --git a/fe/src/main/java/org/apache/doris/qe/StmtExecutor.java b/fe/src/main/java/org/apache/doris/qe/StmtExecutor.java
index 7d7f8795..f9463bb9 100644
--- a/fe/src/main/java/org/apache/doris/qe/StmtExecutor.java
+++ b/fe/src/main/java/org/apache/doris/qe/StmtExecutor.java
@@ -395,21 +395,14 @@ private void analyze() throws AnalysisException, UserException,
             lock(dbs);
             try {
                 parsedStmt.analyze(analyzer);
-                // TODO chenhao16, InsertStmt's QueryStmt rewrite
-                StatementBase originStmt = null;
-                if (parsedStmt instanceof InsertStmt) {
-                    originStmt = parsedStmt;
-                    parsedStmt = ((InsertStmt) parsedStmt).getQueryStmt();
-                }
-                if (parsedStmt instanceof QueryStmt) {
-                    QueryStmt queryStmt1 = (QueryStmt)parsedStmt;
-                    boolean isExplain = ((QueryStmt) parsedStmt).isExplain();
+                if (parsedStmt instanceof QueryStmt || parsedStmt instanceof InsertStmt) {
+                    boolean isExplain = parsedStmt.isExplain();
                     // Apply expr and subquery rewrites.
                     boolean reAnalyze = false;
 
                     ExprRewriter rewriter = analyzer.getExprRewriter();
                     rewriter.reset();
-                    queryStmt1.rewriteExprs(rewriter);
+                    parsedStmt.rewriteExprs(rewriter);
                     reAnalyze = rewriter.changed();
                     if (analyzer.containSubquery()) {
                         StmtRewriter.rewrite(analyzer, parsedStmt);
@@ -421,27 +414,22 @@ private void analyze() throws AnalysisException, UserException,
                         // types and column labels to restore them after the rewritten stmt has been
                         // reset() and re-analyzed.
                         List<Type> origResultTypes = Lists.newArrayList();
-                        for (Expr e: queryStmt1.getResultExprs()) {
+                        for (Expr e: parsedStmt.getResultExprs()) {
                             origResultTypes.add(e.getType());
                         }
                         List<String> origColLabels =
-                                Lists.newArrayList(queryStmt1.getColLabels());
+                                Lists.newArrayList(parsedStmt.getColLabels());
 
                         // Re-analyze the stmt with a new analyzer.
                         analyzer = new Analyzer(context.getCatalog(), context);
-                        // TODO chenhao16 , merge Impala
-                        // insert re-analyze
-                        if (originStmt != null) {
-                            originStmt.reset();
-                            originStmt.analyze(analyzer);
-                        } else {
-                            // query re-analyze
-                            parsedStmt.reset();
-                            parsedStmt.analyze(analyzer);
-                        }
+
+                        // query re-analyze
+                        parsedStmt.reset();
+                        parsedStmt.analyze(analyzer);
+
                         // Restore the original result types and column labels.
-                        queryStmt1.castResultExprs(origResultTypes);
-                        queryStmt1.setColLabels(origColLabels);
+                        parsedStmt.castResultExprs(origResultTypes);
+                        parsedStmt.setColLabels(origColLabels);
                         if (LOG.isTraceEnabled()) {
                             LOG.trace("rewrittenStmt: " + parsedStmt.toSql());
                         }
@@ -449,9 +437,6 @@ private void analyze() throws AnalysisException, UserException,
                     }
                 }
 
-                if (originStmt != null && originStmt instanceof InsertStmt) {
-                    parsedStmt = originStmt;
-                }
                 // create plan
                 planner = new Planner();
                 if (parsedStmt instanceof QueryStmt || parsedStmt instanceof InsertStmt) {


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@doris.apache.org
For additional commands, e-mail: dev-help@doris.apache.org