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
@@ -25,8 +25,6 @@ public class PGUpdateStatement extends SQLUpdateStatement implements PGSQLStatem
private boolean only = false;
private SQLWithSubqueryClause with;
public PGUpdateStatement(){
super (JdbcConstants.POSTGRESQL);
}
@@ -39,14 +37,6 @@ public class PGUpdateStatement extends SQLUpdateStatement implements PGSQLStatem
this.only = only;
}
public SQLWithSubqueryClause getWith() {
return with;
}
public void setWith(SQLWithSubqueryClause with) {
this.with = with;
}
protected void accept0(SQLASTVisitor visitor) {
accept0((PGASTVisitor) visitor);
}
@@ -54,10 +54,10 @@ public class PGExprParser extends SQLExprParser {
static {
String[] strings = { "AVG", "COUNT", "MAX", "MIN", "STDDEV", "SUM", "ROW_NUMBER" };
AGGREGATE_FUNCTIONS_CODES = FnvHash.fnv_64_lower(strings, true);
AGGREGATE_FUNCTIONS_CODES = FnvHash.fnv1a_64_lower(strings, true);
AGGREGATE_FUNCTIONS = new String[AGGREGATE_FUNCTIONS_CODES.length];
for (String str : strings) {
long hash = FnvHash.fnv_64_lower(str);
long hash = FnvHash.fnv1a_64_lower(str);
int index = Arrays.binarySearch(AGGREGATE_FUNCTIONS_CODES, hash);
AGGREGATE_FUNCTIONS[index] = str;
}
@@ -101,8 +101,6 @@ public class PGSchemaStatVisitor extends SchemaStatVisitor implements PGASTVisit
x.getWith().accept(this);
}
setAliasMap();
SQLTableSource using = x.getUsing();
if (using != null) {
using.accept(this);
@@ -111,9 +109,7 @@ public class PGSchemaStatVisitor extends SchemaStatVisitor implements PGASTVisit
x.putAttribute("_original_use_mode", getMode());
setMode(x, Mode.Delete);
String ident = ((SQLIdentifierExpr) x.getTableName()).getName();
TableStat stat = getTableStat(ident, x.getAlias());
TableStat stat = getTableStat(x.getTableName());
stat.incrementDeleteCount();
accept(x.getWhere());
@@ -133,8 +129,6 @@ public class PGSchemaStatVisitor extends SchemaStatVisitor implements PGASTVisit
repository.resolve(x);
}
setAliasMap();
if (x.getWith() != null) {
x.getWith().accept(this);
}
@@ -149,14 +143,6 @@ public class PGSchemaStatVisitor extends SchemaStatVisitor implements PGASTVisit
TableStat stat = getTableStat(ident);
stat.incrementInsertCount();
Map<String, String> aliasMap = getAliasMap();
if (aliasMap != null) {
if (x.getAlias() != null) {
aliasMap.put(x.getAlias(), ident);
}
aliasMap.put(ident, ident);
}
}
accept(x.getColumns());
@@ -191,10 +177,6 @@ public class PGSchemaStatVisitor extends SchemaStatVisitor implements PGASTVisit
repository.resolve(x);
}
Map<String, String> oldAliasMap = getAliasMap();
setAliasMap();
if (x.getWith() != null) {
x.getWith().accept(this);
}
@@ -206,14 +188,9 @@ public class PGSchemaStatVisitor extends SchemaStatVisitor implements PGASTVisit
accept(x.getFrom());
Map<String, String> aliasMap = getAliasMap();
aliasMap.put(ident, ident);
accept(x.getItems());
accept(x.getWhere());
setAliasMap(oldAliasMap);
return false;
}