mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
Merge remote-tracking branch 'alibaba/master'
This commit is contained in:
@@ -17,6 +17,9 @@ package com.alibaba.druid.sql.ast;
|
||||
|
||||
import com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class SQLExprImpl extends SQLObjectImpl implements SQLExpr {
|
||||
|
||||
public SQLExprImpl(){
|
||||
@@ -27,11 +30,16 @@ public abstract class SQLExprImpl extends SQLObjectImpl implements SQLExpr {
|
||||
|
||||
public abstract int hashCode();
|
||||
|
||||
public abstract SQLExpr clone();
|
||||
public SQLExpr clone() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public SQLDataType computeDataType() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public List<SQLObject> getChildren() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,6 +35,7 @@ public class SQLAggregateExpr extends SQLExprImpl implements Serializable, SQLRe
|
||||
protected SQLAggregateOption option;
|
||||
protected final List<SQLExpr> arguments = new ArrayList<SQLExpr>();
|
||||
protected SQLKeep keep;
|
||||
protected SQLExpr filter;
|
||||
protected SQLOver over;
|
||||
protected SQLName overRef;
|
||||
protected SQLOrderBy withinGroup;
|
||||
@@ -186,6 +187,7 @@ public class SQLAggregateExpr extends SQLExprImpl implements Serializable, SQLRe
|
||||
if (option != that.option) return false;
|
||||
if (arguments != null ? !arguments.equals(that.arguments) : that.arguments != null) return false;
|
||||
if (keep != null ? !keep.equals(that.keep) : that.keep != null) return false;
|
||||
if (filter != null ? !filter.equals(that.filter) : that.filter != null) return false;
|
||||
if (over != null ? !over.equals(that.over) : that.over != null) return false;
|
||||
if (overRef != null ? !overRef.equals(that.overRef) : that.overRef != null) return false;
|
||||
if (withinGroup != null ? !withinGroup.equals(that.withinGroup) : that.withinGroup != null) return false;
|
||||
@@ -199,6 +201,7 @@ public class SQLAggregateExpr extends SQLExprImpl implements Serializable, SQLRe
|
||||
result = 31 * result + (option != null ? option.hashCode() : 0);
|
||||
result = 31 * result + (arguments != null ? arguments.hashCode() : 0);
|
||||
result = 31 * result + (keep != null ? keep.hashCode() : 0);
|
||||
result = 31 * result + (filter != null ? filter.hashCode() : 0);
|
||||
result = 31 * result + (over != null ? over.hashCode() : 0);
|
||||
result = 31 * result + (overRef != null ? overRef.hashCode() : 0);
|
||||
result = 31 * result + (withinGroup != null ? withinGroup.hashCode() : 0);
|
||||
@@ -219,6 +222,10 @@ public class SQLAggregateExpr extends SQLExprImpl implements Serializable, SQLRe
|
||||
x.setKeep(keep.clone());
|
||||
}
|
||||
|
||||
if (filter != null) {
|
||||
x.setFilter(filter.clone());
|
||||
}
|
||||
|
||||
if (over != null) {
|
||||
x.setOver(over.clone());
|
||||
}
|
||||
@@ -236,6 +243,17 @@ public class SQLAggregateExpr extends SQLExprImpl implements Serializable, SQLRe
|
||||
return x;
|
||||
}
|
||||
|
||||
public SQLExpr getFilter() {
|
||||
return filter;
|
||||
}
|
||||
|
||||
public void setFilter(SQLExpr x) {
|
||||
if (x != null) {
|
||||
x.setParent(this);
|
||||
}
|
||||
this.filter = x;
|
||||
}
|
||||
|
||||
public SQLDataType computeDataType() {
|
||||
long hash = methodNameHashCod64();
|
||||
|
||||
@@ -277,6 +295,11 @@ public class SQLAggregateExpr extends SQLExprImpl implements Serializable, SQLRe
|
||||
return true;
|
||||
}
|
||||
|
||||
if (filter == expr) {
|
||||
this.filter = target;
|
||||
target.setParent(this);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -334,4 +334,15 @@ public class PGExprParser extends SQLExprParser {
|
||||
}
|
||||
return alias;
|
||||
}
|
||||
|
||||
protected void filter(SQLAggregateExpr x) {
|
||||
if (lexer.identifierEquals(FnvHash.Constants.FILTER)) {
|
||||
lexer.nextToken();
|
||||
accept(Token.LPAREN);
|
||||
accept(Token.WHERE);
|
||||
SQLExpr filter = this.expr();
|
||||
accept(Token.RPAREN);
|
||||
x.setFilter(filter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1445,14 +1445,21 @@ public class SQLExprParser extends SQLParser {
|
||||
|
||||
accept(Token.RPAREN);
|
||||
|
||||
if (lexer.identifierEquals(FnvHash.Constants.FILTER)) {
|
||||
filter(aggregateExpr);
|
||||
}
|
||||
|
||||
if (lexer.token == Token.OVER) {
|
||||
over(aggregateExpr);
|
||||
|
||||
}
|
||||
|
||||
return aggregateExpr;
|
||||
}
|
||||
|
||||
protected void filter(SQLAggregateExpr aggregateExpr) {
|
||||
|
||||
}
|
||||
|
||||
protected void over(SQLAggregateExpr aggregateExpr) {
|
||||
lexer.nextToken();
|
||||
|
||||
@@ -2263,6 +2270,8 @@ public class SQLExprParser extends SQLParser {
|
||||
}
|
||||
|
||||
expr = new SQLBinaryOpExpr(expr, SQLBinaryOperator.Equality, rightExp, dbType);
|
||||
} else {
|
||||
return expr;
|
||||
}
|
||||
break;
|
||||
case TILDE:
|
||||
@@ -2274,6 +2283,8 @@ public class SQLExprParser extends SQLParser {
|
||||
rightExp = relationalRest(rightExp);
|
||||
|
||||
expr = new SQLBinaryOpExpr(expr, SQLBinaryOperator.POSIX_Regular_Match, rightExp, getDbType());
|
||||
} else {
|
||||
return expr;
|
||||
}
|
||||
break;
|
||||
case TILDE_STAR:
|
||||
@@ -2281,6 +2292,8 @@ public class SQLExprParser extends SQLParser {
|
||||
lexer.nextToken();
|
||||
rightExp = relational();
|
||||
expr = new SQLBinaryOpExpr(expr, SQLBinaryOperator.POSIX_Regular_Match_Insensitive, rightExp, getDbType());
|
||||
} else {
|
||||
return expr;
|
||||
}
|
||||
break;
|
||||
case BANG_TILDE:
|
||||
@@ -2288,6 +2301,8 @@ public class SQLExprParser extends SQLParser {
|
||||
lexer.nextToken();
|
||||
rightExp = relational();
|
||||
expr = new SQLBinaryOpExpr(expr, SQLBinaryOperator.POSIX_Regular_Not_Match, rightExp, getDbType());
|
||||
} else {
|
||||
return expr;
|
||||
}
|
||||
break;
|
||||
case BANG_TILDE_STAR:
|
||||
@@ -2295,6 +2310,8 @@ public class SQLExprParser extends SQLParser {
|
||||
lexer.nextToken();
|
||||
rightExp = relational();
|
||||
expr = new SQLBinaryOpExpr(expr, SQLBinaryOperator.POSIX_Regular_Not_Match_POSIX_Regular_Match_Insensitive, rightExp, getDbType());
|
||||
} else {
|
||||
return expr;
|
||||
}
|
||||
break;
|
||||
case TILDE_EQ:
|
||||
@@ -2302,6 +2319,8 @@ public class SQLExprParser extends SQLParser {
|
||||
lexer.nextToken();
|
||||
rightExp = relational();
|
||||
expr = new SQLBinaryOpExpr(expr, SQLBinaryOperator.SAME_AS, rightExp, getDbType());
|
||||
} else {
|
||||
return expr;
|
||||
}
|
||||
break;
|
||||
case RLIKE:
|
||||
@@ -2331,6 +2350,8 @@ public class SQLExprParser extends SQLParser {
|
||||
rightExp = relational();
|
||||
|
||||
expr = new SQLBinaryOpExpr(expr, SQLBinaryOperator.SIMILAR_TO, rightExp, getDbType());
|
||||
} else {
|
||||
return expr;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
||||
@@ -1562,6 +1562,13 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Paramet
|
||||
over.accept(this);
|
||||
}
|
||||
|
||||
final SQLExpr filter = x.getFilter();
|
||||
if (filter != null) {
|
||||
print0(ucase ? "FILTER (WHERE " : "filter (where ");
|
||||
printExpr(filter);
|
||||
print(')');
|
||||
}
|
||||
|
||||
this.parameterized = parameterized;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -652,5 +652,6 @@ public final class FnvHash {
|
||||
long INCREMENT = fnv1a_64_lower("INCREMENT");
|
||||
|
||||
long OVERWRITE = fnv1a_64_lower("OVERWRITE");
|
||||
long FILTER = fnv1a_64_lower("FILTER");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user