sql parser support mysql 5.7 & oceanbase 1.0

This commit is contained in:
高铁
2016-02-29 23:12:13 +08:00
parent bebef5ea9e
commit 0ee24a11d4
44 changed files with 2675 additions and 957 deletions
@@ -0,0 +1,60 @@
/*
* 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.oceanbase;
import java.util.List;
import org.junit.Assert;
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 OceanbaseAlterTableAddPartitionTest extends MysqlTest {
public void test_0() throws Exception {
String sql = "ALTER TABLE members ADD PARTITION (PARTITION p3 VALUES LESS THAN (2000));"; //
MySqlStatementParser parser = new MySqlStatementParser(sql);
List<SQLStatement> stmtList = parser.parseStatementList();
SQLStatement stmt = stmtList.get(0);
String result = SQLUtils.toMySqlString(stmt);
Assert.assertEquals("ALTER TABLE members"
+ "\n\tADD PARTITION (PARTITION p3 VALUES LESS THAN (2000))",
result);
print(stmtList);
Assert.assertEquals(1, stmtList.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("t_basic_store")));
}
}
@@ -0,0 +1,60 @@
/*
* 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.oceanbase;
import java.util.List;
import org.junit.Assert;
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 OceanbaseAlterTableAddPartitionTest2 extends MysqlTest {
public void test_0() throws Exception {
String sql = "alter table clients add partition partitions 18;"; //
MySqlStatementParser parser = new MySqlStatementParser(sql);
List<SQLStatement> stmtList = parser.parseStatementList();
SQLStatement stmt = stmtList.get(0);
String result = SQLUtils.toMySqlString(stmt);
Assert.assertEquals("ALTER TABLE clients"
+ "\n\tADD PARTITION PARTITIONS 18",
result);
print(stmtList);
Assert.assertEquals(1, stmtList.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("t_basic_store")));
}
}
@@ -0,0 +1,60 @@
/*
* 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.oceanbase;
import java.util.List;
import org.junit.Assert;
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 OceanbaseAlterTableCoalescePartitionTest extends MysqlTest {
public void test_0() throws Exception {
String sql = "ALTER TABLE clients COALESCE PARTITION 6"; //
MySqlStatementParser parser = new MySqlStatementParser(sql);
List<SQLStatement> stmtList = parser.parseStatementList();
SQLStatement stmt = stmtList.get(0);
String result = SQLUtils.toMySqlString(stmt);
Assert.assertEquals("ALTER TABLE clients"
+ "\n\tCOALESCE PARTITION 6",
result);
print(stmtList);
Assert.assertEquals(1, stmtList.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("t_basic_store")));
}
}
@@ -0,0 +1,60 @@
/*
* 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.oceanbase;
import java.util.List;
import org.junit.Assert;
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 OceanbaseAlterTableDropPartitionTest extends MysqlTest {
public void test_0() throws Exception {
String sql = "ALTER TABLE tnrange DROP PARTITION p1;"; //
MySqlStatementParser parser = new MySqlStatementParser(sql);
List<SQLStatement> stmtList = parser.parseStatementList();
SQLStatement stmt = stmtList.get(0);
String result = SQLUtils.toMySqlString(stmt);
Assert.assertEquals("ALTER TABLE tnrange"
+ "\n\tDROP PARTITION p1",
result);
print(stmtList);
Assert.assertEquals(1, stmtList.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("t_basic_store")));
}
}
@@ -0,0 +1,61 @@
/*
* 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.oceanbase;
import java.util.List;
import org.junit.Assert;
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 OceanbaseAlterTableReOrganizePartitionTest extends MysqlTest {
public void test_0() throws Exception {
String sql = "ALTER TABLE members "
+ "REORGANIZE PARTITION p0 INTO ( PARTITION s0 VALUES LESS THAN (1960), PARTITION s1 VALUES LESS THAN (1970) );"; //
MySqlStatementParser parser = new MySqlStatementParser(sql);
List<SQLStatement> stmtList = parser.parseStatementList();
SQLStatement stmt = stmtList.get(0);
String result = SQLUtils.toMySqlString(stmt);
Assert.assertEquals("ALTER TABLE members"
+ "\n\tREORGANIZE p0 INTO (PARTITION s0 VALUES LESS THAN (1960), PARTITION s1 VALUES LESS THAN (1970))",
result);
print(stmtList);
Assert.assertEquals(1, stmtList.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("t_basic_store")));
}
}
@@ -0,0 +1,64 @@
/*
* 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.oceanbase;
import java.util.List;
import org.junit.Assert;
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 OceanbaseAlterTableReOrganizePartitionTest2 extends MysqlTest {
public void test_0() throws Exception {
String sql = "ALTER TABLE members " //
+ "REORGANIZE PARTITION s0,s1,p1,p2,p3 INTO ( "//
+ " PARTITION m0 VALUES LESS THAN (1980), " //
+ " PARTITION m1 VALUES LESS THAN (2000)" //
+ ");"; //
MySqlStatementParser parser = new MySqlStatementParser(sql);
List<SQLStatement> stmtList = parser.parseStatementList();
SQLStatement stmt = stmtList.get(0);
String result = SQLUtils.toMySqlString(stmt);
Assert.assertEquals("ALTER TABLE members"
+ "\n\tREORGANIZE s0, s1, p1, p2, p3 INTO (PARTITION m0 VALUES LESS THAN (1980), PARTITION m1 VALUES LESS THAN (2000))",
result);
print(stmtList);
Assert.assertEquals(1, stmtList.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("t_basic_store")));
}
}
@@ -0,0 +1,63 @@
/*
* 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.oceanbase;
import java.util.List;
import org.junit.Assert;
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 OceanbaseCreateTableTest_partitionByHash extends MysqlTest {
public void test_0() throws Exception {
String sql = "CREATE TABLE tnhash ( id INT, name VARCHAR(5) ) PARTITION BY HASH(id) PARTITIONS 2;"; //
MySqlStatementParser parser = new MySqlStatementParser(sql);
List<SQLStatement> stmtList = parser.parseStatementList();
SQLStatement stmt = stmtList.get(0);
String result = SQLUtils.toMySqlString(stmt);
Assert.assertEquals("CREATE TABLE tnhash ("
+ "\n\tid INT, "
+ "\n\tname VARCHAR(5)"
+ "\n)"
+ "\nPARTITION BY HASH (id) PARTITIONS 2",
result);
print(stmtList);
Assert.assertEquals(1, stmtList.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("t_basic_store")));
}
}
@@ -0,0 +1,75 @@
/*
* 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.oceanbase;
import java.util.List;
import org.junit.Assert;
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 OceanbaseCreateTableTest_partitionByHash2 extends MysqlTest {
public void test_0() throws Exception {
String sql = "CREATE TABLE employees ( " //
+ "id INT NOT NULL, fname VARCHAR(30), " //
+ "lname VARCHAR(30), " //
+ "hired DATE NOT NULL DEFAULT '1970-01-01', " //
+ "separated DATE NOT NULL DEFAULT '9999-12-31', " //
+ "job_code INT, " //
+ "store_id INT ) "
+ "PARTITION BY HASH(YEAR(hired)) PARTITIONS 4"; //
MySqlStatementParser parser = new MySqlStatementParser(sql);
List<SQLStatement> stmtList = parser.parseStatementList();
SQLStatement stmt = stmtList.get(0);
String result = SQLUtils.toMySqlString(stmt);
Assert.assertEquals("CREATE TABLE employees ("
+ "\n\tid INT NOT NULL, "
+ "\n\tfname VARCHAR(30), "
+ "\n\tlname VARCHAR(30), "
+ "\n\thired DATE NOT NULL DEFAULT '1970-01-01', "
+ "\n\tseparated DATE NOT NULL DEFAULT '9999-12-31', "
+ "\n\tjob_code INT, "
+ "\n\tstore_id INT"
+ "\n)"
+ "\nPARTITION BY HASH (YEAR(hired)) PARTITIONS 4",
result);
print(stmtList);
Assert.assertEquals(1, stmtList.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(7, visitor.getColumns().size());
Assert.assertEquals(0, visitor.getConditions().size());
// Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("t_basic_store")));
}
}
@@ -0,0 +1,63 @@
/*
* 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.oceanbase;
import java.util.List;
import org.junit.Assert;
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 OceanbaseCreateTableTest_partitionByKey extends MysqlTest {
public void test_0() throws Exception {
String sql = "create table k2(id int primary key, name varchar(20)) partition by key() partitions 2"; //
MySqlStatementParser parser = new MySqlStatementParser(sql);
List<SQLStatement> stmtList = parser.parseStatementList();
SQLStatement stmt = stmtList.get(0);
String result = SQLUtils.toMySqlString(stmt);
Assert.assertEquals("CREATE TABLE k2 ("
+ "\n\tid int PRIMARY KEY, "
+ "\n\tname varchar(20)"
+ "\n)"
+ "\nPARTITION BY KEY () PARTITIONS 2",
result);
print(stmtList);
Assert.assertEquals(1, stmtList.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("t_basic_store")));
}
}
@@ -0,0 +1,83 @@
/*
* 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.oceanbase;
import java.util.List;
import org.junit.Assert;
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 OceanbaseCreateTableTest_rangePartition extends MysqlTest {
public void test_0() throws Exception {
String sql = "CREATE TABLE employees (" //
+ " id INT NOT NULL, fname VARCHAR(30)," //
+ " lname VARCHAR(30), hired DATE NOT NULL DEFAULT '1970-01-01'," //
+ " separated DATE NOT NULL DEFAULT '9999-12-31', job_code INT NOT NULL,"
+ " store_id INT NOT NULL" //
+ " ) PARTITION BY RANGE (store_id) " //
+ "( PARTITION p0 VALUES LESS THAN (6), " //
+ "PARTITION p1 VALUES LESS THAN (11), " //
+ "PARTITION p2 VALUES LESS THAN (16), " //
+ "PARTITION p3 VALUES LESS THAN (21) )";
MySqlStatementParser parser = new MySqlStatementParser(sql);
List<SQLStatement> stmtList = parser.parseStatementList();
SQLStatement stmt = stmtList.get(0);
String result = SQLUtils.toMySqlString(stmt);
Assert.assertEquals("CREATE TABLE employees ("
+ "\n\tid INT NOT NULL, "
+ "\n\tfname VARCHAR(30), "
+ "\n\tlname VARCHAR(30), "
+ "\n\thired DATE NOT NULL DEFAULT '1970-01-01', "
+ "\n\tseparated DATE NOT NULL DEFAULT '9999-12-31', "
+ "\n\tjob_code INT NOT NULL, "
+ "\n\tstore_id INT NOT NULL"
+ "\n)"
+ "\nPARTITION BY RANGE (store_id)"
+ "\n("
+ "\n\tPARTITION p0 VALUES LESS THAN (6),"
+ "\n\tPARTITION p1 VALUES LESS THAN (11),"
+ "\n\tPARTITION p2 VALUES LESS THAN (16),"
+ "\n\tPARTITION p3 VALUES LESS THAN (21)"
+ "\n)",
result);
print(stmtList);
Assert.assertEquals(1, stmtList.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(7, visitor.getColumns().size());
Assert.assertEquals(0, visitor.getConditions().size());
// Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("t_basic_store")));
}
}
@@ -0,0 +1,86 @@
/*
* 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.oceanbase;
import java.util.List;
import org.junit.Assert;
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 OceanbaseCreateTableTest_rangePartition2 extends MysqlTest {
public void test_0() throws Exception {
String sql = "CREATE TABLE employees ( " //
+ "id INT NOT NULL, " //
+ "fname VARCHAR(30), " //
+ "lname VARCHAR(30), " //
+ "hired DATE NOT NULL DEFAULT '1970-01-01', " //
+ "separated DATE NOT NULL DEFAULT '9999-12-31', " //
+ "job_code INT NOT NULL,store_id INT NOT NULL " //
+ ") PARTITION BY RANGE (store_id) " //
+ "( PARTITION p0 VALUES LESS THAN (6), " //
+ "PARTITION p1 VALUES LESS THAN (11), " //
+ "PARTITION p2 VALUES LESS THAN (16), " //
+ "PARTITION p3 VALUES LESS THAN MAXVALUE " //
+ ")";
MySqlStatementParser parser = new MySqlStatementParser(sql);
List<SQLStatement> stmtList = parser.parseStatementList();
SQLStatement stmt = stmtList.get(0);
String result = SQLUtils.toMySqlString(stmt);
Assert.assertEquals("CREATE TABLE employees ("
+ "\n\tid INT NOT NULL, "
+ "\n\tfname VARCHAR(30), "
+ "\n\tlname VARCHAR(30), "
+ "\n\thired DATE NOT NULL DEFAULT '1970-01-01', "
+ "\n\tseparated DATE NOT NULL DEFAULT '9999-12-31', "
+ "\n\tjob_code INT NOT NULL, "
+ "\n\tstore_id INT NOT NULL"
+ "\n)"
+ "\nPARTITION BY RANGE (store_id)"
+ "\n("
+ "\n\tPARTITION p0 VALUES LESS THAN (6),"
+ "\n\tPARTITION p1 VALUES LESS THAN (11),"
+ "\n\tPARTITION p2 VALUES LESS THAN (16),"
+ "\n\tPARTITION p3 VALUES LESS THAN MAXVALUE"
+ "\n)",
result);
print(stmtList);
Assert.assertEquals(1, stmtList.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(7, visitor.getColumns().size());
Assert.assertEquals(0, visitor.getConditions().size());
// Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("t_basic_store")));
}
}
@@ -0,0 +1,84 @@
/*
* 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.oceanbase;
import java.util.List;
import org.junit.Assert;
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 OceanbaseCreateTableTest_rangePartition3 extends MysqlTest {
public void test_0() throws Exception {
String sql = "CREATE TABLE employees ( " //
+ "id INT NOT NULL, " //
+ "fname VARCHAR(30), " //
+ "lname VARCHAR(30), " //
+ "hired DATE NOT NULL DEFAULT '1970-01-01', " //
+ "separated DATE NOT NULL DEFAULT '9999-12-31', " //
+ "job_code INT NOT NULL, store_id INT NOT NULL " //
+ ") PARTITION BY RANGE (job_code) " //
+ "( PARTITION p0 VALUES LESS THAN (100), " //
+ "PARTITION p1 VALUES LESS THAN (1000), " //
+ "PARTITION p2 VALUES LESS THAN (10000) "
+ ")"; //
MySqlStatementParser parser = new MySqlStatementParser(sql);
List<SQLStatement> stmtList = parser.parseStatementList();
SQLStatement stmt = stmtList.get(0);
String result = SQLUtils.toMySqlString(stmt);
Assert.assertEquals("CREATE TABLE employees ("
+ "\n\tid INT NOT NULL, "
+ "\n\tfname VARCHAR(30), "
+ "\n\tlname VARCHAR(30), "
+ "\n\thired DATE NOT NULL DEFAULT '1970-01-01', "
+ "\n\tseparated DATE NOT NULL DEFAULT '9999-12-31', "
+ "\n\tjob_code INT NOT NULL, "
+ "\n\tstore_id INT NOT NULL"
+ "\n)"
+ "\nPARTITION BY RANGE (job_code)"
+ "\n("
+ "\n\tPARTITION p0 VALUES LESS THAN (100),"
+ "\n\tPARTITION p1 VALUES LESS THAN (1000),"
+ "\n\tPARTITION p2 VALUES LESS THAN (10000)"
+ "\n)",
result);
print(stmtList);
Assert.assertEquals(1, stmtList.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(7, visitor.getColumns().size());
Assert.assertEquals(0, visitor.getConditions().size());
// Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("t_basic_store")));
}
}
@@ -0,0 +1,85 @@
/*
* 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.oceanbase;
import java.util.List;
import org.junit.Assert;
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 OceanbaseCreateTableTest_rangePartition4 extends MysqlTest {
public void test_0() throws Exception {
String sql = "CREATE TABLE employees ( " //
+ "id INT NOT NULL, " //
+ "fname VARCHAR(30), " //
+ "lname VARCHAR(30), " //
+ "hired DATE NOT NULL DEFAULT '1970-01-01', " //
+ "separated DATE NOT NULL DEFAULT '9999-12-31', " //
+ "job_code INT, store_id INT " //
+ ") PARTITION BY RANGE (YEAR(separated)) ( " //
+ "PARTITION p0 VALUES LESS THAN (1991), " //
+ "PARTITION p1 VALUES LESS THAN (1996), "
+ "PARTITION p2 VALUES LESS THAN (2001), "
+ "PARTITION p3 VALUES LESS THAN MAXVALUE )"; //
MySqlStatementParser parser = new MySqlStatementParser(sql);
List<SQLStatement> stmtList = parser.parseStatementList();
SQLStatement stmt = stmtList.get(0);
String result = SQLUtils.toMySqlString(stmt);
Assert.assertEquals("CREATE TABLE employees ("
+ "\n\tid INT NOT NULL, "
+ "\n\tfname VARCHAR(30), "
+ "\n\tlname VARCHAR(30), "
+ "\n\thired DATE NOT NULL DEFAULT '1970-01-01', "
+ "\n\tseparated DATE NOT NULL DEFAULT '9999-12-31', "
+ "\n\tjob_code INT, "
+ "\n\tstore_id INT"
+ "\n)"
+ "\nPARTITION BY RANGE (YEAR(separated))"
+ "\n("
+ "\n\tPARTITION p0 VALUES LESS THAN (1991),"
+ "\n\tPARTITION p1 VALUES LESS THAN (1996),"
+ "\n\tPARTITION p2 VALUES LESS THAN (2001),"
+ "\n\tPARTITION p3 VALUES LESS THAN MAXVALUE"
+ "\n)",
result);
print(stmtList);
Assert.assertEquals(1, stmtList.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(7, visitor.getColumns().size());
Assert.assertEquals(0, visitor.getConditions().size());
// Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("t_basic_store")));
}
}
@@ -0,0 +1,71 @@
/*
* 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.oceanbase;
import java.util.List;
import org.junit.Assert;
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 OceanbaseCreateTableTest_rangePartition5 extends MysqlTest {
public void test_0() throws Exception {
String sql = "CREATE TABLE tnrange (id INT, name VARCHAR(5) )"
+ " PARTITION BY RANGE(id) ( "
+ " PARTITION p1 VALUES LESS THAN (1), "
+ " PARTITION p2 VALUES LESS THAN MAXVALUE"
+ ");"; //
MySqlStatementParser parser = new MySqlStatementParser(sql);
List<SQLStatement> stmtList = parser.parseStatementList();
SQLStatement stmt = stmtList.get(0);
String result = SQLUtils.toMySqlString(stmt);
Assert.assertEquals("CREATE TABLE tnrange ("
+ "\n\tid INT, "
+ "\n\tname VARCHAR(5)"
+ "\n)"
+ "\nPARTITION BY RANGE (id)"
+ "\n("
+ "\n\tPARTITION p1 VALUES LESS THAN (1),"
+ "\n\tPARTITION p2 VALUES LESS THAN MAXVALUE"
+ "\n)",
result);
print(stmtList);
Assert.assertEquals(1, stmtList.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("t_basic_store")));
}
}
@@ -0,0 +1,75 @@
/*
* 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.oceanbase;
import java.util.List;
import org.junit.Assert;
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 OceanbaseCreateTableTest_subPartition extends MysqlTest {
public void test_0() throws Exception {
String sql = "CREATE TABLE ts (id INT, purchased DATE) " //
+ "PARTITION BY RANGE(YEAR(purchased)) " //
+ "SUBPARTITION BY HASH(TO_DAYS(purchased)) " //
+ "SUBPARTITIONS 2 ( " //
+ "PARTITION p0 VALUES LESS THAN (1990), " //
+ "PARTITION p1 VALUES LESS THAN (2000), " //
+ "PARTITION p2 VALUES LESS THAN MAXVALUE )"; //
MySqlStatementParser parser = new MySqlStatementParser(sql);
List<SQLStatement> stmtList = parser.parseStatementList();
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)) SUBPARTITIONS 2"
+ "\n("
+ "\n\tPARTITION p0 VALUES LESS THAN (1990),"
+ "\n\tPARTITION p1 VALUES LESS THAN (2000),"
+ "\n\tPARTITION p2 VALUES LESS THAN MAXVALUE"
+ "\n)",
result);
print(stmtList);
Assert.assertEquals(1, stmtList.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("t_basic_store")));
}
}
@@ -0,0 +1,90 @@
/*
* 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.oceanbase;
import java.util.List;
import org.junit.Assert;
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 OceanbaseCreateTableTest_subPartition2 extends MysqlTest {
public void test_0() throws Exception {
String sql = "CREATE TABLE ts (id INT, purchased DATE) " //
+ "PARTITION BY RANGE(YEAR(purchased)) " //
+ "SUBPARTITION BY HASH(TO_DAYS(purchased)) " //
+ "( "
+ " PARTITION p0 VALUES LESS THAN (1990) " //
+ " ( SUBPARTITION s0, SUBPARTITION s1 ), " //
+ " PARTITION p1 VALUES LESS THAN (2000) " //
+ " (SUBPARTITION s2, SUBPARTITION s3), " //
+ " PARTITION p2 VALUES LESS THAN MAXVALUE ( SUBPARTITION s4, SUBPARTITION s5 ) " //
+ ")"; //
MySqlStatementParser parser = new MySqlStatementParser(sql);
List<SQLStatement> stmtList = parser.parseStatementList();
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)",
result);
print(stmtList);
Assert.assertEquals(1, stmtList.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("t_basic_store")));
}
}
@@ -0,0 +1,81 @@
/*
* 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.oceanbase;
import java.util.List;
import org.junit.Assert;
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 OceanbaseCreateTableTest_subPartition3 extends MysqlTest {
public void test_0() throws Exception {
String sql = "CREATE TABLE ts (id INT, purchased DATE) " //
+ "PARTITION BY RANGE(YEAR(purchased)) " //
+ "SUBPARTITION BY HASH(TO_DAYS(purchased)) " //
+ "( PARTITION p0 VALUES LESS THAN (1990) " //
+ "( SUBPARTITION s0, SUBPARTITION s1 ), PARTITION p1 VALUES LESS THAN (2000), PARTITION p2 VALUES LESS THAN MAXVALUE ( SUBPARTITION s2, SUBPARTITION s3 ) )"; //
MySqlStatementParser parser = new MySqlStatementParser(sql);
List<SQLStatement> stmtList = parser.parseStatementList();
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)",
result);
print(stmtList);
Assert.assertEquals(1, stmtList.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("t_basic_store")));
}
}
@@ -0,0 +1,86 @@
/*
* 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.oceanbase;
import java.util.List;
import org.junit.Assert;
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 OceanbaseCreateTableTest_subPartition4 extends MysqlTest {
public void test_0() throws Exception {
String sql = "CREATE TABLE ts (id INT, purchased DATE) " //
+ "PARTITION BY RANGE(YEAR(purchased)) " //
+ "SUBPARTITION BY HASH(TO_DAYS(purchased)) " //
+ "( PARTITION p0 VALUES LESS THAN (1990) ( SUBPARTITION s0, SUBPARTITION s1 ), " //
+ "PARTITION p1 VALUES LESS THAN (2000) ( SUBPARTITION s0, SUBPARTITION s1 ), " //
+ "PARTITION p2 VALUES LESS THAN MAXVALUE ( SUBPARTITION s0, SUBPARTITION s1 ) )"; //
MySqlStatementParser parser = new MySqlStatementParser(sql);
List<SQLStatement> stmtList = parser.parseStatementList();
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)",
result);
print(stmtList);
Assert.assertEquals(1, stmtList.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("t_basic_store")));
}
}
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.druid.bvt.sql.mysql;
package com.alibaba.druid.bvt.sql.oceanbase;
import java.util.List;
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.druid.bvt.sql.mysql;
package com.alibaba.druid.bvt.sql.oceanbase;
import java.util.List;
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.druid.bvt.sql.mysql;
package com.alibaba.druid.bvt.sql.oceanbase;
import java.util.List;
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.druid.bvt.sql.mysql;
package com.alibaba.druid.bvt.sql.oceanbase;
import java.util.List;
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.druid.bvt.sql.mysql;
package com.alibaba.druid.bvt.sql.oceanbase;
import java.util.List;
@@ -0,0 +1,60 @@
/*
* 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.oceanbase;
import java.util.List;
import org.junit.Assert;
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 OceanbaseSelectPartitionTest extends MysqlTest {
public void test_0() throws Exception {
String sql = "SELECT * FROM tnhash partition(p0);"; //
MySqlStatementParser parser = new MySqlStatementParser(sql);
List<SQLStatement> stmtList = parser.parseStatementList();
SQLStatement stmt = stmtList.get(0);
String result = SQLUtils.toMySqlString(stmt);
Assert.assertEquals("SELECT *"
+ "\nFROM tnhash PARTITION (p0)",
result);
print(stmtList);
Assert.assertEquals(1, stmtList.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("t_basic_store")));
}
}