improved sql parser.

This commit is contained in:
wenshao
2017-06-29 15:19:57 +08:00
parent 2f6e406e33
commit bdbc39ec3c
39 changed files with 963 additions and 185 deletions
@@ -54,8 +54,7 @@ public class OceanbaseCreateTableTest_rangePartition extends MysqlTest {
+ "\n\tjob_code INT NOT NULL,"
+ "\n\tstore_id INT NOT NULL"
+ "\n)"
+ "\nPARTITION BY RANGE (store_id)"
+ "\n("
+ "\nPARTITION BY RANGE (store_id) ("
+ "\n\tPARTITION p0 VALUES LESS THAN (6),"
+ "\n\tPARTITION p1 VALUES LESS THAN (11),"
+ "\n\tPARTITION p2 VALUES LESS THAN (16),"
@@ -74,8 +73,7 @@ public class OceanbaseCreateTableTest_rangePartition extends MysqlTest {
+ "\n\tjob_code INT not null,"
+ "\n\tstore_id INT not null"
+ "\n)"
+ "\npartition by range (store_id)"
+ "\n("
+ "\npartition by range (store_id) ("
+ "\n\tpartition p0 values less than (6),"
+ "\n\tpartition p1 values less than (11),"
+ "\n\tpartition p2 values less than (16),"
@@ -57,8 +57,7 @@ public class OceanbaseCreateTableTest_rangePartition2 extends MysqlTest {
+ "\n\tjob_code INT NOT NULL,"
+ "\n\tstore_id INT NOT NULL"
+ "\n)"
+ "\nPARTITION BY RANGE (store_id)"
+ "\n("
+ "\nPARTITION BY RANGE (store_id) ("
+ "\n\tPARTITION p0 VALUES LESS THAN (6),"
+ "\n\tPARTITION p1 VALUES LESS THAN (11),"
+ "\n\tPARTITION p2 VALUES LESS THAN (16),"
@@ -77,8 +76,7 @@ public class OceanbaseCreateTableTest_rangePartition2 extends MysqlTest {
+ "\n\tjob_code INT not null,"
+ "\n\tstore_id INT not null"
+ "\n)"
+ "\npartition by range (store_id)"
+ "\n("
+ "\npartition by range (store_id) ("
+ "\n\tpartition p0 values less than (6),"
+ "\n\tpartition p1 values less than (11),"
+ "\n\tpartition p2 values less than (16),"
@@ -56,8 +56,7 @@ public class OceanbaseCreateTableTest_rangePartition3 extends MysqlTest {
+ "\n\tjob_code INT NOT NULL,"
+ "\n\tstore_id INT NOT NULL"
+ "\n)"
+ "\nPARTITION BY RANGE (job_code)"
+ "\n("
+ "\nPARTITION BY RANGE (job_code) ("
+ "\n\tPARTITION p0 VALUES LESS THAN (100),"
+ "\n\tPARTITION p1 VALUES LESS THAN (1000),"
+ "\n\tPARTITION p2 VALUES LESS THAN (10000)"
@@ -75,8 +74,7 @@ public class OceanbaseCreateTableTest_rangePartition3 extends MysqlTest {
+ "\n\tjob_code INT not null,"
+ "\n\tstore_id INT not null"
+ "\n)"
+ "\npartition by range (job_code)"
+ "\n("
+ "\npartition by range (job_code) ("
+ "\n\tpartition p0 values less than (100),"
+ "\n\tpartition p1 values less than (1000),"
+ "\n\tpartition p2 values less than (10000)"
@@ -56,8 +56,7 @@ public class OceanbaseCreateTableTest_rangePartition4 extends MysqlTest {
+ "\n\tjob_code INT,"
+ "\n\tstore_id INT"
+ "\n)"
+ "\nPARTITION BY RANGE (YEAR(separated))"
+ "\n("
+ "\nPARTITION BY RANGE (YEAR(separated)) ("
+ "\n\tPARTITION p0 VALUES LESS THAN (1991),"
+ "\n\tPARTITION p1 VALUES LESS THAN (1996),"
+ "\n\tPARTITION p2 VALUES LESS THAN (2001),"
@@ -76,8 +75,7 @@ public class OceanbaseCreateTableTest_rangePartition4 extends MysqlTest {
+ "\n\tjob_code INT,"
+ "\n\tstore_id INT"
+ "\n)"
+ "\npartition by range (YEAR(separated))"
+ "\n("
+ "\npartition by range (YEAR(separated)) ("
+ "\n\tpartition p0 values less than (1991),"
+ "\n\tpartition p1 values less than (1996),"
+ "\n\tpartition p2 values less than (2001),"
@@ -44,8 +44,7 @@ public class OceanbaseCreateTableTest_rangePartition5 extends MysqlTest {
+ "\n\tid INT,"
+ "\n\tname VARCHAR(5)"
+ "\n)"
+ "\nPARTITION BY RANGE (id)"
+ "\n("
+ "\nPARTITION BY RANGE (id) ("
+ "\n\tPARTITION p1 VALUES LESS THAN (1),"
+ "\n\tPARTITION p2 VALUES LESS THAN MAXVALUE"
+ "\n);",
@@ -57,8 +56,7 @@ public class OceanbaseCreateTableTest_rangePartition5 extends MysqlTest {
+ "\n\tid INT,"
+ "\n\tname VARCHAR(5)"
+ "\n)"
+ "\npartition by range (id)"
+ "\n("
+ "\npartition by range (id) ("
+ "\n\tpartition p1 values less than (1),"
+ "\n\tpartition p2 values less than maxvalue"
+ "\n);",
@@ -47,8 +47,7 @@ public class OceanbaseCreateTableTest_subPartition extends MysqlTest {
+ "\n\tpurchased DATE"
+ "\n)"
+ "\nPARTITION BY RANGE (YEAR(purchased))"
+ "\nSUBPARTITION BY HASH (TO_DAYS(purchased)) SUBPARTITIONS 2"
+ "\n("
+ "\nSUBPARTITION BY HASH (TO_DAYS(purchased)) SUBPARTITIONS 2 ("
+ "\n\tPARTITION p0 VALUES LESS THAN (1990),"
+ "\n\tPARTITION p1 VALUES LESS THAN (2000),"
+ "\n\tPARTITION p2 VALUES LESS THAN MAXVALUE"
@@ -62,8 +61,7 @@ public class OceanbaseCreateTableTest_subPartition extends MysqlTest {
+ "\n\tpurchased DATE"
+ "\n)"
+ "\npartition by range (YEAR(purchased))"
+ "\nsubpartition by hash (TO_DAYS(purchased)) subpartitions 2"
+ "\n("
+ "\nsubpartition by hash (TO_DAYS(purchased)) subpartitions 2 ("
+ "\n\tpartition p0 values less than (1990),"
+ "\n\tpartition p1 values less than (2000),"
+ "\n\tpartition p2 values less than maxvalue"
@@ -44,56 +44,48 @@ public class OceanbaseCreateTableTest_subPartition2 extends MysqlTest {
SQLStatement stmt = stmtList.get(0);
{
String result = SQLUtils.toMySqlString(stmt);
Assert.assertEquals("CREATE TABLE ts (" + //
"\n\tid INT," + //
"\n\tpurchased DATE" + //
"\n)" + //
"\nPARTITION BY RANGE (YEAR(purchased))" + //
"\nSUBPARTITION BY HASH (TO_DAYS(purchased))" + //
"\n(" + //
"\n\tPARTITION p0 VALUES LESS THAN (1990)" + //
"\n\t(" + //
"\n\t\tSUBPARTITION s0," + //
"\n\t\tSUBPARTITION s1" + //
"\n\t)," + //
"\n\tPARTITION p1 VALUES LESS THAN (2000)" + //
"\n\t(" + //
"\n\t\tSUBPARTITION s2," + //
"\n\t\tSUBPARTITION s3" + //
"\n\t)," + //
"\n\tPARTITION p2 VALUES LESS THAN MAXVALUE" + //
"\n\t(" + //
"\n\t\tSUBPARTITION s4," + //
"\n\t\tSUBPARTITION s5" + //
"\n\t)" + //
"\n)",
Assert.assertEquals("CREATE TABLE ts (\n" +
"\tid INT,\n" +
"\tpurchased DATE\n" +
")\n" +
"PARTITION BY RANGE (YEAR(purchased))\n" +
"SUBPARTITION BY HASH (TO_DAYS(purchased)) (\n" +
"\tPARTITION p0 VALUES LESS THAN (1990) (\n" +
"\t\tSUBPARTITION s0,\n" +
"\t\tSUBPARTITION s1\n" +
"\t),\n" +
"\tPARTITION p1 VALUES LESS THAN (2000) (\n" +
"\t\tSUBPARTITION s2,\n" +
"\t\tSUBPARTITION s3\n" +
"\t),\n" +
"\tPARTITION p2 VALUES LESS THAN MAXVALUE (\n" +
"\t\tSUBPARTITION s4,\n" +
"\t\tSUBPARTITION s5\n" +
"\t)\n" +
")",
result);
}
{
String result = SQLUtils.toMySqlString(stmt, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION);
Assert.assertEquals("create table ts (" + //
"\n\tid INT," + //
"\n\tpurchased DATE" + //
"\n)" + //
"\npartition by range (YEAR(purchased))" + //
"\nsubpartition by hash (TO_DAYS(purchased))" + //
"\n(" + //
"\n\tpartition p0 values less than (1990)" + //
"\n\t(" + //
"\n\t\tsubpartition s0," + //
"\n\t\tsubpartition s1" + //
"\n\t)," + //
"\n\tpartition p1 values less than (2000)" + //
"\n\t(" + //
"\n\t\tsubpartition s2," + //
"\n\t\tsubpartition s3" + //
"\n\t)," + //
"\n\tpartition p2 values less than maxvalue" + //
"\n\t(" + //
"\n\t\tsubpartition s4," + //
"\n\t\tsubpartition s5" + //
"\n\t)" + //
"\n)",
Assert.assertEquals("create table ts (\n" +
"\tid INT,\n" +
"\tpurchased DATE\n" +
")\n" +
"partition by range (YEAR(purchased))\n" +
"subpartition by hash (TO_DAYS(purchased)) (\n" +
"\tpartition p0 values less than (1990) (\n" +
"\t\tsubpartition s0,\n" +
"\t\tsubpartition s1\n" +
"\t),\n" +
"\tpartition p1 values less than (2000) (\n" +
"\t\tsubpartition s2,\n" +
"\t\tsubpartition s3\n" +
"\t),\n" +
"\tpartition p2 values less than maxvalue (\n" +
"\t\tsubpartition s4,\n" +
"\t\tsubpartition s5\n" +
"\t)\n" +
")",
result);
System.out.println(result);
}
@@ -39,25 +39,22 @@ public class OceanbaseCreateTableTest_subPartition3 extends MysqlTest {
SQLStatement stmt = stmtList.get(0);
String result = SQLUtils.toMySqlString(stmt);
Assert.assertEquals("CREATE TABLE ts ("
+ "\n\tid INT,"
+ "\n\tpurchased DATE"
+ "\n)"
+ "\nPARTITION BY RANGE (YEAR(purchased))"
+ "\nSUBPARTITION BY HASH (TO_DAYS(purchased))"
+ "\n("
+ "\n\tPARTITION p0 VALUES LESS THAN (1990)"
+ "\n\t("
+ "\n\t\tSUBPARTITION s0,"
+ "\n\t\tSUBPARTITION s1"
+ "\n\t),"
+ "\n\tPARTITION p1 VALUES LESS THAN (2000),"
+ "\n\tPARTITION p2 VALUES LESS THAN MAXVALUE"
+ "\n\t("
+ "\n\t\tSUBPARTITION s2,"
+ "\n\t\tSUBPARTITION s3"
+ "\n\t)"
+ "\n)",
Assert.assertEquals("CREATE TABLE ts (\n" +
"\tid INT,\n" +
"\tpurchased DATE\n" +
")\n" +
"PARTITION BY RANGE (YEAR(purchased))\n" +
"SUBPARTITION BY HASH (TO_DAYS(purchased)) (\n" +
"\tPARTITION p0 VALUES LESS THAN (1990) (\n" +
"\t\tSUBPARTITION s0,\n" +
"\t\tSUBPARTITION s1\n" +
"\t),\n" +
"\tPARTITION p1 VALUES LESS THAN (2000),\n" +
"\tPARTITION p2 VALUES LESS THAN MAXVALUE (\n" +
"\t\tSUBPARTITION s2,\n" +
"\t\tSUBPARTITION s3\n" +
"\t)\n" +
")",
result);
print(stmtList);
@@ -40,29 +40,25 @@ public class OceanbaseCreateTableTest_subPartition4 extends MysqlTest {
SQLStatement stmt = stmtList.get(0);
String result = SQLUtils.toMySqlString(stmt);
Assert.assertEquals("CREATE TABLE ts ("
+ "\n\tid INT,"
+ "\n\tpurchased DATE"
+ "\n)"
+ "\nPARTITION BY RANGE (YEAR(purchased))"
+ "\nSUBPARTITION BY HASH (TO_DAYS(purchased))"
+ "\n("
+ "\n\tPARTITION p0 VALUES LESS THAN (1990)"
+ "\n\t("
+ "\n\t\tSUBPARTITION s0,"
+ "\n\t\tSUBPARTITION s1"
+ "\n\t),"
+ "\n\tPARTITION p1 VALUES LESS THAN (2000)"
+ "\n\t("
+ "\n\t\tSUBPARTITION s0,"
+ "\n\t\tSUBPARTITION s1"
+ "\n\t),"
+ "\n\tPARTITION p2 VALUES LESS THAN MAXVALUE"
+ "\n\t("
+ "\n\t\tSUBPARTITION s0,"
+ "\n\t\tSUBPARTITION s1"
+ "\n\t)"
+ "\n)",
Assert.assertEquals("CREATE TABLE ts (\n" +
"\tid INT,\n" +
"\tpurchased DATE\n" +
")\n" +
"PARTITION BY RANGE (YEAR(purchased))\n" +
"SUBPARTITION BY HASH (TO_DAYS(purchased)) (\n" +
"\tPARTITION p0 VALUES LESS THAN (1990) (\n" +
"\t\tSUBPARTITION s0,\n" +
"\t\tSUBPARTITION s1\n" +
"\t),\n" +
"\tPARTITION p1 VALUES LESS THAN (2000) (\n" +
"\t\tSUBPARTITION s0,\n" +
"\t\tSUBPARTITION s1\n" +
"\t),\n" +
"\tPARTITION p2 VALUES LESS THAN MAXVALUE (\n" +
"\t\tSUBPARTITION s0,\n" +
"\t\tSUBPARTITION s1\n" +
"\t)\n" +
")",
result);
print(stmtList);