improved db2 parser support. for issue #2489

This commit is contained in:
wenshao
2018-04-16 00:03:21 +08:00
parent 3ea9c0c8ba
commit 0acd0c76df
16 changed files with 440 additions and 79 deletions
@@ -0,0 +1,44 @@
package com.alibaba.druid.sql.ast;
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
public class SQLWindow extends SQLObjectImpl {
private SQLName name;
private SQLOver over;
public SQLWindow(SQLName name, SQLOver over) {
this.setName(name);
this.setOver(over);
}
public SQLName getName() {
return name;
}
public void setName(SQLName x) {
if (x != null) {
x.setParent(this);
}
this.name = x;
}
public SQLOver getOver() {
return over;
}
public void setOver(SQLOver x) {
if (x != null) {
x.setParent(this);
}
this.over = x;
}
@Override
protected void accept0(SQLASTVisitor v) {
if (v.visit(this)) {
acceptChild(v, name);
acceptChild(v, over);
}
v.endVisit(this);
}
}
@@ -36,6 +36,7 @@ public class SQLAggregateExpr extends SQLExprImpl implements Serializable, SQLRe
protected final List<SQLExpr> arguments = new ArrayList<SQLExpr>();
protected SQLKeep keep;
protected SQLOver over;
protected SQLName overRef;
protected SQLOrderBy withinGroup;
protected Boolean ignoreNulls = false;
@@ -104,6 +105,17 @@ public class SQLAggregateExpr extends SQLExprImpl implements Serializable, SQLRe
}
this.over = over;
}
public SQLName getOverRef() {
return overRef;
}
public void setOverRef(SQLName x) {
if (x != null) {
x.setParent(this);
}
this.overRef = x;
}
public SQLKeep getKeep() {
return keep;
@@ -139,6 +151,7 @@ public class SQLAggregateExpr extends SQLExprImpl implements Serializable, SQLRe
acceptChild(visitor, this.arguments);
acceptChild(visitor, this.keep);
acceptChild(visitor, this.over);
acceptChild(visitor, this.overRef);
acceptChild(visitor, this.withinGroup);
}
@@ -162,53 +175,35 @@ public class SQLAggregateExpr extends SQLExprImpl implements Serializable, SQLRe
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((arguments == null) ? 0 : arguments.hashCode());
result = prime * result + ((methodName == null) ? 0 : methodName.hashCode());
result = prime * result + ((option == null) ? 0 : option.hashCode());
result = prime * result + ((over == null) ? 0 : over.hashCode());
return result;
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
SQLAggregateExpr that = (SQLAggregateExpr) o;
if (methodNameHashCod64 != that.methodNameHashCod64) return false;
if (methodName != null ? !methodName.equals(that.methodName) : that.methodName != null) return false;
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 (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;
return ignoreNulls != null ? ignoreNulls.equals(that.ignoreNulls) : that.ignoreNulls == null;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
SQLAggregateExpr other = (SQLAggregateExpr) obj;
if (arguments == null) {
if (other.arguments != null) {
return false;
}
} else if (!arguments.equals(other.arguments)) {
return false;
}
if (methodName == null) {
if (other.methodName != null) {
return false;
}
} else if (!methodName.equals(other.methodName)) {
return false;
}
if (over == null) {
if (other.over != null) {
return false;
}
} else if (!over.equals(other.over)) {
return false;
}
if (option != other.option) {
return false;
}
return true;
public int hashCode() {
int result = methodName != null ? methodName.hashCode() : 0;
result = 31 * result + (int) (methodNameHashCod64 ^ (methodNameHashCod64 >>> 32));
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 + (over != null ? over.hashCode() : 0);
result = 31 * result + (overRef != null ? overRef.hashCode() : 0);
result = 31 * result + (withinGroup != null ? withinGroup.hashCode() : 0);
result = 31 * result + (ignoreNulls != null ? ignoreNulls.hashCode() : 0);
return result;
}
public SQLAggregateExpr clone() {
@@ -228,6 +223,10 @@ public class SQLAggregateExpr extends SQLExprImpl implements Serializable, SQLRe
x.setOver(over.clone());
}
if (overRef != null) {
x.setOverRef(overRef.clone());
}
if (withinGroup != null) {
x.setWithinGroup(withinGroup.clone());
}
@@ -264,6 +263,7 @@ public class SQLAggregateExpr extends SQLExprImpl implements Serializable, SQLRe
if (target == null) {
return false;
}
for (int i = 0; i < arguments.size(); ++i) {
if (arguments.get(i) == expr) {
arguments.set(i, target);
@@ -271,6 +271,12 @@ public class SQLAggregateExpr extends SQLExprImpl implements Serializable, SQLRe
return true;
}
}
if (overRef == expr) {
setOverRef((SQLName) target);
return true;
}
return false;
}
}
@@ -49,6 +49,7 @@ public class SQLColumnDefinition extends SQLObjectImpl implements SQLTableElemen
protected boolean virtual = false;
protected Identity identity;
protected SQLExpr generatedAlawsAs;
public SQLColumnDefinition(){
@@ -59,11 +60,22 @@ public class SQLColumnDefinition extends SQLObjectImpl implements SQLTableElemen
}
// for sqlserver
public void setIdentity(Identity identity) {
if (identity != null) {
identity.setParent(this);
public void setIdentity(Identity x) {
if (x != null) {
x.setParent(this);
}
this.identity = identity;
this.identity = x;
}
public SQLExpr getGeneratedAlawsAs() {
return generatedAlawsAs;
}
public void setGeneratedAlawsAs(SQLExpr x) {
if (x != null) {
x.setParent(this);
}
this.generatedAlawsAs = x;
}
public Boolean getEnable() {
@@ -41,6 +41,7 @@ public class SQLSelectQueryBlock extends SQLObjectImpl implements SQLSelectQuery
protected SQLOrderBy orderBySiblings;
protected SQLSelectGroupByClause groupBy;
protected List<SQLWindow> windows;
protected SQLOrderBy orderBy;
protected boolean parenthesized = false;
protected boolean forUpdate = false;
@@ -719,4 +720,18 @@ public class SQLSelectQueryBlock extends SQLObjectImpl implements SQLSelectQuery
public void setDbType(String dbType) {
this.dbType = dbType;
}
public List<SQLWindow> getWindows() {
return windows;
}
public void addWindow(SQLWindow x) {
if (x != null) {
x.setParent(this);
}
if (windows == null) {
windows = new ArrayList<SQLWindow>(4);
}
this.windows.add(x);
}
}