use of com.alibaba.cobar.parser.ast.stmt.ddl.DDLStatement in project cobar by alibaba.
the class MySQLDDLParserTest method testDDLStmt.
public void testDDLStmt() throws Exception {
String sql = "alTer ignore table tb_name";
MySQLLexer lexer = new MySQLLexer(sql);
MySQLDDLParser parser = new MySQLDDLParser(lexer, new MySQLExprParser(lexer));
DDLStatement dst = parser.ddlStmt();
sql = "alTeR table tb_name";
lexer = new MySQLLexer(sql);
parser = new MySQLDDLParser(lexer, new MySQLExprParser(lexer));
dst = parser.ddlStmt();
sql = "crEate temporary tabLe if not exists tb_name";
lexer = new MySQLLexer(sql);
parser = new MySQLDDLParser(lexer, new MySQLExprParser(lexer));
dst = parser.ddlStmt();
sql = "crEate tabLe if not exists tb_name";
lexer = new MySQLLexer(sql);
parser = new MySQLDDLParser(lexer, new MySQLExprParser(lexer));
dst = parser.ddlStmt();
sql = "crEate temporary tabLe tb_name";
lexer = new MySQLLexer(sql);
parser = new MySQLDDLParser(lexer, new MySQLExprParser(lexer));
dst = parser.ddlStmt();
sql = "crEate unique index index_name on tb(col(id)) desc";
lexer = new MySQLLexer(sql);
parser = new MySQLDDLParser(lexer, new MySQLExprParser(lexer));
dst = parser.ddlStmt();
sql = "crEate fulltext index index_name on tb(col(id))";
lexer = new MySQLLexer(sql);
parser = new MySQLDDLParser(lexer, new MySQLExprParser(lexer));
dst = parser.ddlStmt();
sql = "crEate spatial index index_name on tb(col(id))";
lexer = new MySQLLexer(sql);
parser = new MySQLDDLParser(lexer, new MySQLExprParser(lexer));
dst = parser.ddlStmt();
sql = "crEate index index_name using hash on tb(col(id))";
lexer = new MySQLLexer(sql);
parser = new MySQLDDLParser(lexer, new MySQLExprParser(lexer));
dst = parser.ddlStmt();
sql = "drop index index_name on tb1";
lexer = new MySQLLexer(sql);
parser = new MySQLDDLParser(lexer, new MySQLExprParser(lexer));
dst = parser.ddlStmt();
String output = output2MySQL(dst, sql);
Assert.assertEquals("DROP INDEX index_name ON tb1", output);
sql = "drop temporary tabLe if exists tb1,tb2,tb3 restrict";
lexer = new MySQLLexer(sql);
parser = new MySQLDDLParser(lexer, new MySQLExprParser(lexer));
dst = parser.ddlStmt();
output = output2MySQL(dst, sql);
Assert.assertEquals("DROP TEMPORARY TABLE IF EXISTS tb1, tb2, tb3 RESTRICT", output);
sql = "drop temporary tabLe if exists tb1,tb2,tb3 cascade";
lexer = new MySQLLexer(sql);
parser = new MySQLDDLParser(lexer, new MySQLExprParser(lexer));
dst = parser.ddlStmt();
output = output2MySQL(dst, sql);
Assert.assertEquals("DROP TEMPORARY TABLE IF EXISTS tb1, tb2, tb3 CASCADE", output);
sql = "drop temporary tabLe if exists tb1 cascade";
lexer = new MySQLLexer(sql);
parser = new MySQLDDLParser(lexer, new MySQLExprParser(lexer));
dst = parser.ddlStmt();
output = output2MySQL(dst, sql);
Assert.assertEquals("DROP TEMPORARY TABLE IF EXISTS tb1 CASCADE", output);
sql = "drop tabLe if exists tb1 cascade";
lexer = new MySQLLexer(sql);
parser = new MySQLDDLParser(lexer, new MySQLExprParser(lexer));
dst = parser.ddlStmt();
output = output2MySQL(dst, sql);
Assert.assertEquals("DROP TABLE IF EXISTS tb1 CASCADE", output);
sql = "drop temporary tabLe tb1 cascade";
lexer = new MySQLLexer(sql);
parser = new MySQLDDLParser(lexer, new MySQLExprParser(lexer));
dst = parser.ddlStmt();
output = output2MySQL(dst, sql);
Assert.assertEquals("DROP TEMPORARY TABLE tb1 CASCADE", output);
sql = "rename table tb1 to ntb1,tb2 to ntb2";
lexer = new MySQLLexer(sql);
parser = new MySQLDDLParser(lexer, new MySQLExprParser(lexer));
dst = parser.ddlStmt();
output = output2MySQL(dst, sql);
Assert.assertEquals("RENAME TABLE tb1 TO ntb1, tb2 TO ntb2", output);
sql = "rename table tb1 to ntb1";
lexer = new MySQLLexer(sql);
parser = new MySQLDDLParser(lexer, new MySQLExprParser(lexer));
dst = parser.ddlStmt();
output = output2MySQL(dst, sql);
Assert.assertEquals("RENAME TABLE tb1 TO ntb1", output);
}
use of com.alibaba.cobar.parser.ast.stmt.ddl.DDLStatement in project cobar by alibaba.
the class MySQLDDLParserTest method testTruncate.
public void testTruncate() throws Exception {
String sql = "Truncate table tb1";
MySQLLexer lexer = new MySQLLexer(sql);
MySQLDDLParser parser = new MySQLDDLParser(lexer, new MySQLExprParser(lexer));
DDLStatement trun = (DDLTruncateStatement) parser.truncate();
parser.match(MySQLToken.EOF);
String output = output2MySQL(trun, sql);
Assert.assertEquals("TRUNCATE TABLE tb1", output);
sql = "Truncate tb1";
lexer = new MySQLLexer(sql);
parser = new MySQLDDLParser(lexer, new MySQLExprParser(lexer));
trun = (DDLTruncateStatement) parser.truncate();
parser.match(MySQLToken.EOF);
output = output2MySQL(trun, sql);
Assert.assertEquals("TRUNCATE TABLE tb1", output);
}
Aggregations