mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
remove adb testcase
This commit is contained in:
-945
@@ -1,945 +0,0 @@
|
||||
package com.alibaba.druid.bvt.sql.mysql.createTable;
|
||||
|
||||
import com.alibaba.druid.sql.MysqlTest;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import org.junit.Test;
|
||||
|
||||
public class ADB30_IntegrateUserPrivilege extends MysqlTest {
|
||||
|
||||
|
||||
@Test
|
||||
public void testView() throws Exception {
|
||||
// 首先用户创建一个view, 用户没有任何权限,不能read这张表
|
||||
parse("drop user if exists 'test', if exists 'test1', if exists 'test2', if exists 'test3';");
|
||||
parse("use test4dmp");
|
||||
parse("create view tt as select id from grade");
|
||||
|
||||
// 用户有物理table权限,不可以read这张表
|
||||
parse("grant select on grade to test identified by 'ccc'");
|
||||
|
||||
// 用户有global update权限,不可以read这张表
|
||||
parse("drop user if exists 'test', if exists 'test1', if exists 'test2', if exists 'test3';");
|
||||
parse("grant update on *.* to test");
|
||||
parse("grant update on * to test");
|
||||
|
||||
// 用户有view table select权限,可以read这张表
|
||||
parse("grant select on test4dmp.tt to test");
|
||||
parse("drop user if exists 'test', if exists 'test1', if exists 'test2', if exists 'test3';");
|
||||
|
||||
// 用户有global权限,可以read这张表
|
||||
parse("grant select on *.* to test");
|
||||
parse("drop user if exists 'test', if exists 'test1', if exists 'test2', if exists 'test3';");
|
||||
|
||||
// 用户有db权限,可以read这张表
|
||||
parse("grant select on * to test");
|
||||
parse("drop user if exists 'test', if exists 'test1', if exists 'test2', if exists 'test3';");
|
||||
|
||||
// 漏洞:用户有view table select权限,此时select view table和view映射的物理表,虽然物理表没有权限,但是仍然可以select.
|
||||
parse("grant select on test4dmp.tt to test");
|
||||
parse("drop user if exists 'test', if exists 'test1', if exists 'test2', if exists 'test3';");
|
||||
|
||||
// show create view权限
|
||||
parse("grant SHOW VIEW on test4dmp.tt to test");
|
||||
parse("grant Select on test4dmp.tt to test");
|
||||
parse("drop user if exists 'test', if exists 'test1', if exists 'test2', if exists 'test3';");
|
||||
|
||||
parse("grant SHOW VIEW on * to test");
|
||||
parse( "show create view tt");
|
||||
parse("grant Select on test4dmp.tt to test");
|
||||
parse( "show create view tt");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDropView() throws Exception {
|
||||
// 用户创建一个view
|
||||
parse("drop user if exists 'test', if exists 'test1', if exists 'test2', if exists 'test3';");
|
||||
parse("use test4dmp");
|
||||
parse("create view tt2 as select id from grade");
|
||||
|
||||
// 拥有global delete 权限,失败
|
||||
parse("grant delete on *.* to test");
|
||||
parse( "drop view test4dmp.tt2");
|
||||
|
||||
// 拥有other db drop权限,失败
|
||||
parse("grant drop on mysql.* to test");
|
||||
parse( "drop view test4dmp.tt2");
|
||||
|
||||
// 拥有other table drop 权限,失败
|
||||
parse("grant drop on test4dmp.tt to test");
|
||||
parse( "drop view test4dmp.tt2");
|
||||
|
||||
// 拥有global drop权限,成功
|
||||
parse("grant drop on *.* to test");
|
||||
parse("drop view test4dmp.tt2");
|
||||
|
||||
// 拥有db drop 权限,成功
|
||||
parse("drop user if exists 'test', if exists 'test1', if exists 'test2', if exists 'test3';");
|
||||
parse("create view tt2 as select id from grade");
|
||||
parse("grant drop on test4dmp.* to test");
|
||||
parse("drop view test4dmp.tt2");
|
||||
|
||||
// 拥有table drop权限,成功
|
||||
parse("drop user if exists 'test', if exists 'test1', if exists 'test2', if exists 'test3';");
|
||||
parse("create view tt2 as select id from grade");
|
||||
parse("grant drop on test4dmp.tt2 to test");
|
||||
parse("drop view test4dmp.tt2");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateView() throws Exception {
|
||||
// 用户创建一个view
|
||||
parse("drop user if exists 'test', if exists 'test1', if exists 'test2', if exists 'test3';");
|
||||
parse("use test4dmp");
|
||||
parse("grant select on *.* to test");
|
||||
|
||||
// 没有Create_view权限,有select权限,create view失败
|
||||
parse("create view tt2 as select id from grade");
|
||||
|
||||
// Create_view其他db权限,有select权限,create view失败
|
||||
parse("grant CREATE VIEW on mysql.* to test");
|
||||
parse("create view tt2 as select id from grade");
|
||||
|
||||
// Create_view权限准确,有select权限,create view失败
|
||||
parse("grant CREATE VIEW on test4dmp.* to test");
|
||||
parse("create view tt2 as select id from grade");
|
||||
parse("drop view test4dmp.tt2");
|
||||
parse("drop user if exists 'test', if exists 'test1', if exists 'test2', if exists 'test3';");
|
||||
|
||||
// table级别create view, column级别select 级别校验
|
||||
parse("grant CREATE VIEW on test4dmp.tt3 to test");
|
||||
parse("grant select(id) on test4dmp.grade to test");
|
||||
parse("create view tt2 as select id from grade");
|
||||
|
||||
// db级别create view, table级别select 级别校验
|
||||
parse("drop user if exists 'test', if exists 'test1', if exists 'test2', if exists 'test3';");
|
||||
parse("grant CREATE VIEW on test4dmp.* to test");
|
||||
parse("grant select on test4dmp.grade to test");
|
||||
parse("create view tt3 as select id from grade limit 1");
|
||||
|
||||
// db级别create view, table级别select 级别校验 失败
|
||||
parse("drop user if exists 'test', if exists 'test1', if exists 'test2', if exists 'test3';");
|
||||
parse("grant CREATE VIEW on test4dmp.* to test");
|
||||
parse("grant select on test4dmp.test to test");
|
||||
parse("drop view test4dmp.tt3");
|
||||
parse("create view tt3 as select id from grade limit 1");
|
||||
|
||||
// create view replace语法,需要DROP权限
|
||||
parse("drop user if exists 'test', if exists 'test1', if exists 'test2', if exists 'test3';");
|
||||
parse("grant CREATE VIEW on test4dmp.* to test");
|
||||
parse("grant select on test4dmp.grade to test");
|
||||
parse("create or replace view tt3 as select id from grade limit 1");
|
||||
|
||||
parse("grant DROP on test4dmp.grade to test");
|
||||
parse("create or replace view tt3 as select id from grade limit 1");
|
||||
|
||||
parse("grant DROP on test4dmp.tt3 to test");
|
||||
parse("create or replace view tt3 as select id from grade limit 1");
|
||||
|
||||
// create view replace语法,需要DROP权限
|
||||
parse("drop user if exists 'test', if exists 'test1', if exists 'test2', if exists 'test3';");
|
||||
parse("grant CREATE VIEW on test4dmp.* to test");
|
||||
parse("grant select on test4dmp.grade to test");
|
||||
parse("grant DROP on test4dmp.* to test");
|
||||
parse("create or replace view tt3 as select id from grade limit 1");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShowCreateTable() throws Exception {
|
||||
parse("drop user if exists 'test', if exists 'test1', if exists 'test2', if exists 'test3';");
|
||||
parse("use test4dmp");
|
||||
parse("grant select on *.* to test");
|
||||
|
||||
parse("show create table test4dmp.test");
|
||||
parse("drop user if exists 'test', if exists 'test1', if exists 'test2', if exists 'test3';");
|
||||
|
||||
parse("grant update on *.* to test");
|
||||
parse("show create table test4dmp.test");
|
||||
|
||||
parse("grant select on test4dmp.test to test");
|
||||
parse("show create table test4dmp.test");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_1() throws Exception {
|
||||
SQLStatement parse = parse("CREATE USER IF NOT EXISTS 'adb_system' IDENTIFIED BY 'qpzkC6cgQGPxte5';");
|
||||
System.out.println(parse);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInsertSelect() throws Exception {
|
||||
// 验证sql: insert into test select * from test02 where id=15;
|
||||
// 没有权限场景下失败
|
||||
parse("drop user if exists 'test', if exists 'test1', if exists 'test2', if exists 'test3';");
|
||||
|
||||
parse("create user if not exists 'test'@'%' IDENTIFIED BY 'ccc';");
|
||||
parse("drop table if exists test4p.tt2");
|
||||
parse("create table test4p.tt2(id int, id2 int, primary key (id)) DISTRIBUTE BY BROADCAST;");
|
||||
|
||||
parse("create table test4p.tt3(id int, id2 int, primary key (id)) DISTRIBUTE BY BROADCAST;");
|
||||
parse("insert into test4p.tt3 values(4,2);");
|
||||
parse("insert into test4p.tt3 values(5,2);");
|
||||
parse("insert into test4p.tt3 values(6,2);");
|
||||
parse("insert into tt2 select * from tt3 where id=1;");
|
||||
parse("insert into test4p.tt2 select * from test4p.tt3 where id=1;");
|
||||
|
||||
parse("grant all on test4p.tt to test@'%' identified by 'ccc';");
|
||||
parse("insert into tt2 select * from tt3 where id=1;");
|
||||
parse("insert into test4p.tt2 select * from test4p.tt3 where id=1;");
|
||||
parse("grant select on test4p.tt3 to test@'%' identified by 'ccc';");
|
||||
parse("insert into tt2 select * from tt3 where id=1;");
|
||||
parse("insert into test4p.tt2 select * from test4p.tt3 where id=1;");
|
||||
parse("grant insert on test4p.tt2 to test@'%' identified by 'ccc';");
|
||||
parse("drop user if exists 'test';");
|
||||
|
||||
// 提供了db级别all权限的场景下,可以成功插入数据
|
||||
// 跑的时间太长,忽略掉
|
||||
// parse("grant all on test4p.* to test@'%' identified by 'ccc';");
|
||||
// parse("insert into tt2 select * from tt3 where id=10;");
|
||||
// parse("drop user if exists 'test';");
|
||||
|
||||
// 提供global级别all权限场景下,可以成功插入数据
|
||||
// 跑的时间太长,忽略掉
|
||||
// parse("grant all on *.* to test@'%' identified by 'ccc';");
|
||||
// parse("insert into tt2 select * from tt3 where id=10;");
|
||||
// parse("drop user if exists 'test';");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateDropUser() throws Exception {
|
||||
parse("use mysql");
|
||||
parse("select * from mysql.user");
|
||||
parse("drop user if exists 'test', if exists 'test1', if exists 'test2', if exists 'test3';");
|
||||
|
||||
parse("create user if not exists 'test'@'%' IDENTIFIED BY 'testpasswd';");
|
||||
parse("select user()");
|
||||
parse("select 1");
|
||||
parse( "select * from mysql.user");
|
||||
|
||||
parse("drop user if exists 'test'");
|
||||
|
||||
parse("create user if not exists test@'%' IDENTIFIED BY password 'testpasswd';");
|
||||
|
||||
// create redundance fail
|
||||
parse("create user test@'%s' IDENTIFIED BY password 'testpasswd'");
|
||||
|
||||
parse("drop user 'test'");
|
||||
// drop not exists fail
|
||||
parse("drop user 'test'");
|
||||
|
||||
// create three user
|
||||
parse("create user if not exists test1@'%' identified by 'aa2', if not exists test2@'%' identified by password 'bb', test3;");
|
||||
|
||||
parse("grant update(user,host),insert(user),select on mysql.user to test1@'%' identified by 'ccc';");
|
||||
parse("grant update,select on *.* to test1@'%' identified by 'ccc';");
|
||||
parse("grant update,select on mysql.* to test1@'%' identified by 'ccc';");
|
||||
|
||||
parse("drop user if exists 'test', if exists 'test1', if exists 'test2', if exists 'test3';");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRenameUser() throws Exception {
|
||||
parse("drop user if exists 'test', if exists 'test1', if exists 'test2', if exists 'test3';");
|
||||
|
||||
// 具有 global/db/table/column 权限的用户 , rename一次
|
||||
parse("create user test@'%' identified by '111111';");
|
||||
parse("grant select,update on *.* to test@'%';");
|
||||
parse("grant update on mysql.* to test@'%';");
|
||||
parse("grant update on mysql.user to test@'%';");
|
||||
parse("grant update(host) on mysql.user to test@'%';");
|
||||
|
||||
parse("rename user test@'%' to test1@'%';");
|
||||
parse("select * from mysql.user");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetPassword() throws Exception {
|
||||
parse("drop user if exists 'test', if exists 'test1', if exists 'test2', if exists 'test3'");
|
||||
parse("create user test@'%' IDENTIFIED BY 'testpasswd';");
|
||||
|
||||
parse("set password for 'test'@'%' = 'ddd';");
|
||||
|
||||
parse("set password for 'test'@'%' = password('ddd')");
|
||||
|
||||
parse("drop user if exists 'test', if exists 'test1', if exists 'test2', if exists 'test3'");
|
||||
parse("create user test@'%' IDENTIFIED BY password 'testpasswd'");
|
||||
parse("set password for 'test'@'%' = password('ddd')");
|
||||
|
||||
parse("set password for 'test' = password('eee')");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGrantRevoke() throws Exception {
|
||||
parse("drop user if exists 'test', if exists 'test1', if exists 'test2', if exists 'test3';");
|
||||
|
||||
parse("grant select on *.* to test@'%' identified by 'ccc';");
|
||||
|
||||
parse("grant all on *.* to test@'%' identified by 'ccc';");
|
||||
|
||||
parse("grant grant option on *.* to test@'%' identified by 'ccc';");
|
||||
|
||||
parse("revoke select, grant option on *.* from test@'%';");
|
||||
|
||||
parse("grant select on aa.* to test@'%' identified by 'ddd';");
|
||||
|
||||
parse("grant update,delete on aa.* to test@'%' identified by 'ccc' with grant option;");
|
||||
|
||||
parse("grant update,delete on aa.bb to test@'%' identified by 'ccc' with grant option;");
|
||||
parse("revoke update,delete on aa.bb from test@'%'");
|
||||
|
||||
// parse("grant update(dd,cc),delete(dd),select on aa.bb to test1@'%' identified by 'ccc';");
|
||||
|
||||
parse("grant update(user,host),insert(user),select on mysql.user to test1@'%' identified by 'ccc';");
|
||||
|
||||
parse("revoke update(user),select on mysql.user from test1@'%';");
|
||||
|
||||
parse("grant select, update on db.tbl to 'test'");
|
||||
|
||||
parse("use mysql");
|
||||
parse("drop user if exists 'test', if exists 'test1', if exists 'test2', if exists 'test3';");
|
||||
parse("grant select, update on host to 'test';");
|
||||
parse("revoke all privileges on host from 'test'");
|
||||
parse("revoke all on host from 'test'");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testUserADUSExecuteSQL() throws Exception {
|
||||
parse("drop user if exists 'test';");
|
||||
|
||||
// global授权selelct, 可以select所有表
|
||||
parse("grant select on *.* to test@'%' identified by 'ccc';");
|
||||
parse("use mysql");
|
||||
parse("select * from user;");
|
||||
parse("select * from mysql.user;");
|
||||
parse("select * from INFORMATION_SCHEMA.KEPLER_META_TABLES;");
|
||||
parse("drop user if exists 'test';");
|
||||
|
||||
// global授权all, 可以select所有表
|
||||
parse("grant all on *.* to test@'%' identified by 'ccc';");
|
||||
parse("select * from user;");
|
||||
parse("select * from mysql.user;");
|
||||
parse("select * from INFORMATION_SCHEMA.KEPLER_META_TABLES;");
|
||||
parse("drop user if exists 'test';");
|
||||
|
||||
// db级别授权all, 可以select mysql表,不可以select INFORMATION_SCHEMA表
|
||||
parse("grant all on mysql.* to test@'%' identified by 'ccc';");
|
||||
parse("select * from user;");
|
||||
parse("select * from mysql.user;");
|
||||
parse( "select * from INFORMATION_SCHEMA.KEPLER_META_TABLES;");
|
||||
|
||||
// db级别授权select, 可以select mysql表,不可以select INFORMATION_SCHEMA表
|
||||
parse("revoke all on mysql.* from test@'%';");
|
||||
parse("grant select on mysql.* to test@'%' identified by 'ccc';");
|
||||
parse("select * from user");
|
||||
parse("select * from db");
|
||||
parse("select * from mysql.user");
|
||||
parse("select * from mysql.db");
|
||||
parse( "select * from INFORMATION_SCHEMA.KEPLER_META_TABLES;");
|
||||
|
||||
// table级别授权all, 可以select mysql表,不可以select INFORMATION_SCHEMA表和mysql库其他表
|
||||
parse("revoke select on mysql.* from test@'%';");
|
||||
parse("grant all on mysql.user to test@'%' identified by 'ccc';");
|
||||
parse( "select * from INFORMATION_SCHEMA.KEPLER_META_TABLES;");
|
||||
parse( "select * from db;");
|
||||
parse( "select * from mysql.db;");
|
||||
|
||||
// table级别授权select, 可以select mysql表,不可以select INFORMATION_SCHEMA表和mysql库其他表
|
||||
parse("revoke all on mysql.user from test@'%';");
|
||||
parse("grant select on mysql.user to test@'%' identified by 'ccc';");
|
||||
parse( "select * from INFORMATION_SCHEMA.KEPLER_META_TABLES;");
|
||||
parse( "select * from db;");
|
||||
parse( "select * from mysql.db;");
|
||||
parse("drop user if exists 'test';");
|
||||
|
||||
// column级别授权select host, 可以select mysql表,不可以select INFORMATION_SCHEMA表和mysql库其他表
|
||||
// mysql/information_schema 这些内存表没有做指定列获取的sql优化, 所以这里肯定会获取不到
|
||||
// parse("revoke select on mysql.user from test@'%';");
|
||||
// parse("grant select(host) on mysql.user to test@'%' identified by 'ccc';");
|
||||
// parse("select host from mysql.user;");
|
||||
// parse("select user from mysql.user;");
|
||||
// parse("select * from INFORMATION_SCHEMA.KEPLER_META_TABLES");
|
||||
// parse("select * from mysql.db");
|
||||
// parse("drop user if exists 'test'");
|
||||
|
||||
// 创建表, 并做insert校验
|
||||
parse("use test4p");
|
||||
parse("create table test4p.tt(id int) DISTRIBUTE BY BROADCAST;");
|
||||
|
||||
// global select权限不可以 insert 数据
|
||||
parse("grant select on *.* to test@'%' identified by 'ccc';");
|
||||
parse("select * from tt;");
|
||||
parse( "insert into tt values(3);");
|
||||
parse("select * from test4p.tt;");
|
||||
parse( "insert into test4p.tt values(1);");
|
||||
|
||||
// global insert 权限可以 insert 数据
|
||||
parse("grant insert on *.* to test@'%' identified by 'ccc';");
|
||||
parse("select * from tt;");
|
||||
parse("insert into tt values(2);");
|
||||
parse("select * from test4p.tt;");
|
||||
parse("insert into test4p.tt values(1);");
|
||||
parse("drop user if exists 'test';");
|
||||
|
||||
// db insert 权限可以 insert 数据
|
||||
parse("grant insert on test4p.* to test@'%' identified by 'ccc';");
|
||||
parse( "select * from tt;");
|
||||
parse("insert into tt values(1);");
|
||||
parse( "select * from test4p.tt;");
|
||||
parse("insert into test4p.tt values(1);");
|
||||
parse("drop user if exists 'test';");
|
||||
|
||||
// 其他db insert 权限不可以 insert 数据
|
||||
parse("grant insert on mysql.* to test@'%' identified by 'ccc';");
|
||||
parse( "select * from tt;");
|
||||
parse( "insert into tt values(1);");
|
||||
parse( "select * from test4p.tt;");
|
||||
parse( "insert into test4p.tt values(1);");
|
||||
parse("drop user if exists 'test';");
|
||||
|
||||
// table insert 权限不可以 insert 数据
|
||||
parse("grant insert on test4p.tt to test@'%' identified by 'ccc';");
|
||||
parse( "select * from tt;");
|
||||
parse("insert into tt values(1);");
|
||||
parse( "select * from test4p.tt;");
|
||||
parse("insert into test4p.tt values(1);");
|
||||
parse("drop user if exists 'test';");
|
||||
|
||||
// column insert 权限可以 insert 数据
|
||||
parse("grant insert(id) on test4p.tt to test@'%' identified by 'ccc';");
|
||||
parse( "select * from tt;");
|
||||
parse("insert into tt values(1);");
|
||||
parse( "select * from test4p.tt;");
|
||||
parse("insert into test4p.tt values(1);");
|
||||
parse("insert into test4p.test values(1);");
|
||||
parse("drop user if exists 'test';");
|
||||
|
||||
////////// test update
|
||||
parse("create table test4p.tt2(id int, id2 int, primary key (id)) DISTRIBUTE BY BROADCAST;");
|
||||
// global insert权限不可以 update 数据
|
||||
parse("grant insert on *.* to test@'%' identified by 'ccc';");
|
||||
parse("update tt2 set id2=2;");
|
||||
parse("update test4p.tt2 set id2=2;");
|
||||
parse("drop user if exists 'test';");
|
||||
|
||||
// global update权限可以 update 数据
|
||||
parse("grant update on *.* to test@'%' identified by 'ccc';");
|
||||
parse("update tt2 set id2=2;");
|
||||
parse("update test4p.tt2 set id2=2;");
|
||||
parse("drop user if exists 'test';");
|
||||
|
||||
// db update权限可以 update 数据
|
||||
parse("grant update on test4p.* to test@'%' identified by 'ccc';");
|
||||
parse("update tt2 set id2=2;");
|
||||
parse("update test4p.tt2 set id2=2;");
|
||||
parse("drop user if exists 'test';");
|
||||
|
||||
// 其他db update权限不可以 update 数据
|
||||
parse("grant update on mysql.* to test@'%' identified by 'ccc';");
|
||||
parse("update tt2 set id2=2;");
|
||||
parse("update test4p.tt2 set id2=2;");
|
||||
|
||||
// table update权限可以 update 数据
|
||||
parse("grant update on test4p.tt2 to test@'%' identified by 'ccc';");
|
||||
parse("update tt2 set id2=2;");
|
||||
parse("update test4p.tt2 set id2=2;");
|
||||
parse("drop user if exists 'test';");
|
||||
|
||||
// 其他table update权限不可以 update 数据
|
||||
parse("grant update on test4p.t3 to test@'%' identified by 'ccc';");
|
||||
parse("update tt2 set id2=2;");
|
||||
parse("update test4p.tt2 set id2=2;");
|
||||
parse("drop user if exists 'test';");
|
||||
|
||||
// column update 权限可以 update 数据
|
||||
parse("grant update(id2) on test4p.tt2 to test@'%' identified by 'ccc';");
|
||||
parse("update tt2 set id2=2;");
|
||||
parse("update test4p.tt2 set id2=2;");
|
||||
parse("drop user if exists 'test';");
|
||||
|
||||
// all 权限可以 update 数据
|
||||
parse("grant all on test4p.tt2 to test@'%' identified by 'ccc';");
|
||||
parse("update tt2 set id2=2;");
|
||||
parse("update test4p.tt2 set id2=2;");
|
||||
parse("drop user if exists 'test';");
|
||||
|
||||
////////// test delete
|
||||
// global delete 权限可以 delete 数据
|
||||
parse("grant delete on *.* to test@'%' identified by 'ccc';");
|
||||
parse("delete from tt2 where id2=2;");
|
||||
parse("delete from test4p.tt2 where id2=2;");
|
||||
parse("drop user if exists 'test';");
|
||||
|
||||
// db delete 权限可以 delete 数据
|
||||
parse("grant delete on test4p.* to test@'%' identified by 'ccc';");
|
||||
parse("delete from tt2 where id2=2;");
|
||||
parse("delete from test4p.tt2 where id2=2;");
|
||||
parse("drop user if exists 'test';");
|
||||
|
||||
// 其他db delete 权限不可以 delete 数据
|
||||
parse("grant delete on mysql.* to test@'%' identified by 'ccc';");
|
||||
parse("delete from tt2 where id2=2;");
|
||||
parse("delete from test4p.tt2 where id2=2;");
|
||||
parse("drop user if exists 'test';");
|
||||
|
||||
// table delete 权限可以 delete 数据
|
||||
parse("grant delete on test4p.tt2 to test@'%' identified by 'ccc';");
|
||||
parse("delete from tt2 where id2=2;");
|
||||
parse("drop user if exists 'test';");
|
||||
|
||||
// table all 权限可以 delete 数据
|
||||
parse("grant all on test4p.tt2 to test@'%' identified by 'ccc';");
|
||||
parse("delete from tt2 where id2=2;");
|
||||
parse("drop user if exists 'test';");
|
||||
|
||||
// 其他table all 权限不可以 delete 数据
|
||||
parse("grant all on test4p.tt to test@'%' identified by 'ccc';");
|
||||
parse("delete from tt2 where id2=2;");
|
||||
parse("delete from test4p.tt2 where id2=2;");
|
||||
parse("drop user if exists 'test';");
|
||||
|
||||
// 验证sql: truncate
|
||||
// 没有权限场景下会失败
|
||||
parse("create table test4p.truncatetestt(id int, id2 int, primary key (id)) DISTRIBUTE BY BROADCAST;");
|
||||
parse("truncate table truncatetestt");
|
||||
parse("truncate table test4p.truncatetestt");
|
||||
parse("grant all on mysql.* to test@'%' identified by 'ccc';");
|
||||
parse("truncate table truncatetestt");
|
||||
parse("truncate table test4p.truncatetestt");
|
||||
parse("grant DROP on test4p.* to test@'%' identified by 'ccc';");
|
||||
parse("truncate table truncatetestt");
|
||||
parse("truncate table test4p.truncatetestt");
|
||||
parse("drop user if exists 'test';");
|
||||
|
||||
// 存在all权限场景下成功
|
||||
parse("grant ALL on *.* to test@'%' identified by 'ccc';");
|
||||
parse("truncate table truncatetestt");
|
||||
parse("truncate table test4p.truncatetestt");
|
||||
parse("drop user if exists 'test';");
|
||||
|
||||
// 验证sql: replace into test(id,col1,col2,col3) values(22,'row22','2018-01-01',3.1);
|
||||
parse("grant ALL on *.* to test@'%' identified by 'ccc';");
|
||||
parse("replace into truncatetestt values(4,2);");
|
||||
parse("replace into test4p.truncatetestt values(4,2);");
|
||||
parse("drop user if exists 'test';");
|
||||
|
||||
parse("grant ALL on test4p.truncatetestt to test@'%' identified by 'ccc';");
|
||||
parse("replace into truncatetestt values(4,2);");
|
||||
parse("replace into test4p.truncatetestt values(4,2);");
|
||||
parse("drop user if exists 'test';");
|
||||
|
||||
parse("grant insert(id, id2) on test4p.truncatetestt to test@'%' identified by 'ccc';");
|
||||
parse("replace into truncatetestt values(4,2);");
|
||||
parse("replace into test4p.truncatetestt values(4,2);");
|
||||
parse("drop user if exists 'test';");
|
||||
|
||||
parse("grant select on test4p.* to test@'%' identified by 'ccc';");
|
||||
parse("replace into truncatetestt values(4,2);");
|
||||
parse("replace into test4p.truncatetestt values(4,2);");
|
||||
parse("drop user if exists 'test';");
|
||||
|
||||
parse("grant select on *.* to test@'%' identified by 'ccc';");
|
||||
parse("replace into truncatetestt values(4,2);");
|
||||
parse("replace into test4p.truncatetestt values(4,2);");
|
||||
parse("drop user if exists 'test';");
|
||||
|
||||
// 验证sql: insert overwrite into test select * from test02 where id=3;
|
||||
parse("insert overwrite into test select * from test02 where id=3;");
|
||||
parse("insert into truncatetestt values(1, 2) on duplicate key update id2=2;");
|
||||
parse("insert into test4p.truncatetestt values(1, 2) on duplicate key update id2=2;");
|
||||
parse("grant insert on test4p.* to test@'%' identified by 'ccc';");
|
||||
parse("insert into truncatetestt values(1, 2) on duplicate key update id2=2;");
|
||||
parse("insert into test4p.truncatetestt values(1, 2) on duplicate key update id2=2;");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUserExecSQLAboutPrivilege() throws Exception {
|
||||
parse("drop user if exists 'test', if exists 'test1', if exists 'test2'");
|
||||
|
||||
// 创建一个空用户,没有任何权限是无法 CREATE USER, DROP USER, REVOKE USER, GRANT, SET PASSWORD的
|
||||
parse("create user test@'%' identified by 'ccc';");
|
||||
parse("grant grant option on *.* to test1@'%' identified by 'ccc';");
|
||||
parse( "select * from mysql.user;");
|
||||
parse("create user if not exists 'test1'@'%';");
|
||||
parse("grant grant option on *.* to test1@'%';");
|
||||
parse("drop user if exists 'test1'@'%';");
|
||||
parse("revoke grant option on *.* from test1@'%';");
|
||||
parse("set password for 'test1'@'%' = password('ddd')");
|
||||
parse("drop user if exists 'test', if exists 'test1', if exists 'test2'");
|
||||
|
||||
// grant 权限只能执行grant操作
|
||||
parse("grant grant option, create user on *.* to test@'%'");
|
||||
parse("create user if not exists 'test1'@'%';");
|
||||
parse( "select * from mysql.user;");
|
||||
parse("grant grant option on *.* to test1@'%'");
|
||||
parse("drop user if exists 'test', if exists 'test1', if exists 'test2'");
|
||||
|
||||
// CREATE_USER 权限可以执行 create user操作
|
||||
parse("grant grant option, create user on *.* to test@'%'");
|
||||
parse("create user if not exists 'test1'@'%';");
|
||||
parse("grant grant option on *.* to test1@'%';");
|
||||
parse("revoke grant option on *.* from test1@'%';");
|
||||
parse("rename user 'test1' to 'test2'");
|
||||
parse("drop user 'test2'@'%';");
|
||||
parse("drop user if exists 'test', if exists 'test1', if exists 'test2'");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testCreateTable() throws Exception {
|
||||
// table的all权限可以create table, drop table
|
||||
parse("drop user if exists 'test';");
|
||||
parse("grant all on test4p.ttc3 to test@'%' identified by 'ccc';");
|
||||
parse("use test4p");
|
||||
parse("create table ttc3(id int, id2 int, primary key (id)) DISTRIBUTE BY BROADCAST;");
|
||||
parse("drop table ttc3");
|
||||
parse("drop user if exists 'test';");
|
||||
|
||||
// db的all权限可以create table
|
||||
parse("grant all on test4p.* to test@'%' identified by 'ccc';");
|
||||
parse("create table ttc4(id int, id2 int, primary key (id)) DISTRIBUTE BY BROADCAST;");
|
||||
parse("drop table test4p.ttc4");
|
||||
parse("drop user if exists 'test';");
|
||||
|
||||
// db的create权限可以create table
|
||||
parse("grant CREATE on test4p.* to test@'%' identified by 'ccc';");
|
||||
parse("create table ttc5(id int, id2 int, primary key (id)) DISTRIBUTE BY BROADCAST;");
|
||||
parse("drop table test4p.ttc5");
|
||||
parse("drop user if exists 'test';");
|
||||
|
||||
// db的update权限不可以create table
|
||||
parse("grant UPDATE on test4p.* to test@'%' identified by 'ccc';");
|
||||
parse("create table ttc6(id int, id2 int, primary key (id)) DISTRIBUTE BY BROADCAST;");
|
||||
parse("drop user if exists 'test';");
|
||||
|
||||
// global的update权限不可以create table
|
||||
parse("grant UPDATE on *.* to test@'%' identified by 'ccc';");
|
||||
parse("create table test4p.ttc7(id int, id2 int, primary key (id)) DISTRIBUTE BY BROADCAST;");
|
||||
parse("drop user if exists 'test';");
|
||||
|
||||
// table的create权限可以create table
|
||||
parse("grant CREATE on test4p.ttc8 to test@'%' identified by 'ccc';");
|
||||
parse("create table ttc8(id int, id2 int, primary key (id)) DISTRIBUTE BY BROADCAST;");
|
||||
parse("drop user if exists 'test';");
|
||||
|
||||
// table的drop权限可以drop table
|
||||
parse("grant DROP,CREATE on test4p.ttc9 to test@'%' identified by 'ccc';");
|
||||
parse("create table ttc9(id int, id2 int, primary key (id)) DISTRIBUTE BY BROADCAST;");
|
||||
parse("drop table ttc9");
|
||||
parse("drop user if exists 'test';");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDropDatabase() throws Exception {
|
||||
parse("drop user if exists 'test';");
|
||||
// global的insert权限,不可以drop database
|
||||
parse("grant INSERT on *.* to test@'%' identified by 'ccc';");
|
||||
parse("create database test5p");
|
||||
parse("drop database test5p");
|
||||
parse("drop user if exists 'test';");
|
||||
|
||||
// db的drop权限,可以drop database
|
||||
parse("grant DROP on test5p.* to test@'%' identified by 'ccc';");
|
||||
parse("drop database test5p");
|
||||
parse("drop user if exists 'test';");
|
||||
|
||||
// global的all权限,可以drop database
|
||||
parse("grant ALL on *.* to test@'%' identified by 'ccc';");
|
||||
parse("create database test5p");
|
||||
parse("drop database test5p");
|
||||
parse("drop user if exists 'test';");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAlterTable() throws Exception {
|
||||
parse("grant INSERT on *.* to test@'%' identified by 'ccc';");
|
||||
parse("use test4p;");
|
||||
parse("drop user if exists 'test';");
|
||||
|
||||
parse("create table test4p.talt1(id int, id2 int, primary key (id)) DISTRIBUTE BY BROADCAST;");
|
||||
parse("alter table talt1 add column id3 int;");
|
||||
|
||||
parse("grant ALTER on *.* to test@'%' identified by 'ccc';");
|
||||
parse("alter table test4p.talt1 add column id3 int;");
|
||||
parse("alter table talt1 add column id3 int;");
|
||||
parse("grant CREATE on *.* to test@'%' identified by 'ccc';");
|
||||
parse("alter table test4p.talt1 add column id3 int;");
|
||||
parse("alter table talt1 add column id3 int;");
|
||||
parse("grant INSERT on *.* to test@'%' identified by 'ccc';");
|
||||
parse("alter table test4p.talt1 add column id3 int;");
|
||||
parse("alter table talt1 add column id6 int;");
|
||||
parse("drop user if exists 'test';");
|
||||
|
||||
// db/table级别授权,也可以执行命令
|
||||
parse("grant CREATE on test4p.* to test@'%' identified by 'ccc';");
|
||||
parse("grant INSERT on test4p.* to test@'%' identified by 'ccc';");
|
||||
parse("grant ALTER on test4p.talt1 to test@'%' identified by 'ccc';");
|
||||
parse("alter table test4p.talt1 add column id4 int;");
|
||||
parse("alter table talt1 add column id5 int;");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateInto() throws Exception {
|
||||
parse("grant ALTER on *.* to test@'%' identified by 'ccc';");
|
||||
parse("use test4p;");
|
||||
parse("drop user if exists 'test';");
|
||||
|
||||
parse("create table test4p.updatet4p(id int, id2 int, primary key (id)) DISTRIBUTE BY BROADCAST;");
|
||||
|
||||
// parse("update into test4p.updatet4p values(1, 1)");
|
||||
// parse("update into updatet4p values(1, 1)");
|
||||
// parse("update into test4p.updatet4p values(1, 2)");
|
||||
// parse("update into updatet4p values(1, 2)");
|
||||
parse("grant SELECT on test4p.* to test@'%' identified by 'ccc';");
|
||||
// parse("update into test4p.updatet4p values(1, 2)");
|
||||
// parse("update into updatet4p values(1, 2)");
|
||||
parse("grant UPDATE on test4p.updatet4p to test@'%' identified by 'ccc';");
|
||||
// parse("update into test4p.updatet4p values(1, 2)");
|
||||
// parse("update into updatet4p values(1, 2)");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRevokeAll() throws Exception {
|
||||
parse("drop user if exists 'test', if exists 'test1', if exists 'test2', if exists 'test3';");
|
||||
parse("grant select,update,delete on *.* to test1@'%' identified by 'ccc';");
|
||||
parse("grant select,update,delete on mysql.* to test1@'%' identified by 'ccc';");
|
||||
parse("grant select,update,delete on mysql.host to test1@'%' identified by 'ccc';");
|
||||
parse("grant update(host) on mysql.host to test1@'%' identified by 'ccc';");
|
||||
|
||||
parse("grant select,update,delete on *.* to test@'%' identified by 'ccc';");
|
||||
parse("use mysql");
|
||||
|
||||
// 没有授权CREATE USER权限的时候, revoke失败
|
||||
parse("revoke all privileges, grant option from test1;");
|
||||
parse("grant CREATE USER on *.* to test@'%';");
|
||||
parse("revoke all privileges from test1;");
|
||||
parse("revoke all from test1;");
|
||||
parse("revoke grant option from test1;");
|
||||
parse("revoke all privileges, grant option on *.* from test1;");
|
||||
|
||||
parse("revoke all privileges, grant option from test1;");
|
||||
}
|
||||
|
||||
public void grantDone() throws Exception {
|
||||
parse("grant select on *.* to test1;");
|
||||
parse("grant select on mysql.* to test1;");
|
||||
parse("grant select on mysql.host to test1;");
|
||||
parse("grant select(host) on mysql.host to test1;");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRevokeGrant2() throws Exception {
|
||||
parse("drop user if exists 'test', if exists 'test1', if exists 'test2', if exists 'test3';");
|
||||
// 如果用户有global权限grant select,能够grant global/db/table/column select权限
|
||||
parse("grant select, CREATE USER on *.* to test@'%' with grant option;");
|
||||
parse("grant select on *.* to test1;");
|
||||
parse("grant select on mysql.* to test1;");
|
||||
parse("grant select on mysql.host to test1;");
|
||||
parse("grant select(host) on mysql.host to test1;");
|
||||
parse("drop user if exists 'test', if exists 'test1', if exists 'test2', if exists 'test3';");
|
||||
parse("grant select, grant option, CREATE USER on *.* to test@'%';");
|
||||
parse("grant select on *.* to test1;");
|
||||
parse("grant select on mysql.* to test1;");
|
||||
parse("grant select on mysql.host to test1;");
|
||||
parse("grant select(host) on mysql.host to test1;");
|
||||
parse("drop user if exists 'test', if exists 'test1', if exists 'test2', if exists 'test3';");
|
||||
|
||||
// 如果用户有db权限grant select, 不能够grant global的select,能够grant db/table/column.
|
||||
parse("grant select on mysql.* to test@'%' with grant option;");
|
||||
parse("grant CREATE USER on *.* to test@'%'");
|
||||
parse("grant select on *.* to test1;");
|
||||
parse("grant select on mysql.* to test1;");
|
||||
parse("grant update on mysql.* to test1;");
|
||||
parse("grant select on mysql.host to test1;");
|
||||
parse("grant update on mysql.host to test1;");
|
||||
parse("grant select(host) on mysql.host to test1;");
|
||||
parse("grant update(host) on mysql.host to test1;");
|
||||
parse("drop user if exists 'test', if exists 'test1', if exists 'test2', if exists 'test3';");
|
||||
|
||||
// 如果用户有table权限grant select, 不能够grant global/db. 能够grant table/column.
|
||||
parse("grant select on mysql.host to test@'%' with grant option;");
|
||||
parse("grant CREATE USER on *.* to test@'%'");
|
||||
parse("grant select on *.* to test1;");
|
||||
parse("grant select on mysql.* to test1;");
|
||||
parse("grant select on mysql.host to test1;");
|
||||
parse("grant update on mysql.host to test1;");
|
||||
parse("grant select(host) on mysql.host to test1;");
|
||||
parse("grant update(host) on mysql.host to test1;");
|
||||
parse("drop user if exists 'test', if exists 'test1', if exists 'test2', if exists 'test3';");
|
||||
|
||||
// 如果用户没有grant的global all权限, 不能够grant global/db/table/column.
|
||||
parse("grant all on *.* to test@'%'");
|
||||
parse("grant select on *.* to test1;");
|
||||
parse("grant select on mysql.* to test1;");
|
||||
parse("grant select on mysql.host to test1;");
|
||||
parse("grant select(host) on mysql.host to test1;");
|
||||
parse("drop user if exists 'test', if exists 'test1', if exists 'test2', if exists 'test3';");
|
||||
|
||||
///////
|
||||
// 如果用户有global权限grant select,能够 revoke global/db/table/column select权限
|
||||
parse("grant select, CREATE USER on *.* to test@'%' with grant option;");
|
||||
grantDone();
|
||||
parse("revoke select on *.* from test1;");
|
||||
parse("revoke update on *.* from test1;");
|
||||
parse("revoke select on mysql.* from test1;");
|
||||
parse("revoke update on mysql.* from test1;");
|
||||
parse("revoke select on mysql.host from test1;");
|
||||
parse("revoke update on mysql.host from test1;");
|
||||
parse("revoke select(host) on mysql.host from test1;");
|
||||
parse("revoke update(host) on mysql.host from test1;");
|
||||
parse("drop user if exists 'test', if exists 'test1', if exists 'test2', if exists 'test3';");
|
||||
|
||||
// 如果用户有db权限grant select, 不能够revoke global的select,能够revoke db/table/column.
|
||||
parse("grant select on mysql.* to test@'%' with grant option;");
|
||||
parse("grant CREATE USER on *.* to test@'%'");
|
||||
grantDone();
|
||||
parse("revoke select on *.* from test1;");
|
||||
parse("revoke select on mysql.* from test1;");
|
||||
parse("revoke update on mysql.* from test1;");
|
||||
parse("revoke select on mysql.host from test1;");
|
||||
parse("revoke update on mysql.host from test1;");
|
||||
parse("revoke select(host) on mysql.host from test1;");
|
||||
parse("drop user if exists 'test', if exists 'test1', if exists 'test2', if exists 'test3';");
|
||||
|
||||
// 如果用户有table权限grant select, 不能够revoke global/db. 能够revoke table/column.
|
||||
parse("grant select on mysql.host to test@'%' with grant option;");
|
||||
parse("grant CREATE USER on *.* to test@'%'");
|
||||
grantDone();
|
||||
parse("revoke select on *.* from test1;");
|
||||
parse("revoke select on mysql.* from test1;");
|
||||
parse("revoke select on mysql.host from test1;");
|
||||
parse("revoke update on mysql.host from test1;");
|
||||
parse("revoke select(host) on mysql.host from test1;");
|
||||
parse("revoke update(host) on mysql.host from test1;");
|
||||
parse("drop user if exists 'test', if exists 'test1', if exists 'test2', if exists 'test3';");
|
||||
|
||||
// 如果用户没有grant的global all权限, 不能够revoke global/db/table/column.
|
||||
parse("grant all on *.* to test@'%'");
|
||||
grantDone();
|
||||
parse("revoke select on *.* from test1;");
|
||||
parse("revoke select on mysql.* from test1;");
|
||||
parse("revoke select on mysql.host from test1;");
|
||||
parse("revoke select(host) on mysql.host from test1;");
|
||||
parse("drop user if exists 'test', if exists 'test1', if exists 'test2', if exists 'test3';");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShowGrants() throws Exception {
|
||||
parse("drop user if exists 'test', if exists 'test1', if exists 'test2', if exists 'test3';");
|
||||
parse("show grants");
|
||||
|
||||
parse("create user test@'%' identified by '123456';");
|
||||
parse("show grants");
|
||||
parse("grant select,update on *.* to test@'%';");
|
||||
parse("show grants");
|
||||
parse("grant update on mysql.* to test@'%';");
|
||||
parse("show grants");
|
||||
parse("grant update on mysql.user to test@'%';");
|
||||
parse("show grants");
|
||||
parse("grant update(host) on mysql.user to test@'%';");
|
||||
parse("show grants");
|
||||
|
||||
parse("show grants");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEnableUser() throws Exception {
|
||||
parse("drop user if exists 'test', if exists 'test1', if exists 'test2', if exists 'test3';");
|
||||
parse("create user test@'%' identified by '123456';");
|
||||
parse("grant grant option, CREATE USER on *.* to test@'%';");
|
||||
parse("create user test1@'%' identified by '123456';");
|
||||
|
||||
parse("revoke CONNECT from test1@'%';");
|
||||
parse("GRANT CONNECT on *.* to test1@'%'");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateUserBeforeOpenSwitch() throws Exception {
|
||||
parse("drop user if exists 'test', if exists 'test1', if exists 'test2', if exists 'test3';");
|
||||
parse("create user test@'%' identified by '123456';");
|
||||
|
||||
// 打开开关后,create user的账号没有任何权限
|
||||
parse( "select * from mysql.user");
|
||||
|
||||
// 关闭开关后, create user的账号拥有所有权限
|
||||
parse("drop user if exists 'test', if exists 'test1', if exists 'test2', if exists 'test3';");
|
||||
parse("create user test@'%' identified by '123456';");
|
||||
parse("select * from mysql.user");
|
||||
parse("create user test2@'%' identified by '123456';");
|
||||
|
||||
// 打开开关后,这个账号仍然拥有所有权限
|
||||
parse("select * from mysql.user");
|
||||
parse("create user test3@'%' identified by '123456';");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGrantUser() throws Exception {
|
||||
parse("drop user if exists 'test', if exists 'test1', if exists 'test2', if exists 'test3';");
|
||||
parse("create user test@'%'");
|
||||
parse("grant all on *.* to test");
|
||||
|
||||
parse("drop user if exists 'test', if exists 'test1', if exists 'test2', if exists 'test3';");
|
||||
parse("create user test@'%'");
|
||||
parse("grant all on *.* to test");
|
||||
parse("drop user if exists 'test', if exists 'test1', if exists 'test2', if exists 'test3';");
|
||||
|
||||
// 没有 create user 权限的用户,无法 通过 grant create user.
|
||||
parse("grant grant option, select on *.* to test");
|
||||
parse("grant select on *.* to test2");
|
||||
parse("grant create user on *.* to test");
|
||||
parse("grant select on *.* to test2");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGrantRevokeAvailable() throws Exception {
|
||||
parse("drop user if exists 'test', if exists 'test1', if exists 'test2', if exists 'test3';");
|
||||
|
||||
// 拥有all权限的用户,但是无法grant权限给其他用户
|
||||
parse("grant all on *.* to test@'%' identified by 'ccc';");
|
||||
parse("grant select on *.* to test1@'%';");
|
||||
parse("grant select on mysql.* to test1@'%';");
|
||||
parse("grant select on mysql.user to test1@'%';");
|
||||
parse("grant select(host) on mysql.user to test1@'%';");
|
||||
parse("drop user if exists 'test', if exists 'test1', if exists 'test2', if exists 'test3';");
|
||||
|
||||
// 拥有select 权限的用户,可以grant select权限给所有的用户
|
||||
parse("grant select, CREATE USER on *.* to test@'%' identified by 'ccc' with grant option;");
|
||||
parse("grant select on *.* to test1@'%';");
|
||||
parse("grant select on mysql.* to test1@'%';");
|
||||
parse("grant select on mysql.user to test1@'%';");
|
||||
parse("grant select(host) on mysql.user to test1@'%';");
|
||||
parse("drop user if exists 'test', if exists 'test1', if exists 'test2', if exists 'test3';");
|
||||
|
||||
// 拥有select 权限的用户,可以grant select权限给所有的用户的另一种写法, 也可以revoke
|
||||
parse("grant select, grant option, CREATE USER on *.* to test@'%' identified by 'ccc';");
|
||||
parse("grant select on *.* to test1@'%';");
|
||||
parse("grant select on mysql.* to test1@'%';");
|
||||
parse("grant select on mysql.user to test1@'%';");
|
||||
parse("grant select(host) on mysql.user to test1@'%';");
|
||||
parse("grant update on *.* to test1@'%';");
|
||||
parse("grant update on mysql.* to test1@'%';");
|
||||
parse("grant update on mysql.user to test1@'%';");
|
||||
parse("grant update(host) on mysql.user to test1@'%';");
|
||||
parse("revoke select on *.* from test1@'%';");
|
||||
parse("revoke select on mysql.* from test1@'%';");
|
||||
parse("revoke select on mysql.user from test1@'%';");
|
||||
parse("revoke select(host) on mysql.user from test1@'%';");
|
||||
parse("revoke update on *.* from test1@'%';");
|
||||
parse("revoke update on mysql.* from test1@'%';");
|
||||
parse("revoke update on mysql.user from test1@'%';");
|
||||
parse("revoke update(host) on mysql.user from test1@'%';");
|
||||
parse("drop user if exists 'test', if exists 'test1', if exists 'test2', if exists 'test3';");
|
||||
|
||||
// 没有grant权限,无法给用户grant/revoke权限
|
||||
parse("grant select, CREATE USER on *.* to test@'%' identified by 'ccc';");
|
||||
parse("grant select on mysql.* to test1@'%';");
|
||||
parse("grant select on mysql.* to test1@'%' identified by 'ccc';");
|
||||
parse("revoke select on mysql.* from test1@'%';");
|
||||
|
||||
// 拥有 all 权限的用户, 可以revoke all
|
||||
parse("grant all, grant option on *.* to test@'%' identified by 'ccc';");
|
||||
parse("grant all,grant option on *.* to test1@'%';");
|
||||
parse("revoke all on *.* from test1@'%';");
|
||||
parse("revoke grant option on *.* from test1@'%';");
|
||||
parse("drop user if exists 'test', if exists 'test1', if exists 'test2', if exists 'test3';");
|
||||
}
|
||||
}
|
||||
-166
@@ -1,166 +0,0 @@
|
||||
package com.alibaba.druid.bvt.sql.mysql.createTable;
|
||||
|
||||
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.ast.statement.MySqlCreateTableStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser;
|
||||
import org.junit.Assert;
|
||||
|
||||
public class ADB30_MySqlCreateTableTest extends MysqlTest {
|
||||
|
||||
public void test_create_table1() {
|
||||
String sql = "CREATE TABLE db_name.table_name (\n" +
|
||||
" auto_id bigint NOT NULL AUTO_INCREMENT,\n" +
|
||||
" col1 boolean NULL DEFAULT 1,\n" +
|
||||
" col2 tinyint null,\n" +
|
||||
" col3 smallint NULL DEFAULT 2,\n" +
|
||||
" col4 int not null DEFAULT 3,\n" +
|
||||
" col5 bigint ,\n" +
|
||||
" col6 float ,\n" +
|
||||
" col7 double ,\n" +
|
||||
" col8 varchar,\n" +
|
||||
" col9 timestamp DEFAULT current_timestamp,\n" +
|
||||
" col10 date DEFAULT current_date,\n" +
|
||||
" col11 multivalue DEFAULT 'a' delimiter_tokenizer ': ,' value_type 'varchar int',\n" +
|
||||
" col13 multivalue DEFAULT 'a' nlp_tokenizer 'ik' value_type 'varchar int',\n" +
|
||||
" col14 geo2d delimiter_tokenizer ',',\n" +
|
||||
" key col3_index(col3),\n" +
|
||||
" key col4_index(col4),\n" +
|
||||
" clustering key col5_col6_cls_index(col5,col6),\n" +
|
||||
" primary key (col1, col3)\n" +
|
||||
")\n" +
|
||||
"DISTRIBUTE BY HASH(col1) \n" +
|
||||
"PARTITION BY VALUE(col9) PARTITIONS 365 \n" +
|
||||
"INDEX_ALL='Y'\n" +
|
||||
"COMPRESSION = 'zip'\n" +
|
||||
"ENGINE='CSTORE'";
|
||||
|
||||
MySqlCreateTableStatement stmt = (MySqlCreateTableStatement) SQLUtils.parseSingleMysqlStatement(sql);
|
||||
String engine = SQLUtils.toNormalizeMysqlString(stmt.getOption("engine"));
|
||||
String indexAll = SQLUtils.toNormalizeMysqlString(stmt.getOption("index_All"));
|
||||
String compression = SQLUtils.toNormalizeMysqlString(stmt.getOption("COMPRESSION"));
|
||||
|
||||
Assert.assertEquals("CSTORE", engine);
|
||||
Assert.assertEquals("Y", indexAll);
|
||||
Assert.assertEquals("zip", compression);
|
||||
|
||||
parseTrue(sql, "CREATE TABLE db_name.table_name (\n" +
|
||||
"\tauto_id bigint NOT NULL AUTO_INCREMENT,\n" +
|
||||
"\tcol1 boolean NULL DEFAULT 1,\n" +
|
||||
"\tcol2 tinyint NULL,\n" +
|
||||
"\tcol3 smallint NULL DEFAULT 2,\n" +
|
||||
"\tcol4 int NOT NULL DEFAULT 3,\n" +
|
||||
"\tcol5 bigint,\n" +
|
||||
"\tcol6 float,\n" +
|
||||
"\tcol7 double,\n" +
|
||||
"\tcol8 varchar,\n" +
|
||||
"\tcol9 timestamp DEFAULT CURRENT_TIMESTAMP,\n" +
|
||||
"\tcol10 date DEFAULT CURRENT_DATE,\n" +
|
||||
"\tcol11 multivalue DEFAULT 'a' DELIMITER_TOKENIZER ': ,' VALUE_TYPE 'varchar int',\n" +
|
||||
"\tcol13 multivalue DEFAULT 'a' NLP_TOKENIZER 'ik' VALUE_TYPE 'varchar int',\n" +
|
||||
"\tcol14 geo2d DELIMITER_TOKENIZER ',',\n" +
|
||||
"\tKEY col3_index (col3),\n" +
|
||||
"\tKEY col4_index (col4),\n" +
|
||||
"\tCLUSTERING KEY col5_col6_cls_index (col5, col6),\n" +
|
||||
"\tPRIMARY KEY (col1, col3)\n" +
|
||||
") INDEX_ALL = 'Y' COMPRESSION = 'zip' ENGINE = 'CSTORE'\n" +
|
||||
"DISTRIBUTE BY HASH(col1)\n" +
|
||||
"PARTITION BY VALUE (col9) PARTITIONS 365");
|
||||
}
|
||||
|
||||
public void test_create_table2() {
|
||||
String sql = "CREATE TABLE db_name.table_name (\n" +
|
||||
" auto_id bigint NOT NULL AUTO_INCREMENT,\n" +
|
||||
" col1 boolean NULL DEFAULT 1,\n" +
|
||||
" col2 tinyint null,\n" +
|
||||
" col3 smallint NULL DEFAULT 2,\n" +
|
||||
" col4 int not null DEFAULT 3,\n" +
|
||||
" col5 bigint ,\n" +
|
||||
" col6 float ,\n" +
|
||||
" col7 double ,\n" +
|
||||
" col8 varchar,\n" +
|
||||
" col9 timestamp DEFAULT current_timestamp,\n" +
|
||||
" col10 date DEFAULT current_date,\n" +
|
||||
" col11 multivalue DEFAULT 'a' delimiter_tokenizer ': ,' value_type 'varchar int',\n" +
|
||||
" col13 multivalue DEFAULT 'a' nlp_tokenizer 'ik' value_type 'varchar int',\n" +
|
||||
" col14 geo2d delimiter_tokenizer ',',\n" +
|
||||
" key col3_index(col3),\n" +
|
||||
" key col4_index(col4),\n" +
|
||||
" clustering key col5_col6_cls_index(col5,col6),\n" +
|
||||
" primary key (col1, col3)\n" +
|
||||
")\n" +
|
||||
"DISTRIBUTE BY BROADCAST \n" +
|
||||
"PARTITION BY VALUE(YEARMONTHDAY(col9)) PARTITIONS 365 \n" +
|
||||
"INDEX_ALL='N'\n" +
|
||||
"ENGINE='CSTORE'";
|
||||
|
||||
parseTrue(sql, "CREATE TABLE db_name.table_name (\n" +
|
||||
"\tauto_id bigint NOT NULL AUTO_INCREMENT,\n" +
|
||||
"\tcol1 boolean NULL DEFAULT 1,\n" +
|
||||
"\tcol2 tinyint NULL,\n" +
|
||||
"\tcol3 smallint NULL DEFAULT 2,\n" +
|
||||
"\tcol4 int NOT NULL DEFAULT 3,\n" +
|
||||
"\tcol5 bigint,\n" +
|
||||
"\tcol6 float,\n" +
|
||||
"\tcol7 double,\n" +
|
||||
"\tcol8 varchar,\n" +
|
||||
"\tcol9 timestamp DEFAULT CURRENT_TIMESTAMP,\n" +
|
||||
"\tcol10 date DEFAULT CURRENT_DATE,\n" +
|
||||
"\tcol11 multivalue DEFAULT 'a' DELIMITER_TOKENIZER ': ,' VALUE_TYPE 'varchar int',\n" +
|
||||
"\tcol13 multivalue DEFAULT 'a' NLP_TOKENIZER 'ik' VALUE_TYPE 'varchar int',\n" +
|
||||
"\tcol14 geo2d DELIMITER_TOKENIZER ',',\n" +
|
||||
"\tKEY col3_index (col3),\n" +
|
||||
"\tKEY col4_index (col4),\n" +
|
||||
"\tCLUSTERING KEY col5_col6_cls_index (col5, col6),\n" +
|
||||
"\tPRIMARY KEY (col1, col3)\n" +
|
||||
") INDEX_ALL = 'N' ENGINE = 'CSTORE'\n" +
|
||||
"DISTRIBUTE BY BROADCAST \n" +
|
||||
"PARTITION BY VALUE (YEARMONTHDAY(col9)) PARTITIONS 365");
|
||||
}
|
||||
|
||||
public void test_create_table3() {
|
||||
String sql = "CREATE TABLE test_rename_subpartition_key_columns (\n" +
|
||||
" cid1 INT,\n" +
|
||||
" cid2 INT,\n" +
|
||||
" cid3 INT,\n" +
|
||||
" cid4 INT,\n" +
|
||||
" cid5 INT,\n" +
|
||||
" `ts` VARCHAR,\n" +
|
||||
" clustering KEY ts_cluster_idx(cid5, `TS`)\n" +
|
||||
") DISTRIBUTE BY HASH (`cid1`)\n" +
|
||||
"PARTITION BY VALUE (`cid1`) LIFECYCLE -1\n" +
|
||||
"SUBPARTITION BY VALUE (`YEARMONTHDAY(ts)`)\n" +
|
||||
" BLOCK_SIZE 16\n" +
|
||||
"ENGINE = 'CSTORE'";
|
||||
|
||||
parseTrue(sql, "CREATE TABLE test_rename_subpartition_key_columns (\n" +
|
||||
"\tcid1 INT,\n" +
|
||||
"\tcid2 INT,\n" +
|
||||
"\tcid3 INT,\n" +
|
||||
"\tcid4 INT,\n" +
|
||||
"\tcid5 INT,\n" +
|
||||
"\t`ts` VARCHAR,\n" +
|
||||
"\tCLUSTERING KEY ts_cluster_idx (cid5, `TS`)\n" +
|
||||
") BLOCK_SIZE = 16 ENGINE = 'CSTORE'\n" +
|
||||
"DISTRIBUTE BY HASH(`cid1`)\n" +
|
||||
"PARTITION BY VALUE (`cid1`) LIFECYCLE -1\n" +
|
||||
"SUBPARTITION BY VALUE (`YEARMONTHDAY(ts)`)");
|
||||
}
|
||||
public void test_create_table4() {
|
||||
String sql = "CREATE TABLE sec(col1 int, col2 string, primary key(col1, col2)) " +
|
||||
"DISTRIBUTE BY HASH(col1) " +
|
||||
"PARTITION BY VALUE(col1) " +
|
||||
"SUBPARTITION BY VALUE(YEARMONTHDAY(col2)) LIFECYCLE 30 " +
|
||||
"engine='CSTORE'; ";
|
||||
|
||||
parseTrue(sql, "CREATE TABLE sec (\n" +
|
||||
"\tcol1 int,\n" +
|
||||
"\tcol2 string,\n" +
|
||||
"\tPRIMARY KEY (col1, col2)\n" +
|
||||
") ENGINE = 'CSTORE'\n" +
|
||||
"DISTRIBUTE BY HASH(col1)\n" +
|
||||
"PARTITION BY VALUE (col1)\n" +
|
||||
"SUBPARTITION BY VALUE (YEARMONTHDAY(col2)) LIFECYCLE 30;");
|
||||
}
|
||||
}
|
||||
@@ -1,224 +0,0 @@
|
||||
package com.alibaba.druid.bvt.sql.mysql.createTable;
|
||||
|
||||
import com.alibaba.druid.sql.MysqlTest;
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
|
||||
public class ADB30_MySqlDDLTest extends MysqlTest {
|
||||
|
||||
public void test_archive_table() throws Exception {
|
||||
parseTrue("archive table a.b 1:100, 2:2, 3:3", "ARCHIVE TABLE a.b 1:100, 2:2, 3:3");
|
||||
parseTrue("archive table a.b 1:100, 2 : 2, 3 :3", "ARCHIVE TABLE a.b 1:100, 2:2, 3:3");
|
||||
}
|
||||
|
||||
public void test_alter_table() throws Exception {
|
||||
parseTrue("alter table ddlDb.tbl rename column col1 to col2",
|
||||
"ALTER TABLE ddlDb.tbl\n" +
|
||||
"\tRENAME COLUMN col1 TO col2");
|
||||
|
||||
parseTrue("alter table ddlDb.tbl rename tbl2","RENAME TABLE ddlDb.tbl TO tbl2");
|
||||
parseTrue("alter table ddlDb.addColumn add column c1 double(2,4)",
|
||||
"ALTER TABLE ddlDb.addColumn\n" +
|
||||
"\tADD COLUMN c1 double(2, 4)");
|
||||
parseTrue("alter table ddlDb.tbl drop column col1","ALTER TABLE ddlDb.tbl\n" +
|
||||
"\tDROP COLUMN col1");
|
||||
parseTrue("alter table ddlDb.tbl drop column col1","ALTER TABLE ddlDb.tbl\n" +
|
||||
"\tDROP COLUMN col1");
|
||||
|
||||
|
||||
parseTrue("alter table ddlDb.addColumn add column c1 double(2,4)","ALTER TABLE ddlDb.addColumn\n" +
|
||||
"\tADD COLUMN c1 double(2, 4)");
|
||||
parseTrue("alter table ddlDb.addColumn add column c2 int(3) NOT NULL DEFAULT 123","ALTER TABLE ddlDb.addColumn\n" +
|
||||
"\tADD COLUMN c2 int(3) NOT NULL DEFAULT 123");
|
||||
parseTrue("alter table ddlDb.addColumn add column c1 double(4, 5) NOT NULL DEFAULT 1.23 AUTO_INCREMENT ENCODE='AUTO' COMPRESSION='SNAPPY'",
|
||||
"ALTER TABLE ddlDb.addColumn\n" +
|
||||
"\tADD COLUMN c1 double(4, 5) NOT NULL DEFAULT 1.23 AUTO_INCREMENT ENCODE='AUTO' COMPRESSION='SNAPPY'");
|
||||
|
||||
parseTrue("alter table ddlDb.addColumn add column c1 multivalue NOT NULL AUTO_INCREMENT ENCODE='AUTO' COMPRESSION='SNAPPY' delimiter_tokenizer ': ,' value_type 'varchar int'"
|
||||
,"ALTER TABLE ddlDb.addColumn\n" +
|
||||
"\tADD COLUMN c1 multivalue NOT NULL AUTO_INCREMENT DELIMITER_TOKENIZER ': ,' VALUE_TYPE 'varchar int' ENCODE='AUTO' COMPRESSION='SNAPPY'");
|
||||
|
||||
}
|
||||
|
||||
public void test_backup() throws Exception {
|
||||
parseTrue("backup data into 'sdfwefi', 'fefwefoij'", "BACKUP DATA INTO 'sdfwefi','fefwefoij'");
|
||||
parseTrue("backup log into 'adb','sdfe'", "BACKUP LOG INTO 'adb','sdfe'");
|
||||
parseTrue("backup log list_logs ", "BACKUP LOG LIST_LOGS");
|
||||
parseTrue("backup log status ", "BACKUP LOG STATUS");
|
||||
parseTrue("backup cancel 'sdfwef'", "BACKUP CANCEL 'sdfwef'");
|
||||
}
|
||||
|
||||
public void test_truncate() {
|
||||
parseTrue("TRUNCATE table ddlDb.truncateTable","TRUNCATE TABLE ddlDb.truncateTable");
|
||||
parseTrue("TRUNCATE table ddlDb.truncateTable partition all","TRUNCATE TABLE ddlDb.truncateTable PARTITION ALL");
|
||||
parseTrue("TRUNCATE table ddlDb.truncateTable partition 1,4,5","TRUNCATE TABLE ddlDb.truncateTable PARTITION 1, 4, 5");
|
||||
}
|
||||
|
||||
public void test_restore() throws Exception {
|
||||
parseTrue("restore data from 'dfefw', 'wefeoif'", "RESTORE DATA FROM 'dfefw','wefeoif'");
|
||||
parseTrue("restore log from 'dfefw', 'wefeoif'", "RESTORE LOG FROM 'dfefw','wefeoif'");
|
||||
}
|
||||
|
||||
public void test_restore_2() throws Exception {
|
||||
SQLStatement parse = parse("restore data from '[{\"dbname\":\"backup\",\"url\":\"testBackup/BACKUP_20_20180614172606\",\"upload_id\":20,\"check_type\":\"MD5\",\"checksum\":\"\",\"log_pos\":0,\"file_size\":83717}]','oss://test:test@oss-cn-hangzhou-zmf.aliyuncs.com/039696/testBackup/'");
|
||||
System.out.println(parse);
|
||||
}
|
||||
|
||||
public void test_build() throws Exception {
|
||||
parseTrue("build table a.b ", "BUILD TABLE a.b");
|
||||
parseTrue("build table a.b version = 1000 with split", "BUILD TABLE a.b VERSION = 1000 WITH SPLIT");
|
||||
parseTrue("build table a.b version = 1000 ", "BUILD TABLE a.b VERSION = 1000");
|
||||
parseTrue("build table a.b with split ", "BUILD TABLE a.b WITH SPLIT");
|
||||
}
|
||||
|
||||
public void test_cancel() throws Exception {
|
||||
parseTrue("cancel JOB '1'", "CANCEL JOB '1'");
|
||||
parseTrue("cancel LOAD_JOB '1'", "CANCEL JOB '1'");
|
||||
parseTrue("cancel SYNC_JOB '1'", "CANCEL JOB '1'");
|
||||
}
|
||||
|
||||
public void test_database() throws Exception {
|
||||
parseTrue("create database if not exists test__1 options(shards=1 shard_id=1 replication=1 storage_dependency='INTERNAL')", "CREATE DATABASE IF NOT EXISTS test__1 OPTIONS (replication=1 shards=1 storage_dependency='INTERNAL' shard_id=1 )");
|
||||
parseTrue("create schema if not exists test__1 options(shards=1 shard_id=1 replication=1 storage_dependency='INTERNAL')", "CREATE DATABASE IF NOT EXISTS test__1 OPTIONS (replication=1 shards=1 storage_dependency='INTERNAL' shard_id=1 )");
|
||||
parseTrue("create schema if not exists test__1 shards=1 shard_id=1 replication=1 storage_dependency='INTERNAL'", "CREATE DATABASE IF NOT EXISTS test__1 OPTIONS (replication=1 shards=1 storage_dependency='INTERNAL' shard_id=1 )");
|
||||
}
|
||||
|
||||
public void test_create_table2() {
|
||||
parse("create table testBlockSize_beforeAddColumn(c1 int , c2 int) distribute by hash(c1) " +
|
||||
" partition by value(c2) partitions 99 " +
|
||||
" block_size " + 1 + " engine='analysis'");
|
||||
}
|
||||
|
||||
public void test_database2() throws Exception {
|
||||
SQLStatement create_database_test = parse("create database test");
|
||||
System.out.println(create_database_test);
|
||||
}
|
||||
|
||||
public void test_event() throws Exception {
|
||||
parseTrue("CREATE EVENT e1 on schedule at '2018-12-12 11:12:21' do select 1",
|
||||
"CREATE EVENT e1 ON SCHEDULE AT '2018-12-12 11:12:21'\n" +
|
||||
"DO\n" +
|
||||
"SELECT 1");
|
||||
parseTrue("CREATE EVENT e2 on schedule every 5 minute comment 'e2 as test' do select 1,2,3,4,5",
|
||||
"CREATE EVENT e2 ON SCHEDULE EVERY 5 MINUTECOMMENT 'e2 as test'\n" +
|
||||
"DO\n" +
|
||||
"SELECT 1, 2, 3, 4, 5");
|
||||
}
|
||||
|
||||
public void test_procedure() throws Exception {
|
||||
parseTrue("CREATE procedure pdb.p2() COMMENT 'COMMENT...' LANGUAGE SQL SQL SECURITY DEFINER ( select 1 ) union all (select 2)",
|
||||
"CREATE PROCEDURE pdb.p2 ()\n" +
|
||||
"COMMENT 'COMMENT...'\n" +
|
||||
"LANGUAGE SQL\n" +
|
||||
"SQL SECURITY DEFINER\n" +
|
||||
"(SELECT 1)\n" +
|
||||
"UNION ALL\n" +
|
||||
"(SELECT 2)");
|
||||
}
|
||||
|
||||
public void test_crate_user() throws Exception {
|
||||
parseTrue("create user if not exists 'test1'@'%' identified by 'aa2', 'test2'@'%' identified by password 'bb', test3;",
|
||||
"CREATE USER IF NOT EXISTS 'test1'@'%' IDENTIFIED BY 'aa2', 'test2'@'%' IDENTIFIED BY PASSWORD 'bb', test3;");
|
||||
}
|
||||
|
||||
public void test_drop_db() throws Exception {
|
||||
parseTrue("drop database if exists db1", "DROP DATABASE IF EXISTS db1");
|
||||
}
|
||||
|
||||
public void test_drop_event() throws Exception {
|
||||
parseTrue("DROP EVENT IF EXISTS edb.e1", "DROP EVENT IF EXISTS edb.e1");
|
||||
}
|
||||
|
||||
public void test_drop_procedure() throws Exception {
|
||||
parseTrue("DROP procedure IF EXISTS pdb.p1", "DROP PROCEDURE IF EXISTS pdb.p1");
|
||||
}
|
||||
|
||||
public void test_drop_table() throws Exception {
|
||||
parseTrue("DROP table IF EXISTS pdb.p1", "DROP TABLE IF EXISTS pdb.p1");
|
||||
}
|
||||
|
||||
public void test_drop_user() throws Exception {
|
||||
parseTrue("drop user if exists 'test', 'test1', 'test2', 'test3';",
|
||||
"DROP USER IF EXISTS 'test', 'test1', 'test2', 'test3';");
|
||||
}
|
||||
|
||||
public void test_drop_view() throws Exception {
|
||||
parseTrue("DROP VIEW IF EXISTS viewdb.v1, test4dmp.v1",
|
||||
"DROP VIEW IF EXISTS viewdb.v1, test4dmp.v1");
|
||||
}
|
||||
|
||||
public void test_execute() throws Exception {
|
||||
parseTrue("execute restart RC '123456' finish", "EXECUTE restart RC '123456' finish");
|
||||
}
|
||||
|
||||
public void test_export_db() throws Exception {
|
||||
parseTrue("export database test__1 realtime = 'y'", "EXPORT DATABASE test__1 REALTIME = 'Y'");
|
||||
parseTrue("export database test__1 realtime = 'n'", "EXPORT DATABASE test__1 REALTIME = 'N'");
|
||||
}
|
||||
|
||||
public void test_export_table() throws Exception {
|
||||
parseTrue("export table test__1.t1", "EXPORT TABLE test__1.t1");
|
||||
}
|
||||
|
||||
public void test_flush() throws Exception {
|
||||
parseTrue("flush table test__1.t1 version=4", "FLUSH TABLES test__1.t1 VERSION = 4");
|
||||
}
|
||||
|
||||
public void test_grant() throws Exception {
|
||||
parseTrue("grant select on test4p.tt3 to 'test'@'%' identified by 'ccc';",
|
||||
"GRANT SELECT ON test4p.tt3 TO 'test'@'%' IDENTIFIED BY 'ccc';");
|
||||
|
||||
parseTrue("grant select(id) on test4dmp.grade to test;",
|
||||
"GRANT SELECT(id) ON test4dmp.grade TO test;");
|
||||
}
|
||||
|
||||
public void test_import_db() throws Exception {
|
||||
parseTrue("IMPORT DATABASE test4dmp__2 Status=''", "IMPORT DATABASE test4dmp__2 STATUS = ''");
|
||||
}
|
||||
|
||||
public void test_import_table() throws Exception {
|
||||
parseTrue("import table tablename version = 123", "IMPORT TABLE tablename VERSIOIN = 123");
|
||||
parseTrue("import table tablename version = 123 build='Y'", "IMPORT TABLE tablename VERSIOIN = 123 BUILD = 'Y'");
|
||||
}
|
||||
|
||||
public void test_manage_instance_group() throws Exception {
|
||||
parseTrue("add INSTANCE_GROUP 1 REPLICATION = 3\n", "ADD INSTANCE_GROUP 1 REPLICATION = 3");
|
||||
parseTrue("drop INSTANCE_GROUP 2,3", "DROP INSTANCE_GROUP 2,3");
|
||||
}
|
||||
|
||||
public void test_migrate() throws Exception {
|
||||
parseTrue("migrate database test4dmp shards='test4dmp__1,test4dmp__3' host from '301':'127.0.0.1':1123:'offline' to '304':'30.40.43.23':4309:'online'",
|
||||
"MIGRATE DATABASE test4dmp SHARDS='test4dmp__1,test4dmp__3' HOST FROM '301':'127.0.0.1':1123:'offline' TO '304':'30.40.43.23':4309:'online'");
|
||||
}
|
||||
|
||||
public void test_revoke() throws Exception {
|
||||
parseTrue("revoke update,delete on aa.bb from test@'%' ",
|
||||
"REVOKE UPDATE, DELETE ON aa.bb FROM 'test'@'%'");
|
||||
}
|
||||
|
||||
public void test_raft() throws Exception {
|
||||
parseTrue("sync raft_leader_transfer shard='shardname' from='fromMemberAddr' to='toMemberAddr' timeout=10000",
|
||||
"SYNC RAFT_LEADER_TRANSFER SHARD='shardname' FROM='fromMemberAddr' TO='toMemberAddr' TIMEOUT=10000");
|
||||
|
||||
parseTrue("SYNC RAFT_MEMBER_CHANGE noleader SHARD='shardName'\n" +
|
||||
" HOST='hostId'\n" +
|
||||
" STATUS='ACTIVE'\n" +
|
||||
"FORCE", "SYNC RAFT_MEMBER_CHANGE NOLEADER SHARD='shardName' HOST='hostId' STATUS='ACTIVE' FORCE");
|
||||
}
|
||||
|
||||
public void test_rename_user() throws Exception {
|
||||
parseTrue("rename user test@'%' to test1@'%'", "RENAME USER 'test'@'%' TO 'test1'@'%'");
|
||||
parseTrue("rename user 'test1' to 'test2'", "RENAME USER 'test1' TO 'test2'");
|
||||
}
|
||||
|
||||
public void test_show_command() throws Exception {
|
||||
parseTrue("show cluster name", "SHOW CLUSTER NAME");
|
||||
parseTrue("Show Migrate task status where 1=1", "SHOW MIGRATE TASK STATUS WHERE 1 = 1");
|
||||
}
|
||||
|
||||
public void test_submit_job() throws Exception {
|
||||
parseTrue("submit job await select 1", "SUBMIT JOB AWAIT SELECT 1");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,614 +0,0 @@
|
||||
package com.alibaba.druid.bvt.sql.mysql.createTable;
|
||||
|
||||
import com.alibaba.druid.sql.MysqlTest;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlCreateTableStatement;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class ADB30_TestDDLParser extends MysqlTest {
|
||||
|
||||
@Test
|
||||
public void testRenameTable() {
|
||||
{
|
||||
String sql = "alter table ddlDb.tbl rename tbl2";
|
||||
parse(sql);
|
||||
}
|
||||
|
||||
{
|
||||
String sql = "alter table ddlDb.tbl rename to ddlDb2.tbl2";
|
||||
parse(sql);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRenameColumn() {
|
||||
{
|
||||
String sql = "alter table ddlDb.tbl rename column col1 to col2";
|
||||
parse(sql);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testComment() {
|
||||
{
|
||||
String sql = "alter table test_table_comment comment = 'mycomment111'";
|
||||
SQLStatement stmt = parse(sql);
|
||||
System.out.println(stmt);
|
||||
}
|
||||
}
|
||||
@Test
|
||||
public void testrename() {
|
||||
{
|
||||
String sql = "alter table t1 rename to t2";
|
||||
SQLStatement stmt = parse(sql);
|
||||
System.out.println(stmt);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void testDropColumn() {
|
||||
{
|
||||
String sql = "alter table ddlDb.tbl drop column col1";
|
||||
parse(sql);
|
||||
|
||||
}
|
||||
{
|
||||
String sql = "alter table ddlDb.tbl drop col2";
|
||||
parse(sql);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTruncate() {
|
||||
String sql = "TRUNCATE table ddlDb.truncateTable";
|
||||
|
||||
sql = "TRUNCATE table ddlDb.truncateTable partition all";
|
||||
SQLStatement stmt = parse(sql);
|
||||
System.out.println(stmt);
|
||||
|
||||
sql = "TRUNCATE table ddlDb.truncateTable partition 1,4,5";
|
||||
parse(sql);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddColumn() {
|
||||
String sql = "alter table ddlDb.addColumn add column c1 double(2,4)";
|
||||
parse(sql);
|
||||
|
||||
sql = "alter table ddlDb.addColumn add column c2 int(3) NOT NULL DEFAULT 123";
|
||||
parse(sql);
|
||||
sql = "alter table ddlDb.addColumn add column c1 double(4, 5) NOT NULL DEFAULT 1.23 AUTO_INCREMENT ENCODE='AUTO' COMPRESSION='SNAPPY'";
|
||||
parse(sql);
|
||||
|
||||
sql = "alter table ddlDb.addColumn add column c1 multivalue NOT NULL AUTO_INCREMENT ENCODE='AUTO' COMPRESSION='SNAPPY' delimiter_tokenizer ': ,' value_type 'varchar int'";
|
||||
parse(sql);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDropKey() {
|
||||
String sql = "alter table ddlDB.test_dropKey drop key col1_Index";
|
||||
parse(sql);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTableMultiColumn() {
|
||||
String sql1 = "create table test__1.t1(c1 multivalue delimiter_tokenizer 'x' value_type 'varchar') distribute by hash(c1) engine='analysis'";
|
||||
parse(sql1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTableControl() {
|
||||
String build1 = "build table testdb.test4dmp version=10000";
|
||||
String build2 = "build table testdb.test4dmp";
|
||||
String flush1 = "flush table testdb.test4dmp version=10000";
|
||||
String flush2 = "flush table testdb.test4dmp";
|
||||
parse(build1);
|
||||
parse(build2);
|
||||
parse(flush1);
|
||||
parse(flush2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMigrateSynctax() {
|
||||
String migrate = "migrate database test4dmp shards = 'test4dmp__1' group from '55156' to '55157'";
|
||||
parse(migrate);
|
||||
}
|
||||
@Test
|
||||
public void testMigrateNewSynctax() {
|
||||
String migrate = "migrate database test4dmp shards = 'test4dmp__1' group from '55156':'192.68.1.1':1200:'offline' to '55157':'10.12.1.1':3433:'online'";
|
||||
parse(migrate);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testImportSynctax() {
|
||||
String migrate = "import database test4dmp";
|
||||
parse(migrate);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateTableWithoutDB() {
|
||||
String ddl = "create table t1(c1 int, primary key(c1)) distribute by hash(c1)";
|
||||
parse(ddl);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateDB() {
|
||||
String ddl = "create database test";
|
||||
parse(ddl);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateSchema() {
|
||||
String ddl1 = "create schema test";
|
||||
parse(ddl1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreatePhysicalDB() {
|
||||
String ddl = "create physical database test shards = 1 replication = 1";
|
||||
parse(ddl);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreatePhysicalSchema() {
|
||||
String ddl = "create physical schema test shards = 1 replication = 1";
|
||||
parse(ddl);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreatePhysicalSchema2() {
|
||||
String ddl = "CREATE PHYSICAL DATABASE IF NOT EXISTS shardname\n" +
|
||||
"STORAGE_DEPENDENCY = 'INTERNAL'\n" +
|
||||
"SHARD_ID = 1\n" +
|
||||
"REPLICATION = 3\n" +
|
||||
"REPLICA_TYPE = 'DATA'\n" +
|
||||
"DATA_REPLICATION = 3\n";
|
||||
SQLStatement stmt = parse(ddl);
|
||||
assertEquals("CREATE PHYSICAL DATABASE IF NOT EXISTS shardname OPTIONS (REPLICATION=3 REPLICA_TYPE='DATA' STORAGE_DEPENDENCY='INTERNAL' DATA_REPLICATION=3 SHARD_ID=1 )", stmt.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDropDB() {
|
||||
String ddl = "drop database test";
|
||||
parse(ddl);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDropSchema() {
|
||||
String ddl = "drop schema test";
|
||||
parse(ddl);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDropPhysicalDB() {
|
||||
String ddl = "drop physical database test";
|
||||
parse(ddl);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDropPhysicalSchema() {
|
||||
String ddl = "drop physical schema test";
|
||||
parse(ddl);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateTableWithClustered() {
|
||||
String sql = "CREATE TABLE IF NOT EXISTS `configs` ("
|
||||
+ "`CLUSTER_NAME` varchar(128) NOT NULL,"
|
||||
+ "`KEY` varchar(255) NOT NULL,"
|
||||
+ "`VALUE` text NOT NULL,"
|
||||
+ "`DESCRIPTION` text NULL,"
|
||||
+ "`CREATE_TIME` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,"
|
||||
+ " CLUSTERED INDEX idx_1 (col1,col2),"
|
||||
+ " CLUSTERED KEY idx_2 (col1,col2),"
|
||||
+ "PRIMARY KEY (`CLUSTER_NAME`,`KEY`)"
|
||||
+ ") ENGINE=InnoDB DEFAULT CHARSET=utf8";
|
||||
MySqlCreateTableStatement statement = (MySqlCreateTableStatement) parse(sql);
|
||||
assertEquals("CREATE TABLE IF NOT EXISTS `configs` (\n" +
|
||||
"\t`CLUSTER_NAME` varchar(128) NOT NULL,\n" +
|
||||
"\t`KEY` varchar(255) NOT NULL,\n" +
|
||||
"\t`VALUE` text NOT NULL,\n" +
|
||||
"\t`DESCRIPTION` text NULL,\n" +
|
||||
"\t`CREATE_TIME` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,\n" +
|
||||
"\tCLUSTERED INDEX idx_1(col1, col2),\n" +
|
||||
"\tCLUSTERED KEY idx_2 (col1, col2),\n" +
|
||||
"\tPRIMARY KEY (`CLUSTER_NAME`, `KEY`)\n" +
|
||||
") ENGINE = InnoDB CHARSET = utf8", statement.toString());
|
||||
assertEquals(1, statement.getMysqlIndexes().size());
|
||||
assertEquals(2, statement.getMysqlKeys().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateTableWithClustered3() {
|
||||
String sql = "CREATE TABLE IF NOT EXISTS `configs` ("
|
||||
+ "`CLUSTER_NAME` varchar(128) NOT NULL,"
|
||||
+ "`KEY` varchar(255) NOT NULL,"
|
||||
+ "`VALUE` text NOT NULL,"
|
||||
+ "`DESCRIPTION` text NULL,"
|
||||
+ "`CREATE_TIME` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,"
|
||||
+ " FULLTEXT KEY idx_1 (col1,col2),"
|
||||
+ " FULLTEXT INDEX idx_2 (col1,col2),"
|
||||
+ "PRIMARY KEY (`CLUSTER_NAME`,`KEY`)"
|
||||
+ ") ENGINE=InnoDB DEFAULT CHARSET=utf8";
|
||||
MySqlCreateTableStatement statement = (MySqlCreateTableStatement)parse(sql);
|
||||
assertEquals("CREATE TABLE IF NOT EXISTS `configs` (\n" +
|
||||
"\t`CLUSTER_NAME` varchar(128) NOT NULL,\n" +
|
||||
"\t`KEY` varchar(255) NOT NULL,\n" +
|
||||
"\t`VALUE` text NOT NULL,\n" +
|
||||
"\t`DESCRIPTION` text NULL,\n" +
|
||||
"\t`CREATE_TIME` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,\n" +
|
||||
"\tFULLTEXT KEY idx_1 (col1, col2),\n" +
|
||||
"\tFULLTEXT INDEX idx_2(col1, col2),\n" +
|
||||
"\tPRIMARY KEY (`CLUSTER_NAME`, `KEY`)\n" +
|
||||
") ENGINE = InnoDB CHARSET = utf8", statement.toString());
|
||||
|
||||
assertEquals(1, statement.getMysqlIndexes().size());
|
||||
assertEquals(2, statement.getMysqlKeys().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateTableWithClustered4() {
|
||||
String sql = "CREATE TABLE IF NOT EXISTS `configs` ("
|
||||
+ "`CLUSTER_NAME` varchar(128) NOT NULL,"
|
||||
+ "`KEY` varchar(255) NOT NULL,"
|
||||
+ "`VALUE` text NOT NULL,"
|
||||
+ "`DESCRIPTION` text NULL,"
|
||||
+ "`CREATE_TIME` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,"
|
||||
+ " CLUSTERING KEY idx_1 (col1,col2),"
|
||||
+ " CLUSTERING INDEX idx_2 (col1,col2),"
|
||||
+ "PRIMARY KEY (`CLUSTER_NAME`,`KEY`)"
|
||||
+ ") ENGINE=InnoDB DEFAULT CHARSET=utf8";
|
||||
SQLStatement statement = parse(sql);
|
||||
assertEquals("CREATE TABLE IF NOT EXISTS `configs` (\n" +
|
||||
"\t`CLUSTER_NAME` varchar(128) NOT NULL,\n" +
|
||||
"\t`KEY` varchar(255) NOT NULL,\n" +
|
||||
"\t`VALUE` text NOT NULL,\n" +
|
||||
"\t`DESCRIPTION` text NULL,\n" +
|
||||
"\t`CREATE_TIME` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,\n" +
|
||||
"\tCLUSTERING KEY idx_1 (col1, col2),\n" +
|
||||
"\tCLUSTERING INDEX idx_2(col1, col2),\n" +
|
||||
"\tPRIMARY KEY (`CLUSTER_NAME`, `KEY`)\n" +
|
||||
") ENGINE = InnoDB CHARSET = utf8", statement.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAlterClusteredIndex() {
|
||||
String ddl = "alter table t29_kernel ADD CLUSTERED INDEX index07 (col1);";
|
||||
SQLStatement statement = parse(ddl);
|
||||
Assert.assertEquals("ALTER TABLE t29_kernel\n" +
|
||||
"\tADD CLUSTERED INDEX index07 (col1);", statement.toString());
|
||||
|
||||
ddl = "alter table t29_kernel ADD CLUSTERED KEY index07 (col1);";
|
||||
statement = parse(ddl);
|
||||
Assert.assertEquals("ALTER TABLE t29_kernel\n" +
|
||||
"\tADD CLUSTERED KEY index07 (col1);", statement.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateClusteredIndex() {
|
||||
String ddl = "CREATE CLUSTERED index index10 on t29_kernel(col1);";
|
||||
SQLStatement statement = parse(ddl);
|
||||
Assert.assertEquals("CREATE CLUSTERED INDEX index10 ON t29_kernel (col1);", statement.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* 一级分区
|
||||
*/
|
||||
@Test
|
||||
public void testCreateTable1() {
|
||||
String ddl = "CREATE TABLE db_name.table_name ( "
|
||||
+ "col1 boolean, "
|
||||
+ "col2 tinyint(1),"
|
||||
+ "col3 smallint(2),"
|
||||
+ "col4 int(3),"
|
||||
+ "col5 integer(4),"
|
||||
+ "col6 bigint(5),"
|
||||
+ "col7 float(6,7),"
|
||||
+ "col8 double(7,8),"
|
||||
+ "col9 varchar(9),"
|
||||
+ "col10 date,"
|
||||
+ "col11 time,"
|
||||
+ "col12 timestamp,"
|
||||
+ "col13 geo2d delimiter_tokenizer ',',"
|
||||
+ "col14 geo2d delimiter_tokenizer ':',"
|
||||
+ "col15 mediumint(8),"
|
||||
+ "col16 decimal(10,11),"
|
||||
+ "col17 datetime,"
|
||||
+ "primary key (col1,col6),"
|
||||
+ "key col4_index (col4),"
|
||||
+ "key col6_index (col6),"
|
||||
+ "clustering key col1_col2_index (col1,col2)"
|
||||
// + "clustering key col5_col7_col9_index (col5,col7,col9)"
|
||||
+ ")"
|
||||
+ "DISTRIBUTE BY HASH(col1)";
|
||||
parse(ddl);
|
||||
}
|
||||
|
||||
/**
|
||||
* 二级分区
|
||||
*/
|
||||
@Test
|
||||
public void testCreateTable2() {
|
||||
String ddl = "CREATE TABLE DB_NAME.TABLE_NAME ( "
|
||||
+ "COL1 BOOLEAN, "
|
||||
+ "COL2 TINYINT,"
|
||||
+ "COL3 SMALLINT,"
|
||||
+ "COL4 INT,"
|
||||
+ "COL5 INTEGER,"
|
||||
+ "COL6 BIGINT,"
|
||||
+ "COL7 FLOAT,"
|
||||
+ "COL8 DOUBLE,"
|
||||
+ "COL9 VARCHAR,"
|
||||
+ "COL10 DATE,"
|
||||
+ "COL11 TIME,"
|
||||
+ "COL12 TIMESTAMP,"
|
||||
+ "KEY COL4_INDEX (COL4),"
|
||||
+ "KEY COL6_INDEX (COL6),"
|
||||
+ "CLUSTERING KEY COL1_COL2_INDEX (COL1,COL2),"
|
||||
+ "PRIMARY KEY (COL1,COL6,COL11)"
|
||||
+ ")"
|
||||
+ "DISTRIBUTE BY HASH(COL1)"
|
||||
+ "PARTITION BY VALUE(COL11)"
|
||||
+ "PARTITIONS 365";
|
||||
parse(ddl);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 维度表
|
||||
*/
|
||||
@Test
|
||||
public void testCreateTable3() {
|
||||
String ddl = "CREATE TABLE DB_NAME.TABLE_NAME ( " + "COL1 BOOLEAN, " + "COL2 TINYINT," + "COL3 SMALLINT,"
|
||||
+ "COL4 INT," + "COL5 INTEGER," + "COL6 BIGINT," + "COL7 FLOAT," + "COL8 DOUBLE," + "COL9 VARCHAR,"
|
||||
+ "COL10 DATE," + "COL11 TIME," + "COL12 TIMESTAMP," + "PRIMARY KEY (COL1,COL6)" + ")"
|
||||
+ "DISTRIBUTE BY BROADCAST";
|
||||
parse(ddl);
|
||||
|
||||
ddl = "CREATE TABLE DB_NAME.TABLE_NAME ( " + "COL1 BOOLEAN, " + "COL2 TINYINT," + "COL3 SMALLINT,"
|
||||
+ "COL4 INT," + "COL5 INTEGER," + "COL6 BIGINT," + "COL7 FLOAT," + "COL8 DOUBLE," + "COL9 VARCHAR,"
|
||||
+ "COL10 DATE," + "COL11 TIME," + "COL12 TIMESTAMP," + "PRIMARY KEY (COL1,COL6)" + ")"
|
||||
+ "DISTRIBUTE BY BROADCAST PARTITION BY VALUE(`COL12`) PARTITIONS 30";
|
||||
|
||||
parse(ddl);
|
||||
}
|
||||
|
||||
// test subpartition and archive
|
||||
@Test
|
||||
public void testCreateTable4() {
|
||||
String ddl = "CREATE TABLE DB_NAME.TABLE_NAME ( "
|
||||
+ "COL1 BOOLEAN, "
|
||||
+ "COL2 TINYINT,"
|
||||
+ "COL3 SMALLINT,"
|
||||
+ "COL4 INT,"
|
||||
+ "COL5 INTEGER,"
|
||||
+ "COL6 BIGINT,"
|
||||
+ "COL7 FLOAT,"
|
||||
+ "COL8 DOUBLE,"
|
||||
+ "COL9 VARCHAR,"
|
||||
+ "COL10 DATE,"
|
||||
+ "COL11 TIME,"
|
||||
+ "COL12 TIMESTAMP"
|
||||
+ ")"
|
||||
+ "DISTRIBUTE BY HASH(COL1) "
|
||||
+ "PARTITION BY VALUE(COL11) PARTITIONS -1 "
|
||||
+ "SUBPARTITION BY VALUE(COL6) PARTITIONS 1 "
|
||||
+ "ARCHIVE BY OSS";
|
||||
parse(ddl);
|
||||
}
|
||||
|
||||
// test rt_index_all
|
||||
@Test
|
||||
public void testCreateTable5() {
|
||||
String ddl = "CREATE TABLE DB_NAME.TABLE_NAME ( "
|
||||
+ "COL1 BOOLEAN, "
|
||||
+ "COL2 TINYINT,"
|
||||
+ "COL3 SMALLINT,"
|
||||
+ "COL4 INT,"
|
||||
+ "COL5 INTEGER,"
|
||||
+ "COL6 BIGINT,"
|
||||
+ "COL7 FLOAT,"
|
||||
+ "COL8 DOUBLE,"
|
||||
+ "COL9 VARCHAR,"
|
||||
+ "COL10 DATE,"
|
||||
+ "COL11 TIME,"
|
||||
+ "COL12 TIMESTAMP"
|
||||
+ ")"
|
||||
+ "DISTRIBUTE BY HASH(COL1) "
|
||||
+ "INDEX_ALL='Y' RT_INDEX_ALL='Y'";
|
||||
parse(ddl);
|
||||
}
|
||||
|
||||
// test rt_index auto added for cluster key
|
||||
@Test
|
||||
public void testCreateTable6() {
|
||||
String ddl = "CREATE TABLE DB_NAME.TABLE_NAME ( "
|
||||
+ "COL1 BOOLEAN, "
|
||||
+ "COL2 TINYINT, "
|
||||
+ "clustering key col2_presort_idx(col2)"
|
||||
+ ")"
|
||||
+ "DISTRIBUTE BY HASH(COL1) ";
|
||||
parse(ddl);
|
||||
}
|
||||
// test rt_index auto added for cluster key
|
||||
@Test
|
||||
public void testCreateTable7() {
|
||||
String ddl = "create table test_charset11(charset int) distribute by hash(charset) engine='analysis' default charset='utf8' collate utf8_bin";
|
||||
SQLStatement parse = parse(ddl);
|
||||
System.out.println(parse);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDrop() {
|
||||
String ddl = "DROP TABLE db_name.table_name";
|
||||
parse(ddl);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateTableStringType() {
|
||||
String ddl = "CREATE TABLE baofeng (col1 varchar, col2 string) DISTRIBUTE BY BROADCAST";
|
||||
parse(ddl);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void testCreateTableWithTwoClusterIndex() {
|
||||
String ddl = "CREATE TABLE DB_NAME.TABLE_NAME ( "
|
||||
+ "COL1 BOOLEAN, "
|
||||
+ "COL2 TINYINT,"
|
||||
+ "COL3 SMALLINT,"
|
||||
+ "COL4 INT,"
|
||||
+ "COL5 INTEGER,"
|
||||
+ "COL6 BIGINT,"
|
||||
+ "COL7 FLOAT,"
|
||||
+ "COL8 DOUBLE,"
|
||||
+ "COL9 VARCHAR,"
|
||||
+ "COL10 DATE,"
|
||||
+ "COL11 TIME,"
|
||||
+ "COL12 TIMESTAMP,"
|
||||
+ "KEY COL4_INDEX (COL4),"
|
||||
+ "KEY COL6_INDEX (COL6),"
|
||||
+ "CLUSTERING KEY COL1_COL2_INDEX (COL1,COL2),"
|
||||
+ "CLUSTERING KEY COL5_COL7_COL9_INDEX (COL5,COL7,COL9),"
|
||||
+ "PRIMARY KEY (COL1,COL6,COL11)"
|
||||
+ ")"
|
||||
+ "DISTRIBUTE BY HASH(COL1)"
|
||||
+ "PARTITION BY VALUE(COL11)"
|
||||
+ "PARTITIONS 365";
|
||||
|
||||
parse(ddl);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateBroadcastTableWithPartitionAndPrimayKey() {
|
||||
String ddl = "CREATE TABLE if not exists hehe (col1 varchar, col2 string, primary key(col2)) DISTRIBUTE BY BROADCAST PARTITION BY VALUE(YEARMONTHDAY(col2))";
|
||||
parse(ddl);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testCreateTableIfNotExists() {
|
||||
String ddl = "CREATE TABLE if not exists baofeng (col1 varchar, col2 string) DISTRIBUTE BY BROADCAST";
|
||||
parse(ddl);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateTableWithComment() {
|
||||
String ddl = "CREATE TABLE baofeng (col1 varchar COMMENT '', col2 string COMMENT 'it is string') DISTRIBUTE BY BROADCAST";
|
||||
parse(ddl);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateTableWithNumberColumn() {
|
||||
String ddl = "CREATE TABLE baofeng (123_col1 varchar, a234 string) DISTRIBUTE BY BROADCAST";
|
||||
parse(ddl);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPartitionFunction() {
|
||||
String ddl = "CREATE TABLE baofeng (col1 varchar COMMENT '', col2 string COMMENT 'it is string') DISTRIBUTE BY HASH(col1) PARTITION BY VALUE(DATE_FORMAT(col2, '%Y%m%d')) PARTITIONS 365";
|
||||
parse(ddl);
|
||||
ddl = "CREATE TABLE baofeng (col1 varchar COMMENT '', col2 string COMMENT 'it is string') DISTRIBUTE BY HASH(col1) PARTITION BY VALUE(YEARMONTHDAY(col2)) PARTITIONS 365";
|
||||
parse(ddl);
|
||||
ddl = "CREATE TABLE baofeng (col1 varchar COMMENT '', col2 string COMMENT 'it is string') DISTRIBUTE BY HASH(col1) PARTITION BY VALUE(col2) PARTITIONS 365";
|
||||
parse(ddl);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPkDistributeKey() {
|
||||
String ddl = "CREATE TABLE shiyuan (col1 varchar, col2 string, col3 int, primary key(col2,col3,col1)) distribute by hash(col1, col2)";
|
||||
parse(ddl);
|
||||
|
||||
ddl = "CREATE TABLE shiyuan (col1 varchar, col2 string, col3 int, primary key(col2,col1)) distribute by hash(col1, col2)";
|
||||
parse(ddl);
|
||||
|
||||
try {
|
||||
ddl = "CREATE TABLE shiyuan (col1 varchar, col2 string, col3 int, primary key(col2)) distribute by hash(col1, col2)";
|
||||
parse(ddl);
|
||||
Assert.fail();
|
||||
} catch(Throwable t) {
|
||||
Assert.assertTrue(true);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAlterPartitionNum() {
|
||||
String sql = "alter table ddlDb.t1 partitions 10";
|
||||
SQLStatement stmt = parse(sql);
|
||||
System.out.println(stmt);
|
||||
|
||||
sql = "alter table ddlDb.t partitions 11";
|
||||
parse(sql);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAlterBlockSize() {
|
||||
String sql = "alter table ddlDb.t1 block_size 1000";
|
||||
parseTrue(sql,"ALTER TABLE ddlDb.t1\n" +
|
||||
"\tBLOCK_SIZE 1000");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTableOptions() {
|
||||
String sql = "alter table ddlDb.t compression 'snappy'";
|
||||
parseTrue(sql,"ALTER TABLE ddlDb.t\n" +
|
||||
"\tCOMPRESSION = 'snappy'");
|
||||
|
||||
sql = "alter table ddlDb.t compression = 'zstd'";
|
||||
parseTrue(sql, "ALTER TABLE ddlDb.t\n" +
|
||||
"\tCOMPRESSION = 'zstd'");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateOSSTableWithEndpointCheck() {
|
||||
String ddl = "Create Table `bf_rds_logs_oss_dump` (\n" + "`INS_IP` varchar NOT NULL,\n" + "`INS_PORT` int NOT NULL,\n" + "`CID` int,\n" + "`TID` int,\n" + "`TS` timestamp NOT NULL,\n" + "`ORIGIN_TIME` bigint,\n" + "`USER_IP` varchar,\n" + "`USER` varchar,\n" + "`DB` varchar,\n" + "`FAIL` varchar,\n" + "`LATENCY` bigint,\n" + "`RETURN_ROWS` bigint,\n" + "`UPDATE_ROWS` bigint,\n" + "`CHECK_ROWS` bigint,\n" + "`ISBIND` int,\n" + "`S_HASH` bigint,\n" + "`LOG` varchar,\n" + "`INS_NAME` varchar,\n" + "`DB_TYPE` varchar,\n" + "`EXTENSION` varchar,\n" + "`SQL_TYPE` varchar\n" + ") ENGINE='OSS'\n" + "TABLE_PROPERTIES='{\n" + "\"URL\":\"oss://079903/rdslog_hz/oss_dump\",\n" + "\"endpoint\":\"oss-cn-hangzhou-zmf.aliyuncs.com\",\n" + "\"accessid\":\"3P555zrtaSpb8enU\",\n" + "\"accesskey\":\"DueU9NxvLo4PcOBGL40FzBQlrMjzeu\",\n" + "\"delimiter\":\"|\"\n" + "}'";
|
||||
|
||||
parseTrue(ddl,"CREATE TABLE `bf_rds_logs_oss_dump` (\n" +
|
||||
"\t`INS_IP` varchar NOT NULL,\n" +
|
||||
"\t`INS_PORT` int NOT NULL,\n" +
|
||||
"\t`CID` int,\n" +
|
||||
"\t`TID` int,\n" +
|
||||
"\t`TS` timestamp NOT NULL,\n" +
|
||||
"\t`ORIGIN_TIME` bigint,\n" +
|
||||
"\t`USER_IP` varchar,\n" +
|
||||
"\t`USER` varchar,\n" +
|
||||
"\t`DB` varchar,\n" +
|
||||
"\t`FAIL` varchar,\n" +
|
||||
"\t`LATENCY` bigint,\n" +
|
||||
"\t`RETURN_ROWS` bigint,\n" +
|
||||
"\t`UPDATE_ROWS` bigint,\n" +
|
||||
"\t`CHECK_ROWS` bigint,\n" +
|
||||
"\t`ISBIND` int,\n" +
|
||||
"\t`S_HASH` bigint,\n" +
|
||||
"\t`LOG` varchar,\n" +
|
||||
"\t`INS_NAME` varchar,\n" +
|
||||
"\t`DB_TYPE` varchar,\n" +
|
||||
"\t`EXTENSION` varchar,\n" +
|
||||
"\t`SQL_TYPE` varchar\n" +
|
||||
") ENGINE = 'OSS' TABLE_PROPERTIES = '{\n" +
|
||||
"\"URL\":\"oss://079903/rdslog_hz/oss_dump\",\n" +
|
||||
"\"endpoint\":\"oss-cn-hangzhou-zmf.aliyuncs.com\",\n" +
|
||||
"\"accessid\":\"3P555zrtaSpb8enU\",\n" +
|
||||
"\"accesskey\":\"DueU9NxvLo4PcOBGL40FzBQlrMjzeu\",\n" +
|
||||
"\"delimiter\":\"|\"\n" +
|
||||
"}'");
|
||||
|
||||
// String ddl2 = "Create Table `bf_rds_logs_oss_dump` (\n" + "`INS_IP` varchar NOT NULL,\n" + "`INS_PORT` int NOT NULL,\n" + "`CID` int,\n" + "`TID` int,\n" + "`TS` timestamp NOT NULL,\n" + "`ORIGIN_TIME` bigint,\n" + "`USER_IP` varchar,\n" + "`USER` varchar,\n" + "`DB` varchar,\n" + "`FAIL` varchar,\n" + "`LATENCY` bigint,\n" + "`RETURN_ROWS` bigint,\n" + "`UPDATE_ROWS` bigint,\n" + "`CHECK_ROWS` bigint,\n" + "`ISBIND` int,\n" + "`S_HASH` bigint,\n" + "`LOG` varchar,\n" + "`INS_NAME` varchar,\n" + "`DB_TYPE` varchar,\n" + "`EXTENSION` varchar,\n" + "`SQL_TYPE` varchar\n" + ") ENGINE='OSS'\n" + "TABLE_PROPERTIES='{\n" + "\"URL\":\"oss://079903/rdslog_hz/oss_dump\",\n" + "\"endpoint\":\"oss-ap-southeast-1-internal.aliyuncs.com\",\n" + "\"accessid\":\"3P555zrtaSpb8enU\",\n" + "\"accesskey\":\"DueU9NxvLo4PcOBGL40FzBQlrMjzeu\",\n" + "\"delimiter\":\"|\"\n" + "}'";
|
||||
// try {
|
||||
// parse(ddl2);
|
||||
// Assert.assertTrue(false);
|
||||
// } catch (Throwable e) {
|
||||
// // oss-ap-southeast-1-internal.aliyuncs.com not reachable
|
||||
// Assert.assertTrue(true);
|
||||
// }
|
||||
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -40,6 +40,10 @@ public class PostgresqlResourceTest extends PGTest {
|
||||
// }
|
||||
}
|
||||
|
||||
public void test_1() throws Exception {
|
||||
exec_test("bvt/parser/postgresql-1.txt");
|
||||
}
|
||||
|
||||
public void exec_test(String resource) throws Exception {
|
||||
System.out.println(resource);
|
||||
InputStream is = null;
|
||||
|
||||
Reference in New Issue
Block a user