use of com.alibaba.druid.sql.visitor.SchemaStatVisitor 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.sql.visitor.SchemaStatVisitor 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.sql.visitor.SchemaStatVisitor in project druid by alibaba.
the class OdpsMultiInsertTest method exec_test.
public void exec_test(String resource) throws Exception {
// System.out.println(resource);
InputStream is = null;
is = Thread.currentThread().getContextClassLoader().getResourceAsStream(resource);
Reader reader = new InputStreamReader(is, "UTF-8");
String input = Utils.read(reader);
JdbcUtils.close(reader);
String[] items = input.split("---------------------------");
String sql = items[0].trim();
String expect = items[1].trim();
OdpsStatementParser parser = new OdpsStatementParser(sql);
List<SQLStatement> statementList = parser.parseStatementList();
SQLStatement stmt = statementList.get(0);
Assert.assertEquals(1, statementList.size());
SchemaStatVisitor visitor = new OdpsSchemaStatVisitor();
stmt.accept(visitor);
// System.out.println(sql);
// System.out.println("Tables : " + visitor.getTables());
// System.out.println("fields : " + visitor.getColumns());
//
// System.out.println();
// System.out.println("---------------------------");
// System.out.println(SQLUtils.toOdpsString(stmt));
}
use of com.alibaba.druid.sql.visitor.SchemaStatVisitor in project druid by alibaba.
the class OdpsResourceTest method exec_test.
public void exec_test(String resource) throws Exception {
// System.out.println(resource);
InputStream is = null;
is = Thread.currentThread().getContextClassLoader().getResourceAsStream(resource);
Reader reader = new InputStreamReader(is, "UTF-8");
String input = Utils.read(reader);
JdbcUtils.close(reader);
String[] items = input.split("---------------------------");
String sql = items[0].trim();
String expect = null;
if (items.length > 1) {
expect = items[1].trim();
}
OdpsStatementParser parser = new OdpsStatementParser(sql);
List<SQLStatement> statementList = parser.parseStatementList();
SQLStatement stmt = statementList.get(0);
Assert.assertEquals(1, statementList.size());
SchemaStatVisitor visitor = new OdpsSchemaStatVisitor();
stmt.accept(visitor);
// System.out.println(sql);
// System.out.println("Tables : " + visitor.getTables());
// System.out.println("fields : " + visitor.getColumns());
//
// System.out.println();
// System.out.println("---------------------------");
// System.out.println(SQLUtils.toOdpsString(stmt));
}
use of com.alibaba.druid.sql.visitor.SchemaStatVisitor in project druid by alibaba.
the class OdpsSelectTest10 method test_select.
public void test_select() throws Exception {
String sql = "select /* + mapjoin(a) */ " + " a.name, b.fals" + //
" from abc a join abc1 b on a.name = b.fals;";
Assert.assertEquals("SELECT /*+ mapjoin(a) */ a.name" + "\n\t, b.fals" + "\nFROM abc a" + "\nJOIN abc1 b" + "\nON a.name = b.fals;", SQLUtils.formatOdps(sql));
Assert.assertEquals("select /*+ mapjoin(a) */ a.name" + "\n\t, b.fals" + "\nfrom abc a" + "\njoin abc1 b" + "\non a.name = b.fals;", SQLUtils.formatOdps(sql, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION));
List<SQLStatement> statementList = SQLUtils.parseStatements(sql, JdbcConstants.ODPS);
SQLStatement stmt = statementList.get(0);
Assert.assertEquals(1, statementList.size());
SchemaStatVisitor visitor = SQLUtils.createSchemaStatVisitor(JdbcConstants.ODPS);
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(2, visitor.getTables().size());
Assert.assertEquals(2, visitor.getColumns().size());
Assert.assertEquals(2, visitor.getConditions().size());
Assert.assertTrue(visitor.getColumns().contains(new Column("abc", "name")));
}
Aggregations