use of com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor in project druid by alibaba.
the class MySqlCreateTableTest68 method test_one.
@Test
public void test_one() throws Exception {
String sql = "CREATE TABLE t1 (" + "\n\tyear_col INT," + "\n\tsome_data INT" + "\n)" + "\nPARTITION BY RANGE (year_col) (" + " PARTITION p0 VALUES LESS THAN (1991)," + " PARTITION p1 VALUES LESS THAN (1995)," + " PARTITION p2 VALUES LESS THAN (1999)," + " PARTITION p3 VALUES LESS THAN (2002)," + " PARTITION p4 VALUES LESS THAN (2006)," + " PARTITION p5 VALUES LESS THAN MAXVALUE" + ");";
MySqlStatementParser parser = new MySqlStatementParser(sql);
SQLStatement stmt = parser.parseCreateTable();
MySqlSchemaStatVisitor visitor = new MySqlSchemaStatVisitor();
stmt.accept(visitor);
{
String output = SQLUtils.toMySqlString(stmt);
Assert.assertEquals("CREATE TABLE t1 (" + "\n\tyear_col INT, " + "\n\tsome_data INT" + "\n)" + "\nPARTITION BY RANGE (year_col)" + "\n(" + "\n\tPARTITION p0 VALUES LESS THAN (1991)," + "\n\tPARTITION p1 VALUES LESS THAN (1995)," + "\n\tPARTITION p2 VALUES LESS THAN (1999)," + "\n\tPARTITION p3 VALUES LESS THAN (2002)," + "\n\tPARTITION p4 VALUES LESS THAN (2006)," + "\n\tPARTITION p5 VALUES LESS THAN MAXVALUE" + "\n)", output);
}
{
String output = SQLUtils.toMySqlString(stmt, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION);
Assert.assertEquals("create table t1 (" + "\n\tyear_col INT, " + "\n\tsome_data INT" + "\n)" + "\npartition by range (year_col)" + "\n(" + "\n\tpartition p0 values less than (1991)," + "\n\tpartition p1 values less than (1995)," + "\n\tpartition p2 values less than (1999)," + "\n\tpartition p3 values less than (2002)," + "\n\tpartition p4 values less than (2006)," + "\n\tpartition p5 values less than maxvalue" + "\n)", output);
}
}
use of com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor in project druid by alibaba.
the class MySqlCreateTableTest69 method test_one.
@Test
public void test_one() throws Exception {
String sql = "CREATE TABLE t1 (" + " s1 INT," + " s2 INT AS (EXP(s1)) STORED" + ")" + "PARTITION BY LIST (s2) (" + " PARTITION p1 VALUES IN (1)" + ");";
MySqlStatementParser parser = new MySqlStatementParser(sql);
SQLStatement stmt = parser.parseCreateTable();
MySqlSchemaStatVisitor visitor = new MySqlSchemaStatVisitor();
stmt.accept(visitor);
{
String output = SQLUtils.toMySqlString(stmt);
Assert.assertEquals("CREATE TABLE t1 (" + "\n\ts1 INT, " + "\n\ts2 INT AS (EXP(s1)) SORTED" + "\n)" + "\nPARTITION BY LIST (s2)" + "\n(" + "\n\tPARTITION p1 VALUES IN (1)" + "\n)", output);
}
{
String output = SQLUtils.toMySqlString(stmt, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION);
Assert.assertEquals("create table t1 (" + "\n\ts1 INT, " + "\n\ts2 INT as (EXP(s1)) sorted" + "\n)" + "\npartition by list (s2)" + "\n(" + "\n\tpartition p1 values in (1)" + "\n)", output);
}
}
use of com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor in project druid by alibaba.
the class MySqlCreateProcedureTest2 method test_1.
public void test_1() throws Exception {
String sql = "create or replace procedure sp_name(level int,age int)" + " begin" + " declare x,y,z int;" + " lable_1: begin" + " insert into test values(id,age);" + " end lable_1;" + " end";
MySqlStatementParser parser = new MySqlStatementParser(sql);
List<SQLStatement> statementList = parser.parseStatementList();
SQLStatement statemen = statementList.get(0);
// print(statementList);
Assert.assertEquals(1, statementList.size());
MySqlSchemaStatVisitor visitor = new MySqlSchemaStatVisitor();
statemen.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(2, visitor.getColumns().size());
Assert.assertEquals(0, visitor.getConditions().size());
Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("test")));
Assert.assertTrue(visitor.getColumns().contains(new Column("test", "id")));
Assert.assertTrue(visitor.getColumns().contains(new Column("test", "age")));
}
use of com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor in project druid by alibaba.
the class MySqlCreateProcedureTest2 method test_2.
public void test_2() throws Exception {
String sql = "create or replace procedure sp_name(level int,age int)" + " begin" + " declare x,y,z int;" + " lable_1: loop" + " insert into test values(id,age);" + " end loop lable_1;" + " end";
MySqlStatementParser parser = new MySqlStatementParser(sql);
List<SQLStatement> statementList = parser.parseStatementList();
SQLStatement statemen = statementList.get(0);
// print(statementList);
Assert.assertEquals(1, statementList.size());
MySqlSchemaStatVisitor visitor = new MySqlSchemaStatVisitor();
statemen.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(2, visitor.getColumns().size());
Assert.assertEquals(0, visitor.getConditions().size());
Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("test")));
Assert.assertTrue(visitor.getColumns().contains(new Column("test", "id")));
Assert.assertTrue(visitor.getColumns().contains(new Column("test", "age")));
}
use of com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor in project druid by alibaba.
the class MySqlCreateProcedureTest3 method test_0.
public void test_0() throws Exception {
String sql = "create or replace procedure sp_name(level int,age int)" + " begin" + " declare x,y,z int;" + " lable_1: while x do" + " insert into test values(id,age);" + " leave lable_1;" + " end while lable_1;" + " end";
MySqlStatementParser parser = new MySqlStatementParser(sql);
List<SQLStatement> statementList = parser.parseStatementList();
SQLStatement statemen = statementList.get(0);
// print(statementList);
Assert.assertEquals(1, statementList.size());
MySqlSchemaStatVisitor visitor = new MySqlSchemaStatVisitor();
statemen.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(2, visitor.getColumns().size());
Assert.assertEquals(0, visitor.getConditions().size());
Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("test")));
Assert.assertTrue(visitor.getColumns().contains(new Column("test", "id")));
Assert.assertTrue(visitor.getColumns().contains(new Column("test", "age")));
}
Aggregations