use of com.alibaba.druid.stat.TableStat in project druid by alibaba.
the class MySqlAlterTableDropIndex_0 method test_alter_first.
public void test_alter_first() throws Exception {
String sql = "ALTER TABLE `test`.`tb1` DROP INDEX `ix` ;";
MySqlStatementParser parser = new MySqlStatementParser(sql);
SQLStatement stmt = parser.parseStatementList().get(0);
parser.match(Token.EOF);
Assert.assertEquals(//
"ALTER TABLE `test`.`tb1`" + "\n\tDROP INDEX `ix`", SQLUtils.toMySqlString(stmt));
Assert.assertEquals(//
"alter table `test`.`tb1`" + "\n\tdrop index `ix`", SQLUtils.toMySqlString(stmt, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION));
SchemaStatVisitor visitor = new SQLUtils().createSchemaStatVisitor(JdbcConstants.MYSQL);
stmt.accept(visitor);
TableStat tableStat = visitor.getTableStat("test.tb1");
assertNotNull(tableStat);
assertEquals(1, tableStat.getAlterCount());
assertEquals(1, tableStat.getDropIndexCount());
}
use of com.alibaba.druid.stat.TableStat in project druid by alibaba.
the class MySqlAlterTableDropKey method test_alter_first.
public void test_alter_first() throws Exception {
String sql = "alter table t6 drop key v";
MySqlStatementParser parser = new MySqlStatementParser(sql);
SQLStatement stmt = parser.parseStatementList().get(0);
parser.match(Token.EOF);
Assert.assertEquals(//
"ALTER TABLE t6" + "\n\tDROP KEY v", SQLUtils.toMySqlString(stmt));
Assert.assertEquals(//
"alter table t6" + "\n\tdrop key v", SQLUtils.toMySqlString(stmt, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION));
SchemaStatVisitor visitor = new SQLUtils().createSchemaStatVisitor(JdbcConstants.MYSQL);
stmt.accept(visitor);
TableStat tableStat = visitor.getTableStat("t6");
assertNotNull(tableStat);
assertEquals(1, tableStat.getAlterCount());
assertEquals(1, tableStat.getDropIndexCount());
}
use of com.alibaba.druid.stat.TableStat in project druid by alibaba.
the class MySqlAlterTableAddUniqueTest method test_alter_first.
public void test_alter_first() throws Exception {
String sql = "ALTER TABLE icp.wx_msg ADD CONSTRAINT idx_msgId_msgType_event_eventKey UNIQUE (msgId, msgType, event, eventKey)";
MySqlStatementParser parser = new MySqlStatementParser(sql);
SQLStatement stmt = parser.parseStatementList().get(0);
parser.match(Token.EOF);
Assert.assertEquals("ALTER TABLE icp.wx_msg" + "\n\tADD UNIQUE (msgId, msgType, event, eventKey)", SQLUtils.toMySqlString(stmt));
Assert.assertEquals("alter table icp.wx_msg" + "\n\tadd unique (msgId, msgType, event, eventKey)", SQLUtils.toMySqlString(stmt, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION));
SchemaStatVisitor visitor = new SQLUtils().createSchemaStatVisitor(JdbcConstants.MYSQL);
stmt.accept(visitor);
TableStat tableStat = visitor.getTableStat("icp.wx_msg");
assertNotNull(tableStat);
assertEquals(1, tableStat.getAlterCount());
assertEquals(1, tableStat.getCreateIndexCount());
}
use of com.alibaba.druid.stat.TableStat in project druid by alibaba.
the class MySqlDropIndexTest method test_0.
public void test_0() throws Exception {
String sql = "drop index index_name on table_name ";
MySqlStatementParser parser = new MySqlStatementParser(sql);
List<SQLStatement> statementList = parser.parseStatementList();
SQLDropIndexStatement stmt = (SQLDropIndexStatement) statementList.get(0);
// print(statementList);
Assert.assertEquals(1, statementList.size());
MySqlSchemaStatVisitor visitor = new MySqlSchemaStatVisitor();
stmt.accept(visitor);
// System.out.println("Tables : " + visitor.getTables());
// System.out.println("fields : " + visitor.getColumns());
// System.out.println("coditions : " + visitor.getConditions());
// System.out.println("orderBy : " + visitor.getOrderByColumns());
Assert.assertEquals(1, visitor.getTables().size());
Assert.assertEquals(0, visitor.getColumns().size());
Assert.assertEquals(0, visitor.getConditions().size());
Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("table_name")));
TableStat tableStat = visitor.getTables().get(new TableStat.Name("table_name"));
Assert.assertEquals(1, tableStat.getDropIndexCount());
}
use of com.alibaba.druid.stat.TableStat in project druid by alibaba.
the class MySqlSchemaStatVisitor method visit.
@Override
public boolean visit(MySqlReplaceStatement x) {
setMode(x, Mode.Replace);
setAliasMap();
SQLName tableName = x.getTableName();
String ident = null;
if (tableName instanceof SQLIdentifierExpr) {
ident = ((SQLIdentifierExpr) tableName).getName();
} else if (tableName instanceof SQLPropertyExpr) {
SQLPropertyExpr propertyExpr = (SQLPropertyExpr) tableName;
if (propertyExpr.getOwner() instanceof SQLIdentifierExpr) {
ident = propertyExpr.toString();
}
}
if (ident != null) {
setCurrentTable(x, ident);
TableStat stat = getTableStat(ident);
stat.incrementInsertCount();
Map<String, String> aliasMap = getAliasMap();
putAliasMap(aliasMap, ident, ident);
}
accept(x.getColumns());
accept(x.getValuesList());
accept(x.getQuery());
return false;
}
Aggregations