refactor sql parser.

This commit is contained in:
wenshao
2017-08-29 17:10:26 +08:00
parent 2b164c377b
commit 718500cf59
24 changed files with 235 additions and 282 deletions
@@ -1643,7 +1643,7 @@ public class MySqlStatementParser extends SQLStatementParser {
lexer.nextToken();
if (database instanceof SQLIdentifierExpr) {
SQLIdentifierExpr ident = (SQLIdentifierExpr) database;
ident.setName(ident.getName() + "-" + strVal);
database = new SQLIdentifierExpr(ident.getName() + "-" + strVal);
}
}
stmt.setDatabase(database);
@@ -99,7 +99,6 @@ public class MySqlSchemaStatVisitor extends SchemaStatVisitor implements MySqlAS
if (x.getTableSource() instanceof SQLExprTableSource) {
SQLName tableName = (SQLName) ((SQLExprTableSource) x.getTableSource()).getExpr();
String ident = tableName.toString();
setCurrentTable(x, ident);
TableStat stat = this.getTableStat(ident);
stat.incrementDeleteCount();
@@ -146,8 +145,6 @@ public class MySqlSchemaStatVisitor extends SchemaStatVisitor implements MySqlAS
}
if (ident != null) {
setCurrentTable(x, ident);
TableStat stat = getTableStat(ident);
stat.incrementInsertCount();
@@ -318,8 +315,6 @@ public class MySqlSchemaStatVisitor extends SchemaStatVisitor implements MySqlAS
}
if (ident != null) {
setCurrentTable(x, ident);
TableStat stat = getTableStat(ident);
stat.incrementInsertCount();
@@ -88,7 +88,7 @@ public class FromSubqueryResolver extends OracleASTVisitorAdapter {
String ident = identifierExpr.getName();
String mappingIdent = mappings.get(ident);
if (mappingIdent != null) {
identifierExpr.setName(mappingIdent);
x.setExpr(new SQLIdentifierExpr(mappingIdent));
}
}
return false;
@@ -71,7 +71,6 @@ public class OdpsSchemaStatVisitor extends SchemaStatVisitor implements OdpsASTV
if (tableName instanceof SQLName) {
String ident = ((SQLName) tableName).toString();
setCurrentTable(ident);
TableStat stat = getTableStat(ident);
stat.incrementInsertCount();
@@ -29,8 +29,8 @@ public class OracleRangeExpr extends OracleSQLObjectImpl implements SQLExpr {
}
public OracleRangeExpr(SQLExpr lowBound, SQLExpr upBound){
this.lowBound = lowBound;
this.upBound = upBound;
setLowBound(lowBound);
setUpBound(upBound);
}
@Override
@@ -47,6 +47,9 @@ public class OracleRangeExpr extends OracleSQLObjectImpl implements SQLExpr {
}
public void setLowBound(SQLExpr lowBound) {
if (lowBound != null) {
lowBound.setParent(this);
}
this.lowBound = lowBound;
}
@@ -55,6 +58,9 @@ public class OracleRangeExpr extends OracleSQLObjectImpl implements SQLExpr {
}
public void setUpBound(SQLExpr upBound) {
if (upBound != null) {
upBound.setParent(this);
}
this.upBound = upBound;
}
@@ -164,7 +164,6 @@ public class OracleSchemaStatVisitor extends SchemaStatVisitor implements Oracle
x.putAttribute(ATTR_TABLE, table);
}
}
restoreCurrentTable(x);
}
public boolean visit(OracleUpdateStatement x) {
@@ -185,7 +184,6 @@ public class OracleSchemaStatVisitor extends SchemaStatVisitor implements Oracle
if (tableExpr instanceof SQLName) {
String ident = tableExpr.toString();
setCurrentTable(ident);
TableStat stat = getTableStat(ident);
stat.incrementUpdateCount();
@@ -431,7 +429,6 @@ public class OracleSchemaStatVisitor extends SchemaStatVisitor implements Oracle
this.aliasMap.put(x.getAlias(), table);
}
addSubQuery(x.getAlias(), x.getSelect());
this.setCurrentTable(x.getAlias());
}
if (table != null) {
@@ -701,7 +698,6 @@ public class OracleSchemaStatVisitor extends SchemaStatVisitor implements Oracle
if (x.getTableName() instanceof SQLName) {
String ident = ((SQLName) x.getTableName()).toString();
setCurrentTable(x, ident);
TableStat stat = getTableStat(ident);
stat.incrementInsertCount();
@@ -769,14 +765,9 @@ public class OracleSchemaStatVisitor extends SchemaStatVisitor implements Oracle
}
if (parent instanceof OracleMultiInsertStatement) {
SQLSelect subQuery = ((OracleMultiInsertStatement) parent).getSubQuery();
if (subQuery != null) {
String table = (String) subQuery.getAttribute("_table_");
setCurrentTable(x, table);
}
}
x.getWhen().accept(this);
x.getThen().accept(this);
restoreCurrentTable(x);
return false;
}
@@ -935,7 +926,6 @@ public class OracleSchemaStatVisitor extends SchemaStatVisitor implements Oracle
@Override
public void endVisit(SQLAlterTableStatement x) {
restoreCurrentTable(x);
}
@Override
@@ -1004,7 +994,6 @@ public class OracleSchemaStatVisitor extends SchemaStatVisitor implements Oracle
@Override
public void endVisit(OracleCreateIndexStatement x) {
restoreCurrentTable(x);
}
@Override
@@ -112,7 +112,6 @@ public class PGSchemaStatVisitor extends SchemaStatVisitor implements PGASTVisit
setMode(x, Mode.Delete);
String ident = ((SQLIdentifierExpr) x.getTableName()).getName();
setCurrentTable(ident);
TableStat stat = getTableStat(ident, x.getAlias());
stat.incrementDeleteCount();
@@ -143,13 +142,10 @@ public class PGSchemaStatVisitor extends SchemaStatVisitor implements PGASTVisit
x.putAttribute("_original_use_mode", getMode());
setMode(x, Mode.Insert);
String originalTable = getCurrentTable();
SQLName tableName = x.getTableName();
{
String ident = tableName.toString();
setCurrentTable(ident);
x.putAttribute("_old_local_", originalTable);
TableStat stat = getTableStat(ident);
stat.incrementInsertCount();
@@ -204,7 +200,6 @@ public class PGSchemaStatVisitor extends SchemaStatVisitor implements PGASTVisit
}
String ident = x.getTableName().toString();
setCurrentTable(ident);
TableStat stat = getTableStat(ident);
stat.incrementUpdateCount();
@@ -87,7 +87,6 @@ public class SQLServerSchemaStatVisitor extends SchemaStatVisitor implements SQL
setAliasMap();
String ident = x.getTableName().toString();
setCurrentTable(ident);
TableStat stat = getTableStat(ident);
stat.incrementUpdateCount();