This is an automated email from the ASF dual-hosted git repository.

morrysnow pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/master by this push:
     new 330ed9a84c [fix](Nereids) toSql is not work well in non-query 
statement (#15752)
330ed9a84c is described below

commit 330ed9a84c669568c51549e18e45d570c0a15461
Author: morrySnow <101034200+morrys...@users.noreply.github.com>
AuthorDate: Wed Jan 11 18:56:55 2023 +0800

    [fix](Nereids) toSql is not work well in non-query statement (#15752)
---
 .../src/main/java/org/apache/doris/analysis/SlotRef.java     |  2 ++
 fe/fe-core/src/main/java/org/apache/doris/qe/QueryState.java | 10 ++++++++++
 .../src/main/java/org/apache/doris/qe/StmtExecutor.java      | 12 +++++++++++-
 3 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/SlotRef.java 
b/fe/fe-core/src/main/java/org/apache/doris/analysis/SlotRef.java
index 44197b3b5b..53aa8fde90 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/SlotRef.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/SlotRef.java
@@ -227,6 +227,8 @@ public class SlotRef extends Expr {
             return tblName.toSql() + "." + label;
         } else if (label != null) {
             if (ConnectContext.get() != null
+                    && ConnectContext.get().getState().isNereids()
+                    && !ConnectContext.get().getState().isQuery()
                     && ConnectContext.get().getSessionVariable() != null
                     && 
ConnectContext.get().getSessionVariable().isEnableNereidsPlanner()
                     && desc != null) {
diff --git a/fe/fe-core/src/main/java/org/apache/doris/qe/QueryState.java 
b/fe/fe-core/src/main/java/org/apache/doris/qe/QueryState.java
index 3cf2f22779..b075ccc984 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/qe/QueryState.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/qe/QueryState.java
@@ -48,6 +48,7 @@ public class QueryState {
     private int warningRows = 0;
     // make it public for easy to use
     public int serverStatus = 0;
+    public boolean isNereids = false;
 
     public QueryState() {
     }
@@ -61,6 +62,7 @@ public class QueryState {
         isQuery = false;
         affectedRows = 0;
         warningRows = 0;
+        isNereids = false;
     }
 
     public MysqlStateType getStateType() {
@@ -136,6 +138,14 @@ public class QueryState {
         return warningRows;
     }
 
+    public void setNereids(boolean nereids) {
+        isNereids = nereids;
+    }
+
+    public boolean isNereids() {
+        return isNereids;
+    }
+
     public MysqlPacket toResponsePacket() {
         MysqlPacket packet = null;
         switch (stateType) {
diff --git a/fe/fe-core/src/main/java/org/apache/doris/qe/StmtExecutor.java 
b/fe/fe-core/src/main/java/org/apache/doris/qe/StmtExecutor.java
index a6f1660eff..adeacac51f 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/qe/StmtExecutor.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/qe/StmtExecutor.java
@@ -94,6 +94,7 @@ import org.apache.doris.mysql.privilege.PrivPredicate;
 import org.apache.doris.nereids.NereidsPlanner;
 import org.apache.doris.nereids.StatementContext;
 import org.apache.doris.nereids.glue.LogicalPlanAdapter;
+import org.apache.doris.nereids.trees.plans.commands.Command;
 import org.apache.doris.planner.OlapScanNode;
 import org.apache.doris.planner.OriginalPlanner;
 import org.apache.doris.planner.Planner;
@@ -425,10 +426,18 @@ public class StmtExecutor implements ProfileWriter {
         context.setStmtId(STMT_ID_GENERATOR.incrementAndGet());
         context.setQueryId(queryId);
         // set isQuery first otherwise this state will be lost if some error 
occurs
-        if (parsedStmt instanceof QueryStmt || parsedStmt instanceof 
LogicalPlanAdapter) {
+        if (parsedStmt instanceof QueryStmt) {
             context.getState().setIsQuery(true);
         }
 
+        if (parsedStmt instanceof LogicalPlanAdapter) {
+            context.getState().setNereids(true);
+            if (parsedStmt.getExplainOptions() == null
+                    && !(((LogicalPlanAdapter) parsedStmt).getLogicalPlan() 
instanceof Command)) {
+                context.getState().setIsQuery(true);
+            }
+        }
+
         try {
             if (context.isTxnModel() && !(parsedStmt instanceof InsertStmt)
                     && !(parsedStmt instanceof TransactionStmt)) {
@@ -452,6 +461,7 @@ public class StmtExecutor implements ProfileWriter {
                         // fall back to legacy planner
                         LOG.warn("fall back to legacy planner, because: {}", 
e.getMessage(), e);
                         parsedStmt = null;
+                        context.getState().setNereids(false);
                         analyze(context.getSessionVariable().toThrift());
                     }
                 } catch (Exception e) {


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

Reply via email to