use of com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor in project druid by alibaba.
the class MySqlCreateTableTest41 method test_0.
public void test_0() throws Exception {
String sql = //
"CREATE TABLE tk (col1 INT, col2 CHAR(5), col3 DATE)" + //
" PARTITION BY LINEAR KEY(col3)" + //
" PARTITIONS 5;";
MySqlStatementParser parser = new MySqlStatementParser(sql);
List<SQLStatement> statementList = parser.parseStatementList();
SQLStatement stmt = 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(3, visitor.getColumns().size());
Assert.assertEquals(0, visitor.getConditions().size());
Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("tk")));
String output = SQLUtils.toMySqlString(stmt);
Assert.assertEquals(//
"CREATE TABLE tk (" + //
"\n\tcol1 INT, " + //
"\n\tcol2 CHAR(5), " + //
"\n\tcol3 DATE" + "\n)" + "\nPARTITION BY LINEAR KEY (col3) PARTITIONS 5", output);
}
use of com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor in project druid by alibaba.
the class MySqlCreateTableTest42 method test_0.
public void test_0() throws Exception {
String sql = //
"CREATE TABLE rc (" + //
" a INT NOT NULL, " + //
" b INT NOT NULL" + //
")" + //
"PARTITION BY RANGE COLUMNS(a,b) (" + //
" PARTITION p0 VALUES LESS THAN (10,5)," + //
" PARTITION p1 VALUES LESS THAN (20,10)," + //
" PARTITION p2 VALUES LESS THAN (MAXVALUE,15)," + //
" PARTITION p3 VALUES LESS THAN (MAXVALUE,MAXVALUE)" + //
");";
MySqlStatementParser parser = new MySqlStatementParser(sql);
List<SQLStatement> statementList = parser.parseStatementList();
SQLStatement stmt = 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(2, visitor.getColumns().size());
Assert.assertEquals(0, visitor.getConditions().size());
Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("rc")));
String output = SQLUtils.toMySqlString(stmt);
Assert.assertEquals(//
"CREATE TABLE rc (" + //
"\n\ta INT NOT NULL, " + //
"\n\tb INT NOT NULL" + "\n)" + "\nPARTITION BY RANGE COLUMNS (a, b)" + //
"\n(" + //
"\n\tPARTITION p0 VALUES LESS THAN (10, 5)," + //
"\n\tPARTITION p1 VALUES LESS THAN (20, 10)," + //
"\n\tPARTITION p2 VALUES LESS THAN (MAXVALUE, 15)," + //
"\n\tPARTITION p3 VALUES LESS THAN (MAXVALUE, MAXVALUE)" + "\n)", output);
}
use of com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor in project druid by alibaba.
the class MySqlCreateTableTest19 method test_0.
public void test_0() throws Exception {
String sql = "CREATE TABLE new_tbl LIKE orig_tbl;";
MySqlStatementParser parser = new MySqlStatementParser(sql);
List<SQLStatement> statementList = parser.parseStatementList();
SQLStatement stmt = statementList.get(0);
//
Assert.assertEquals(//
"CREATE TABLE new_tbl LIKE orig_tbl", SQLUtils.toMySqlString(stmt));
//
Assert.assertEquals(//
"create table new_tbl like orig_tbl", SQLUtils.toMySqlString(stmt, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION));
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("new_tbl")));
}
use of com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor in project druid by alibaba.
the class MySqlCreateTableTest20 method test_0.
public void test_0() throws Exception {
String sql = "CREATE TABLE new_tbl (LIKE orig_tbl);";
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(0, visitor.getColumns().size());
Assert.assertEquals(0, visitor.getConditions().size());
Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("new_tbl")));
}
use of com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor in project druid by alibaba.
the class MySqlCreateTableTest21 method test_0.
public void test_0() throws Exception {
String sql = "CREATE TABLE new_tbl (LIKE orig_tbl);";
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(0, visitor.getColumns().size());
Assert.assertEquals(0, visitor.getConditions().size());
Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("new_tbl")));
}
Aggregations