mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
improved sql parser for mysql ddl subpartition
This commit is contained in:
@@ -57,7 +57,8 @@ public class MySqlCreateTableTest40 extends MysqlTest {
|
||||
Assert.assertEquals("CREATE TABLE t1 (" + //
|
||||
"\n\tcol1 INT, " + //
|
||||
"\n\tcol2 CHAR(5)" + //
|
||||
"\n) PARTITION BY HASH (col1)", output);
|
||||
"\n)"
|
||||
+ "\nPARTITION BY HASH (col1)", output);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,7 +59,8 @@ public class MySqlCreateTableTest41 extends MysqlTest {
|
||||
"\n\tcol1 INT, " + //
|
||||
"\n\tcol2 CHAR(5), " + //
|
||||
"\n\tcol3 DATE" + //
|
||||
"\n) PARTITION BY LINEAR KEY (col3) PARTITIONS 5", output);
|
||||
"\n)"
|
||||
+ "\nPARTITION BY LINEAR KEY (col3) PARTITIONS 5", output);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,7 +65,8 @@ public class MySqlCreateTableTest42 extends MysqlTest {
|
||||
Assert.assertEquals("CREATE TABLE rc (" + //
|
||||
"\n\ta INT NOT NULL, " + //
|
||||
"\n\tb INT NOT NULL" + //
|
||||
"\n) PARTITION BY RANGE COLUMNS (a, b)(" + //
|
||||
"\n)"
|
||||
+ "\nPARTITION BY RANGE COLUMNS (a, b) (" + //
|
||||
"\n\tPARTITION p0 VALUES LESS THAN (10, 5), " + //
|
||||
"\n\tPARTITION p1 VALUES LESS THAN (20, 10), " + //
|
||||
"\n\tPARTITION p2 VALUES LESS THAN (MAXVALUE, 15), " + //
|
||||
|
||||
@@ -65,7 +65,8 @@ public class MySqlCreateTableTest43 extends MysqlTest {
|
||||
Assert.assertEquals("CREATE TABLE client_firms (" + //
|
||||
"\n\tid INT, " + //
|
||||
"\n\tname VARCHAR(35)" + //
|
||||
"\n) PARTITION BY LIST (id) (" + //
|
||||
"\n)"
|
||||
+ "\nPARTITION BY LIST (id) (" + //
|
||||
"\n\tPARTITION r0 VALUES IN (1, 5, 9, 13, 17, 21), " + //
|
||||
"\n\tPARTITION r1 VALUES IN (2, 6, 10, 14, 18, 22), " + //
|
||||
"\n\tPARTITION r2 VALUES IN (3, 7, 11, 15, 19, 23), " + //
|
||||
|
||||
@@ -65,7 +65,8 @@ public class MySqlCreateTableTest44 extends MysqlTest {
|
||||
Assert.assertEquals("CREATE TABLE lc (" + //
|
||||
"\n\ta INT NULL, " + //
|
||||
"\n\tb INT NULL" + //
|
||||
"\n) PARTITION BY LIST COLUMNS (a, b) (" + //
|
||||
"\n)" + //
|
||||
"\nPARTITION BY LIST COLUMNS (a, b) (" + //
|
||||
"\n\tPARTITION p0 VALUES IN ((0, 0), (NULL, NULL)), " + //
|
||||
"\n\tPARTITION p1 VALUES IN ((0, 1), (0, 2), (0, 3), (1, 1), (1, 2)), " + //
|
||||
"\n\tPARTITION p2 VALUES IN ((1, 0), (2, 0), (2, 1), (3, 0), (3, 1)), " + //
|
||||
|
||||
@@ -72,7 +72,8 @@ public class MySqlCreateTableTest45 extends MysqlTest {
|
||||
"\n\tid INT, " + //
|
||||
"\n\tname VARCHAR(30), " + //
|
||||
"\n\tadate DATE" + //
|
||||
"\n) PARTITION BY LIST (YEAR(adate)) (" + //
|
||||
"\n)" + //
|
||||
"\nPARTITION BY LIST (YEAR(adate)) (" + //
|
||||
"\n\tPARTITION p1999 VALUES IN (1995, 1999, 2003)" + //
|
||||
"\n\t\tDATA DIRECTORY '/var/appdata/95/data'" + //
|
||||
"\n\t\tINDEX DIRECTORY '/var/appdata/95/idx', " + //
|
||||
|
||||
@@ -51,7 +51,8 @@ public class MySqlCreateTableTest66 extends MysqlTest {
|
||||
+ "\n\tb_iden_string varchar, "
|
||||
+ "\n\tcounter bigint, "
|
||||
+ "\n\tdurationtime bigint"
|
||||
+ "\n) PARTITION BY HASH KEY(a_iden_string) PARTITION NUM 100"
|
||||
+ "\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);
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright 1999-2101 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.druid.bvt.sql.mysql;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.alibaba.druid.sql.MysqlTest;
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser;
|
||||
import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor;
|
||||
|
||||
public class MySqlCreateTableTest67 extends MysqlTest {
|
||||
|
||||
@Test
|
||||
public void test_one() throws Exception {
|
||||
String sql = "CREATE TABLE t1 ( a INT NOT NULL, PRIMARY KEY (a))"
|
||||
+ " ENGINE=InnoDB TABLESPACE ts1 "
|
||||
+ " PARTITION BY RANGE (a) PARTITIONS 3 ("
|
||||
+ " PARTITION P1 VALUES LESS THAN (2),"
|
||||
+ " PARTITION P2 VALUES LESS THAN (4) TABLESPACE ts2,"
|
||||
+ " PARTITION P3 VALUES LESS THAN (6) TABLESPACE ts3);";
|
||||
|
||||
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\ta INT NOT NULL, "
|
||||
+ "\n\tPRIMARY KEY (a)"
|
||||
+ "\n) ENGINE = InnoDB TABLESPACE ts1"
|
||||
+ "\nPARTITION BY RANGE (a) PARTITIONS 3 ("
|
||||
+ "\n\tPARTITION P1 VALUES LESS THAN (2), "
|
||||
+ "\n\tPARTITION P2 VALUES LESS THAN (4) TABLESPACE ts2, "
|
||||
+ "\n\tPARTITION P3 VALUES LESS THAN (6) TABLESPACE ts3"
|
||||
+ "\n)", output);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Copyright 1999-2101 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.druid.bvt.sql.mysql;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.alibaba.druid.sql.MysqlTest;
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser;
|
||||
import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor;
|
||||
|
||||
public class MySqlCreateTableTest68 extends MysqlTest {
|
||||
|
||||
@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\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);
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user