improved clickhouse support, fix #3977

This commit is contained in:
高铁
2020-10-22 19:15:47 +08:00
parent e71c2a6e93
commit 8c5c56c313
9 changed files with 141 additions and 10 deletions
@@ -37,6 +37,9 @@ public class SQLInSubQueryExpr extends SQLExprImpl implements Serializable, SQLR
// for ads query hint
public SQLCommentHint hint;
// for clickhouse
private boolean global;
public SQLInSubQueryExpr(){
}
@@ -53,6 +56,7 @@ public class SQLInSubQueryExpr extends SQLExprImpl implements Serializable, SQLR
public SQLInSubQueryExpr clone() {
SQLInSubQueryExpr x = new SQLInSubQueryExpr();
x.not = not;
x.global = global;
if (expr != null) {
x.setExpr(expr.clone());
}
@@ -118,6 +122,7 @@ public class SQLInSubQueryExpr extends SQLExprImpl implements Serializable, SQLR
int result = 1;
result = prime * result + ((expr == null) ? 0 : expr.hashCode());
result = prime * result + (not ? 1231 : 1237);
result = prime * result + (global ? 1231 : 1237);
result = prime * result + ((subQuery == null) ? 0 : subQuery.hashCode());
return result;
}
@@ -144,6 +149,9 @@ public class SQLInSubQueryExpr extends SQLExprImpl implements Serializable, SQLR
if (not != other.not) {
return false;
}
if (global != other.global) {
return false;
}
if (subQuery == null) {
if (other.subQuery != null) {
return false;
@@ -174,4 +182,12 @@ public class SQLInSubQueryExpr extends SQLExprImpl implements Serializable, SQLR
public void setHint(SQLCommentHint hint) {
this.hint = hint;
}
public boolean isGlobal() {
return global;
}
public void setGlobal(boolean global) {
this.global = global;
}
}
@@ -27,6 +27,7 @@ public class ClickhouseLexer extends Lexer {
map.put("LIMIT", Token.LIMIT);
map.put("SHOW", Token.SHOW);
map.put("ALL", Token.ALL);
map.put("GLOBAL", Token.GLOBAL);
DEFAULT_KEYWORDS = new Keywords(map);
}
@@ -1022,6 +1022,7 @@ public class SQLExprParser extends SQLParser {
sqlExpr = new SQLBinaryExpr(strVal);
break;
}
case GLOBAL:
case CONTAINS:
sqlExpr = inRest(null);
break;
@@ -2580,6 +2581,14 @@ public class SQLExprParser extends SQLParser {
}
public final SQLExpr inRest(SQLExpr expr) {
boolean global = false;
// for clickhouse
if (lexer.token == Token.GLOBAL) {
global = true;
lexer.nextToken();
}
if (lexer.token == Token.IN) {
lexer.nextTokenLParen();
@@ -2675,6 +2684,11 @@ public class SQLExprParser extends SQLParser {
inSubQueryExpr.setSubQuery(((SQLQueryExpr) targetExpr).getSubQuery());
inSubQueryExpr.setHint(inListExpr.getHint());
if (global) {
inSubQueryExpr.setGlobal(true);
}
expr = inSubQueryExpr;
}
}
@@ -3261,6 +3275,7 @@ public class SQLExprParser extends SQLParser {
break;
case IN:
case CONTAINS:
case GLOBAL:
expr = inRest(expr);
break;
case EQEQ:
@@ -66,12 +66,13 @@ public enum Token {
EXPLAIN("EXPLAIN"),
FOR("FOR"),
IF("IF"),
ALL("ALL"),
UNION("UNION"),
IF("IF"),
GLOBAL("GLOBAL"),
ALL("ALL"),
UNION("UNION"),
EXCEPT("EXCEPT"),
INTERSECT("INTERSECT"),
MINUS("MINUS"),
@@ -4239,7 +4239,11 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Paramet
if (x.isNot()) {
print0(ucase ? " NOT IN (" : " not in (");
} else {
print0(ucase ? " IN (" : " in (");
if (x.isGlobal()) {
print0(ucase ? " GLOBAL IN (" : " global in (");
} else {
print0(ucase ? " IN (" : " in (");
}
}
this.indentCount++;
@@ -121,7 +121,7 @@ public interface JdbcConstants {
String ELASTIC_SEARCH_DRIVER = "com.alibaba.xdriver.elastic.jdbc.ElasticDriver";
String CLICKHOUSE = "clickhouse";
DbType CLICKHOUSE = DbType.clickhouse;
String CLICKHOUSE_DRIVER = "ru.yandex.clickhouse.ClickHouseDriver";
String KDB = "kdb";