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 0e66385 [SQL] Disable some unsupported syntax (#3357)
0e66385 is described below
commit 0e66385235933efc1c09b21d64599eb3873c7f48
Author: yangzhg <[email protected]>
AuthorDate: Fri Apr 24 22:01:35 2020 +0800
[SQL] Disable some unsupported syntax (#3357)
Disable some syntax when subquery is not binary predicate in case when
clause.
---
.../java/org/apache/doris/analysis/CaseExpr.java | 3 +++
.../java/org/apache/doris/analysis/SelectStmt.java | 27 +++++++++++++++++-----
.../org/apache/doris/analysis/SelectStmtTest.java | 19 +++++++++++++++
3 files changed, 43 insertions(+), 6 deletions(-)
diff --git a/fe/src/main/java/org/apache/doris/analysis/CaseExpr.java
b/fe/src/main/java/org/apache/doris/analysis/CaseExpr.java
index 1d0f9f8..602aabd 100644
--- a/fe/src/main/java/org/apache/doris/analysis/CaseExpr.java
+++ b/fe/src/main/java/org/apache/doris/analysis/CaseExpr.java
@@ -101,6 +101,9 @@ public class CaseExpr extends Expr {
CaseExpr expr = (CaseExpr) obj;
return hasCaseExpr == expr.hasCaseExpr && hasElseExpr ==
expr.hasElseExpr;
}
+ public boolean hasCaseExpr() {
+ return hasCaseExpr;
+ }
@Override
public String toSqlImpl() {
diff --git a/fe/src/main/java/org/apache/doris/analysis/SelectStmt.java
b/fe/src/main/java/org/apache/doris/analysis/SelectStmt.java
index d8c3e1f..d70333c 100644
--- a/fe/src/main/java/org/apache/doris/analysis/SelectStmt.java
+++ b/fe/src/main/java/org/apache/doris/analysis/SelectStmt.java
@@ -183,7 +183,7 @@ public class SelectStmt extends QueryStmt {
baseTblSmap.clear();
groupingInfo = null;
}
-
+
@Override
public QueryStmt clone() {
return new SelectStmt(this);
@@ -1004,8 +1004,8 @@ public class SelectStmt extends QueryStmt {
if (selectList.isDistinct()
&& (groupByClause != null
- || TreeNode.contains(resultExprs,
Expr.isAggregatePredicate())
- || (havingClauseAfterAnaylzed != null &&
havingClauseAfterAnaylzed.contains(Expr.isAggregatePredicate())))) {
+ || TreeNode.contains(resultExprs, Expr.isAggregatePredicate())
+ || (havingClauseAfterAnaylzed != null &&
havingClauseAfterAnaylzed.contains(Expr.isAggregatePredicate())))) {
throw new AnalysisException("cannot combine SELECT DISTINCT with
aggregate functions or GROUP BY");
}
@@ -1388,9 +1388,24 @@ public class SelectStmt extends QueryStmt {
if
(!item.getExpr().contains(Predicates.instanceOf(Subquery.class))) {
continue;
}
- item.setExpr(rewriteSubquery(item.getExpr(), analyzer));
- }
+ CaseExpr caseExpr = (CaseExpr) item.getExpr();
+ int childIdx = 0;
+ if (caseExpr.hasCaseExpr()
+ &&
caseExpr.getChild(childIdx++).contains(Predicates.instanceOf(Subquery.class))) {
+ throw new AnalysisException("Only support subquery in binary
predicate in case statement.");
+ }
+ while (childIdx + 2 <= caseExpr.getChildren().size()) {
+ Expr child = caseExpr.getChild(childIdx++);
+ // when
+ if (!(child instanceof BinaryPredicate) &&
child.contains(Predicates.instanceOf(Subquery.class))) {
+ throw new AnalysisException("Only support subquery in
binary predicate in case statement.");
+ }
+ // then
+ childIdx++;
+ }
+ rewriteSubquery(item.getExpr(), analyzer);
+ }
selectList.rewriteExprs(rewriter, analyzer);
}
@@ -1435,7 +1450,7 @@ public class SelectStmt extends QueryStmt {
throw new AnalysisException("Only support select subquery in
case statement.");
}
SelectStmt subquery = (SelectStmt) ((Subquery)
expr).getStatement();
- if (subquery.resultExprs.size() != 1) {
+ if (subquery.resultExprs.size() != 1 ||
!subquery.returnsSingleRow()) {
throw new AnalysisException("Only support select subquery
produce one column in case statement.");
}
subquery.reset();
diff --git a/fe/src/test/java/org/apache/doris/analysis/SelectStmtTest.java
b/fe/src/test/java/org/apache/doris/analysis/SelectStmtTest.java
index f58776c..f2d1917 100644
--- a/fe/src/test/java/org/apache/doris/analysis/SelectStmtTest.java
+++ b/fe/src/test/java/org/apache/doris/analysis/SelectStmtTest.java
@@ -92,6 +92,25 @@ public class SelectStmtTest {
SelectStmt stmt = (SelectStmt) UtFrameUtils.parseAndAnalyzeStmt(sql1,
ctx);
stmt.rewriteExprs(new Analyzer(ctx.getCatalog(),
ctx).getExprRewriter());
Assert.assertTrue(stmt.toSql().contains("`$a$1`.`$c$1` > `k4` THEN
`$a$2`.`$c$2` ELSE `$a$3`.`$c$3`"));
+
+ String sql2 = "select case when k1 in (select k1 from db1.tbl1) then
\"true\" else k1 end a from db1.tbl1";
+ try {
+ SelectStmt stmt2 = (SelectStmt)
UtFrameUtils.parseAndAnalyzeStmt(sql2, ctx);
+ stmt2.rewriteExprs(new Analyzer(ctx.getCatalog(),
ctx).getExprRewriter());
+ Assert.fail("syntax not supported.");
+ } catch (AnalysisException e) {
+ } catch (Exception e) {
+ Assert.fail("must be AnalysisException.");
+ }
+ try {
+ String sql3 = "select case k1 when exists (select 1) then
\"empty\" else \"p_test\" end a from db1.tbl1";
+ SelectStmt stmt3 = (SelectStmt)
UtFrameUtils.parseAndAnalyzeStmt(sql3, ctx);
+ stmt3.rewriteExprs(new Analyzer(ctx.getCatalog(),
ctx).getExprRewriter());
+ Assert.fail("syntax not supported.");
+ } catch (AnalysisException e) {
+ } catch (Exception e) {
+ Assert.fail("must be AnalysisException.");
+ }
}
@Test
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]