This is an automated email from the ASF dual-hosted git repository.
morningman pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-doris.git
The following commit(s) were added to refs/heads/master by this push:
new c2c81d5 [Fix]SlotRef.tosql() is the same as the SQL returned by
different sql
c2c81d5 is described below
commit c2c81d58dc0bdf467cff100c751ef765ceea2792
Author: Mingyu Chen <[email protected]>
AuthorDate: Mon May 18 14:47:48 2020 +0800
[Fix]SlotRef.tosql() is the same as the SQL returned by different sql
Fix: #3555
NOTICE(#3622):
This is a "revert of revert pull request".
This pr is mainly used to synthesize the PRs whose commits were
scattered and submitted due to the wrong merge method into a complete
single commit.
---
.../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: [email protected]
For additional commands, e-mail: [email protected]