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 2021/08/07 13:34:13 UTC
[incubator-doris] branch master updated: [Enhance][Fold constant]
Support fold constants in `InlineView` by BE (#6393)
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 882242e [Enhance][Fold constant] Support fold constants in `InlineView` by BE (#6393)
882242e is described below
commit 882242ed15905828c29e344b26a39bf5d41760cb
Author: qiye <ji...@gmail.com>
AuthorDate: Sat Aug 7 21:34:02 2021 +0800
[Enhance][Fold constant] Support fold constants in `InlineView` by BE (#6393)
Add support for folding constants in InlineView by BE.
---
.../java/org/apache/doris/analysis/SelectStmt.java | 6 ++++++
.../org/apache/doris/analysis/QueryStmtTest.java | 22 +++++++++++++++++++++-
2 files changed, 27 insertions(+), 1 deletion(-)
diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/SelectStmt.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/SelectStmt.java
index 9219489..146a57a 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/SelectStmt.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/SelectStmt.java
@@ -1359,6 +1359,9 @@ public class SelectStmt extends QueryStmt {
registerExprId(ref.onClause);
exprMap.put(ref.onClause.getId().toString(), ref.onClause);
}
+ if (ref instanceof InlineViewRef) {
+ ((InlineViewRef) ref).getViewStmt().collectExprs(exprMap);
+ }
}
if (whereClause != null) {
@@ -1465,6 +1468,9 @@ public class SelectStmt extends QueryStmt {
if (ref.onClause != null) {
ref.setOnClause(rewrittenExprMap.get(ref.onClause.getId().toString()));
}
+ if (ref instanceof InlineViewRef) {
+ ((InlineViewRef) ref).getViewStmt().putBackExprs(rewrittenExprMap);
+ }
}
if (whereClause != null) {
diff --git a/fe/fe-core/src/test/java/org/apache/doris/analysis/QueryStmtTest.java b/fe/fe-core/src/test/java/org/apache/doris/analysis/QueryStmtTest.java
index e76f24e..77048d6 100644
--- a/fe/fe-core/src/test/java/org/apache/doris/analysis/QueryStmtTest.java
+++ b/fe/fe-core/src/test/java/org/apache/doris/analysis/QueryStmtTest.java
@@ -111,7 +111,7 @@ public class QueryStmtTest {
stmt = (QueryStmt) UtFrameUtils.parseAndAnalyzeStmt(sql, ctx);
exprsMap.clear();
stmt.collectExprs(exprsMap);
- Assert.assertEquals(6, exprsMap.size());
+ Assert.assertEquals(7, exprsMap.size());
sql = "select\n" +
" avg(t1.k4)\n" +
@@ -188,6 +188,13 @@ public class QueryStmtTest {
exprsMap.clear();
stmt.collectExprs(exprsMap);
Assert.assertEquals(4, exprsMap.size());
+
+ // inline view
+ sql = "select a.k1, b.now from (select k1,k2 from db1.baseall)a, (select now() as now)b";
+ stmt = (QueryStmt) UtFrameUtils.parseAndAnalyzeStmt(sql, ctx);
+ exprsMap.clear();
+ stmt.collectExprs(exprsMap);
+ Assert.assertEquals(5, exprsMap.size());
}
@Test
@@ -257,6 +264,19 @@ public class QueryStmtTest {
Assert.assertTrue(stmt.toSql().contains("root''@''%"));
Assert.assertTrue(stmt.toSql().contains("root''@''127.0.0.1"));
+ // inline view
+ sql = "SELECT\n" +
+ " t1.k1, t2.k1\n" +
+ "FROM\n" +
+ " (select USER() k1, CURRENT_USER() k2, SCHEMA() k3) t1,\n" +
+ " (select @@license k1, @@version k2) t2\n";
+ stmt = UtFrameUtils.parseAndAnalyzeStmt(sql, ctx);
+ stmt.foldConstant(new Analyzer(ctx.getCatalog(), ctx).getExprRewriter());
+ // reAnalyze
+ reAnalyze(stmt, ctx);
+ Assert.assertTrue(stmt.toSql().contains("root''@''%"));
+ Assert.assertTrue(stmt.toSql().contains("root''@''127.0.0.1"));
+ Assert.assertTrue(stmt.toSql().contains("Apache License, Version 2.0"));
}
private void reAnalyze(StatementBase stmt, ConnectContext ctx) throws UserException {
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org