refactor sql parser.

This commit is contained in:
wenshao
2017-08-30 16:51:50 +08:00
parent aa260c9ee3
commit 99fe9112b4
75 changed files with 994 additions and 974 deletions
@@ -133,7 +133,9 @@ public class SQLAggregateExpr extends SQLExprImpl implements Serializable, SQLRe
protected void accept0(SQLASTVisitor visitor) {
if (visitor.visit(this)) {
acceptChild(visitor, this.arguments);
acceptChild(visitor, this.keep);
acceptChild(visitor, this.over);
acceptChild(visitor, this.withinGroup);
}
visitor.endVisit(this);
@@ -22,12 +22,12 @@ import com.alibaba.druid.sql.visitor.SQLASTVisitor;
import com.alibaba.druid.util.FnvHash;
public class SQLIdentifierExpr extends SQLExprImpl implements SQLName {
protected String name;
private transient String lowerName;
private transient long hashCode64;
protected String name;
private String lowerName;
private long hashCode64;
private transient SQLObject resolvedColumn;
private transient SQLObject resolvedOwnerObject;
private SQLObject resolvedColumn;
private SQLObject resolvedOwnerObject;
public SQLIdentifierExpr(){
@@ -125,6 +125,10 @@ public class SQLIdentifierExpr extends SQLExprImpl implements SQLName {
return null;
}
public SQLObject getResolvedColumnObject() {
return resolvedColumn;
}
public void setResolvedColumn(SQLColumnDefinition resolvedColumn) {
this.resolvedColumn = resolvedColumn;
}
@@ -29,7 +29,7 @@ public class SQLPropertyExpr extends SQLExprImpl implements SQLName {
private transient long hashCode64;
private transient SQLColumnDefinition resolvedColumn;
private transient SQLObject resolvedTableSource;
private transient SQLObject resolvedOwnerObject;
public SQLPropertyExpr(String owner, String name){
this(new SQLIdentifierExpr(owner), name);
@@ -119,7 +119,7 @@ public class SQLPropertyExpr extends SQLExprImpl implements SQLName {
} else if (owner == null){
hash = FnvHash.BASIC;
} else {
hash = FnvHash.fnv_64_lower(owner.toString());
hash = FnvHash.fnv1a_64_lower(owner.toString());
hash ^= '.';
hash *= FnvHash.PRIME;
@@ -170,7 +170,7 @@ public class SQLPropertyExpr extends SQLExprImpl implements SQLName {
x.hashCode64 = hashCode64;
x.resolvedColumn = resolvedColumn;
x.resolvedTableSource = resolvedTableSource;
x.resolvedOwnerObject = resolvedOwnerObject;
return x;
}
@@ -214,41 +214,45 @@ public class SQLPropertyExpr extends SQLExprImpl implements SQLName {
}
public SQLTableSource getResolvedTableSource() {
if (resolvedTableSource instanceof SQLTableSource) {
return (SQLTableSource) resolvedTableSource;
if (resolvedOwnerObject instanceof SQLTableSource) {
return (SQLTableSource) resolvedOwnerObject;
}
return null;
}
public void setResolvedTableSource(SQLTableSource resolvedTableSource) {
this.resolvedTableSource = resolvedTableSource;
this.resolvedOwnerObject = resolvedTableSource;
}
public void setResolvedProcedure(SQLCreateProcedureStatement stmt) {
this.resolvedTableSource = stmt;
this.resolvedOwnerObject = stmt;
}
public void setResolvedOwnerObject(SQLObject resolvedOwnerObject) {
this.resolvedTableSource = resolvedOwnerObject;
this.resolvedOwnerObject = resolvedOwnerObject;
}
public SQLCreateProcedureStatement getResolvedProcudure() {
if (this.resolvedTableSource instanceof SQLCreateProcedureStatement) {
return (SQLCreateProcedureStatement) this.resolvedTableSource;
if (this.resolvedOwnerObject instanceof SQLCreateProcedureStatement) {
return (SQLCreateProcedureStatement) this.resolvedOwnerObject;
}
return null;
}
public SQLObject getResolvedOwnerObject() {
return resolvedOwnerObject;
}
public SQLDataType computeDataType() {
if (resolvedColumn != null) {
return resolvedColumn.getDataType();
}
if (resolvedTableSource != null
&& resolvedTableSource instanceof SQLSubqueryTableSource) {
SQLSelect select = ((SQLSubqueryTableSource) resolvedTableSource).getSelect();
if (resolvedOwnerObject != null
&& resolvedOwnerObject instanceof SQLSubqueryTableSource) {
SQLSelect select = ((SQLSubqueryTableSource) resolvedOwnerObject).getSelect();
SQLSelectQueryBlock queryBlock = select.getFirstQueryBlock();
if (queryBlock == null) {
return null;