Search in sources :

Example 51 with MySqlSchemaStatVisitor

use of com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor in project druid by alibaba.

the class MySqlCreateTableTest22 method test_0.

public void test_0() throws Exception {
    String sql = //
    "CREATE TABLE t1 (" + //
    "c1 INT STORAGE DISK," + //
    "c2 INT STORAGE MEMORY " + ") TABLESPACE ts_1 ENGINE NDB;";
    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("t1")));
    String output = SQLUtils.toMySqlString(stmt);
    Assert.assertEquals(//
    "CREATE TABLE t1 (" + //
    "\n\tc1 INT STORAGE DISK, " + //
    "\n\tc2 INT STORAGE MEMORY" + "\n) TABLESPACE ts_1 ENGINE = NDB", output);
}
Also used : MySqlSchemaStatVisitor(com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor) MySqlStatementParser(com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement)

Example 52 with MySqlSchemaStatVisitor

use of com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor in project druid by alibaba.

the class MySqlCreateTableTest24 method test_0.

public void test_0() throws Exception {
    String sql = //
    "CREATE TABLE lookup" + //
    "  (id INT, INDEX USING BTREE (id))" + //
    "  AVG_ROW_LENGTH = 1024;";
    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(1, visitor.getColumns().size());
    Assert.assertEquals(0, visitor.getConditions().size());
    Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("lookup")));
    String output = SQLUtils.toMySqlString(stmt);
    Assert.assertEquals(//
    "CREATE TABLE lookup (" + //
    "\n\tid INT, " + //
    "\n\tINDEX USING BTREE(id)" + "\n) AVG_ROW_LENGTH = 1024", output);
}
Also used : MySqlSchemaStatVisitor(com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor) MySqlStatementParser(com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement)

Example 53 with MySqlSchemaStatVisitor

use of com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor in project druid by alibaba.

the class MySqlCreateTableTest26 method test_0.

public void test_0() throws Exception {
    String sql = //
    "CREATE TABLE lookup" + //
    "  (id INT, INDEX USING BTREE (id))" + //
    "  MAX_ROWS 1024;";
    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(1, visitor.getColumns().size());
    Assert.assertEquals(0, visitor.getConditions().size());
    Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("lookup")));
    String output = SQLUtils.toMySqlString(stmt);
    Assert.assertEquals(//
    "CREATE TABLE lookup (" + //
    "\n\tid INT, " + //
    "\n\tINDEX USING BTREE(id)" + "\n) MAX_ROWS = 1024", output);
}
Also used : MySqlSchemaStatVisitor(com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor) MySqlStatementParser(com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement)

Example 54 with MySqlSchemaStatVisitor

use of com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor in project druid by alibaba.

the class MySqlCreateTableTest62 method test_one.

@Test
public void test_one() throws Exception {
    String sql = "create table a ( b varchar(15) CHARACTER SET latin1 DEFAULT NULL)";
    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 a (" + "\n\tb varchar(15) CHARACTER SET latin1 DEFAULT NULL" + "\n)", output);
    }
    {
        String output = SQLUtils.toMySqlString(stmt, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION);
        Assert.assertEquals("create table a (" + "\n\tb varchar(15) character set latin1 default null" + "\n)", output);
    }
}
Also used : MySqlSchemaStatVisitor(com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor) MySqlStatementParser(com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement) MysqlTest(com.alibaba.druid.sql.MysqlTest) Test(org.junit.Test)

Example 55 with MySqlSchemaStatVisitor

use of com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor in project druid by alibaba.

the class MySqlCreateTableTest66 method test_one.

@Test
public void test_one() throws Exception {
    String sql = "create table hp_db.g20_relationship_communication_daily(                   " + " a_iden_string    varchar," + " b_iden_string    varchar," + " counter          bigint," + " durationtime     bigint" + ") " + "\nPARTITION BY HASH KEY(a_iden_string) PARTITION NUM 100" + "\nSUBPARTITION BY LIST(bdt bigint)" + "\nSUBPARTITION OPTIONS(available_Partition_Num=90)" + "\nTABLEGROUP g20_test_group;";
    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 hp_db.g20_relationship_communication_daily (" + "\n\ta_iden_string varchar, " + "\n\tb_iden_string varchar, " + "\n\tcounter bigint, " + "\n\tdurationtime bigint" + "\n)" + "\nPARTITION BY HASH KEY(a_iden_string) PARTITION NUM 100" + "\nSUBPARTITION BY LIST (bdt bigint)" + "\nSUBPARTITION OPTIONS (available_Partition_Num = 90)" + "\nTABLEGROUP g20_test_group", output);
    }
    {
        String output = SQLUtils.toMySqlString(stmt, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION);
        Assert.assertEquals("create table hp_db.g20_relationship_communication_daily (" + "\n\ta_iden_string varchar, " + "\n\tb_iden_string varchar, " + "\n\tcounter bigint, " + "\n\tdurationtime bigint" + "\n)" + "\npartition by hash key(a_iden_string) partition num 100" + "\nsubpartition by list (bdt bigint)" + "\nsubpartition options (available_Partition_Num = 90)" + "\ntablegroup g20_test_group", output);
    }
}
Also used : MySqlSchemaStatVisitor(com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor) MySqlStatementParser(com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement) MysqlTest(com.alibaba.druid.sql.MysqlTest) Test(org.junit.Test)

Aggregations

MySqlSchemaStatVisitor (com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor)345 SQLStatement (com.alibaba.druid.sql.ast.SQLStatement)344 MySqlStatementParser (com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser)341 Column (com.alibaba.druid.stat.TableStat.Column)74 MysqlTest (com.alibaba.druid.sql.MysqlTest)29 Test (org.junit.Test)29 SQLSelect (com.alibaba.druid.sql.ast.statement.SQLSelect)15 SQLSelectStatement (com.alibaba.druid.sql.ast.statement.SQLSelectStatement)15 MySqlSelectQueryBlock (com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock)15 MySqlInsertStatement (com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlInsertStatement)12 SQLInsertStatement (com.alibaba.druid.sql.ast.statement.SQLInsertStatement)5 MySqlCreateTableStatement (com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlCreateTableStatement)4 SQLCreateTableStatement (com.alibaba.druid.sql.ast.statement.SQLCreateTableStatement)3 SQLCreateViewStatement (com.alibaba.druid.sql.ast.statement.SQLCreateViewStatement)3 SQLStatementParser (com.alibaba.druid.sql.parser.SQLStatementParser)2 SchemaStatVisitor (com.alibaba.druid.sql.visitor.SchemaStatVisitor)2 SQLExpr (com.alibaba.druid.sql.ast.SQLExpr)1 SQLName (com.alibaba.druid.sql.ast.SQLName)1 SQLBinaryOpExpr (com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr)1 SQLCharExpr (com.alibaba.druid.sql.ast.expr.SQLCharExpr)1