You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by mo...@apache.org on 2020/05/18 05:25:51 UTC

[incubator-doris] branch revert-3610-revert-3577-SlotRef_toSql created (now 6f4754f)

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

morningman pushed a change to branch revert-3610-revert-3577-SlotRef_toSql
in repository https://gitbox.apache.org/repos/asf/incubator-doris.git.


      at 6f4754f  Revert "Revert "[Fix]SlotRef.tosql() is the same as the SQL returned by different sql" (#3610)"

This branch includes the following new commits:

     new 6f4754f  Revert "Revert "[Fix]SlotRef.tosql() is the same as the SQL returned by different sql" (#3610)"

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



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


[incubator-doris] 01/01: Revert "Revert "[Fix]SlotRef.tosql() is the same as the SQL returned by different sql" (#3610)"

Posted by mo...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

morningman pushed a commit to branch revert-3610-revert-3577-SlotRef_toSql
in repository https://gitbox.apache.org/repos/asf/incubator-doris.git

commit 6f4754fbfb08089b8b80a6218257ee0231de8310
Author: Mingyu Chen <mo...@gmail.com>
AuthorDate: Mon May 18 13:25:41 2020 +0800

    Revert "Revert "[Fix]SlotRef.tosql() is the same as the SQL returned by different sql" (#3610)"
    
    This reverts commit 539efb35328c09da22567dbc7ca0df3df9333000.
---
 .../java/org/apache/doris/analysis/SlotRef.java    |  9 +++++
 .../apache/doris/analysis/StmtRewriterTest.java    | 39 ++++++++++++++++------
 2 files changed, 38 insertions(+), 10 deletions(-)

diff --git a/fe/src/main/java/org/apache/doris/analysis/SlotRef.java b/fe/src/main/java/org/apache/doris/analysis/SlotRef.java
index 8f99bb0..572be39 100644
--- a/fe/src/main/java/org/apache/doris/analysis/SlotRef.java
+++ b/fe/src/main/java/org/apache/doris/analysis/SlotRef.java
@@ -162,6 +162,15 @@ public class SlotRef extends Expr {
             return tblName.toSql() + "." + label + sb.toString();
         } else if (label != null) {
             return label + sb.toString();
+        } else if (desc.getSourceExprs() != null) {
+            if (desc.getId().asInt() != 1) {
+                sb.append("<slot " + Integer.toString(desc.getId().asInt()) + ">");
+            }
+            for (Expr expr : desc.getSourceExprs()) {
+                sb.append(" ");
+                sb.append(expr.toSql());
+            }
+            return sb.toString();
         } else {
             return "<slot " + Integer.toString(desc.getId().asInt()) + ">" + sb.toString();
         }
diff --git a/fe/src/test/java/org/apache/doris/analysis/StmtRewriterTest.java b/fe/src/test/java/org/apache/doris/analysis/StmtRewriterTest.java
index 77e1d4b..039a190 100644
--- a/fe/src/test/java/org/apache/doris/analysis/StmtRewriterTest.java
+++ b/fe/src/test/java/org/apache/doris/analysis/StmtRewriterTest.java
@@ -21,6 +21,8 @@ import org.apache.doris.common.FeConstants;
 import org.apache.doris.utframe.DorisAssert;
 import org.apache.doris.utframe.UtFrameUtils;
 
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
 import org.junit.AfterClass;
 import org.junit.BeforeClass;
 import org.junit.Test;
@@ -28,6 +30,7 @@ import org.junit.Test;
 import java.util.UUID;
 
 public class StmtRewriterTest {
+    private static final Logger LOG = LogManager.getLogger(StmtRewriterTest.class);
 
     private static String baseDir = "fe";
     private static String runningDir = baseDir + "/mocked/StmtRewriterTest/"
@@ -149,7 +152,9 @@ public class StmtRewriterTest {
         String subquery = "select avg(salary) from " + TABLE_NAME;
         String query = "select empid, sum(salary) from " + TABLE_NAME + " group by empid having sum(salary) > (" +
                 subquery + ");";
-        dorisAssert.query(query).explainContains("CROSS JOIN", "predicates: <slot 3> > <slot 8>");
+        LOG.info("EXPLAIN:{}", dorisAssert.query(query).explainQuery());
+        dorisAssert.query(query).explainContains("CROSS JOIN",
+                "predicates: <slot 3> sum(`salary`) > <slot 8> avg(`salary`)");
     }
 
     /**
@@ -258,8 +263,10 @@ public class StmtRewriterTest {
         String subquery = "select avg(salary) from " + TABLE_NAME;
         String query = "select empid a, sum(salary) from " + TABLE_NAME + " group by empid having sum(salary) > (" +
                 subquery + ") order by a;";
-        dorisAssert.query(query).explainContains("CROSS JOIN", "predicates: <slot 3> > <slot 8>",
-                "order by: <slot 10> ASC");
+        LOG.info("EXPLAIN:{}", dorisAssert.query(query).explainQuery());
+        dorisAssert.query(query).explainContains("CROSS JOIN",
+                "predicates: <slot 3> sum(`salary`) > <slot 8> avg(`salary`)",
+                "order by: <slot 10> `$a$1`.`$c$1` ASC");
     }
 
     /**
@@ -368,9 +375,12 @@ public class StmtRewriterTest {
         String subquery = "select avg(salary) from " + TABLE_NAME;
         String query = "select empid a from " + TABLE_NAME + " group by empid having sum(salary) > (" +
                 subquery + ") order by sum(salary);";
+        LOG.info("EXPLAIN:{}", dorisAssert.query(query).explainQuery());
         dorisAssert.query(query).explainContains("group by: `empid`",
-                "CROSS JOIN", "predicates: <slot 3> > <slot 8>",
-                "order by: <slot 10> ASC", "OUTPUT EXPRS:<slot 11>");
+                "CROSS JOIN",
+                "predicates: <slot 3> sum(`salary`) > <slot 8> avg(`salary`)",
+                "order by: <slot 10> `$a$1`.`$c$2` ASC",
+                "OUTPUT EXPRS:<slot 11> `$a$1`.`$c$1`");
     }
 
     /**
@@ -480,9 +490,12 @@ public class StmtRewriterTest {
         String subquery = "select avg(salary) from " + TABLE_NAME;
         String query = "select empid a, sum(salary) b from " + TABLE_NAME + " group by a having b > (" +
                 subquery + ") order by b;";
+        LOG.info("EXPLAIN:{}", dorisAssert.query(query).explainQuery());
         dorisAssert.query(query).explainContains("group by: `empid`",
-                "CROSS JOIN", "predicates: <slot 3> > <slot 8>",
-                "order by: <slot 10> ASC", "OUTPUT EXPRS:<slot 11> | <slot 10>");
+                "CROSS JOIN",
+                "predicates: <slot 3> sum(`salary`) > <slot 8> avg(`salary`)",
+                "order by: <slot 10> `$a$1`.`$c$2` ASC",
+                "OUTPUT EXPRS:<slot 11> `$a$1`.`$c$1` | <slot 10> `$a$1`.`$c$2`");
     }
 
     /**
@@ -591,9 +604,12 @@ public class StmtRewriterTest {
         String subquery = "select avg(salary) from " + TABLE_NAME;
         String query = "select empid a, sum(salary) b from " + TABLE_NAME + " group by a having b > (" +
                 subquery + ") order by b limit 100;";
+        LOG.info("EXPLAIN:{}", dorisAssert.query(query).explainQuery());
         dorisAssert.query(query).explainContains("group by: `empid`",
-                "CROSS JOIN", "predicates: <slot 3> > <slot 8>",
-                "order by: <slot 10> ASC", "OUTPUT EXPRS:<slot 11> | <slot 10>", "limit: 100");
+                "CROSS JOIN",
+                "predicates: <slot 3> sum(`salary`) > <slot 8> avg(`salary`)",
+                "order by: <slot 10> `$a$1`.`$c$2` ASC",
+                "OUTPUT EXPRS:<slot 11> `$a$1`.`$c$1` | <slot 10> `$a$1`.`$c$2`");
     }
 
     /**
@@ -604,8 +620,11 @@ public class StmtRewriterTest {
         String subquery = "select avg(salary) from " + TABLE_NAME + " where empid between 1 and 2";
         String query = "select empid a, sum(salary) b from " + TABLE_NAME + " group by a having b > (" +
                 subquery + ");";
+        LOG.info("EXPLAIN:{}", dorisAssert.query(query).explainQuery());
         dorisAssert.query(query).explainContains(
-                "CROSS JOIN", "predicates: <slot 3> > <slot 9>", "`empid` >= 1, `empid` <= 2");
+                "CROSS JOIN",
+                "predicates: <slot 3> sum(`salary`) > <slot 9> avg(`salary`)",
+                "PREDICATES: `empid` >= 1, `empid` <= 2");
     }
 
     @AfterClass


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