提交 e6c4f137 编写于 作者: B Becivells 提交者: martianzhang

增加关于 SOAR SQL 重写的 Bats 测试脚本 (#197)

* Bats Test SQL Rewrite

* Bats Test SQL Rewrite and Add golden file
上级 d22add80
# Query: 8093354EDF76BFDA
★ ★ ★ ★ ☆ 80分
```sql
SELECT
b
FROM
c
```
## 最外层 SELECT 未指定 WHERE 条件
* **Item:** CLA.001
* **Severity:** L4
* **Content:** SELECT 语句没有 WHERE 子句,可能检查比预期更多的行(全表扫描)。对于 SELECT COUNT(\*) 类型的请求如果不要求精度,建议使用 SHOW TABLE STATUS 或 EXPLAIN 替代。
# Query: DD1A4C78C3479C1E
★ ★ ★ ★ ☆ 80分
```sql
SELECT
a
FROM
b
```
## 最外层 SELECT 未指定 WHERE 条件
* **Item:** CLA.001
* **Severity:** L4
* **Content:** SELECT 语句没有 WHERE 子句,可能检查比预期更多的行(全表扫描)。对于 SELECT COUNT(\*) 类型的请求如果不要求精度,建议使用 SHOW TABLE STATUS 或 EXPLAIN 替代。
# Query: 7EC60923DD614DF2
★ ☆ ☆ ☆ ☆ 30分
```sql
create table a (a int, b int, c int, d int)
```
## 建议为表添加注释
* **Item:** CLA.011
* **Severity:** L1
* **Content:** 为表添加注释能够使得表的意义更明确,从而为日后的维护带来极大的便利。
## 请为列添加默认值
* **Item:** COL.004
* **Severity:** L1
* **Content:** 请为列添加默认值,如果是 ALTER 操作,请不要忘记将原字段的默认值写上。字段无默认值,当表较大时无法在线变更表结构。
## 列未添加注释
* **Item:** COL.005
* **Severity:** L1
* **Content:** 建议对表中每个列添加注释,来明确每个列在表中的含义及作用。
## 表中包含有太多的列
* **Item:** COL.006
* **Severity:** L3
* **Content:** 表中包含有太多的列
## 未指定主键或主键非 int 或 bigint
* **Item:** KEY.007
* **Severity:** L4
* **Content:** 未指定主键或主键非 int 或 bigint,建议将主键设置为 int unsigned 或 bigint unsigned。
## 请为表选择合适的存储引擎
* **Item:** TBL.002
* **Severity:** L4
* **Content:** 建表或修改表的存储引擎时建议使用推荐的存储引擎,如:innodb
select * from film where length = ?
select * from film where length is null
select * from film having title = ?
select * from sakila.film where length >= ?
select * from sakila.film where length >= ?
select * from film where length between ? and ?
select * from film where title like ?
select * from film where title is not null
select * from film where length = ? and title = ?
select * from film where length > ? and title = ?
select * from film where length > ? and language_id < ? and title = ?
select * from film where length > ? and language_id < ?
select release_year, sum(length) from film where length = ? and language_id = ? group by release_year
select release_year, sum(length) from film where length >= ? group by release_year
select release_year, language_id, sum(length) from film group by release_year, language_id
select release_year, sum(length) from film where length = ? group by language_id)
select release_year, sum(film_id) from film group by release_year
select * from address group by address,district
select title from film where abs(language_id) = ? group by title
select language_id from film where length = ? group by release_year order by language_id
select release_year from film where length = ? group by release_year order by release_year
select * from film where length = ? order by release_year, language_id desc
select release_year from film where length = ? group by release_year order by release_year limit ?
select * from film where length = ? order by release_year limit ?
select * from film order by release_year limit ?
select film_id from film order by release_year limit ?
select * from film where length > ? order by length limit ?
select * from film where length < ? order by length limit ?
select * from customer where address_id in(?+) order by last_name
select * from film where release_year = ? and length != ? order by title
select title from film where release_year = ?
select title, replacement_cost from film where language_id = ? and length = ?
select title from film where language_id > ? and length > ?
select * from film where length = ? and title = ? order by release_year
select * from film where length > ? and title = ? order by release_year
select * from film where length > ? order by release_year
select * from city a inner join country b on a.country_id=b.country_id
select * from city a left join country b on a.country_id=b.country_id
select * from city a right join country b on a.country_id=b.country_id
select * from city a left join country b on a.country_id=b.country_id where b.last_update is null
select * from city a right join country b on a.country_id=b.country_id where a.last_update is null
select * from city a left join country b on a.country_id=b.country_id union select * from city a right join country b on a.country_id=b.country_id
select * from city a right join country b on a.country_id=b.country_id where a.last_update is null union select * from city a left join country b on a.country_id=b.country_id where b.last_update is null
select country_id, last_update from city natural join country
select country_id, last_update from city natural left join country
select country_id, last_update from city natural right join country
select a.country_id, a.last_update from city a straight_join country b on a.country_id=b.country_id
select a.address, a.postal_code from sakila.address a where a.city_id in(?+)
select city from( select city_id from city where city = ? order by last_update desc limit ?, ?) i join city on (i.city_id = city.city_id) join country on (country.country_id = city.country_id) order by city desc
delete city, country from city inner join country using (country_id) where city.city_id = ?
delete city from city left join country on city.country_id = country.country_id where country.country is null
delete a1, a2 from city as a1 inner join country as a2 where a1.country_id=a2.country_id
delete from a1, a2 using city as a1 inner join country as a2 where a1.country_id=a2.country_id
delete from film where length > ?
update city inner join country using(country_id) set city.city = ?, city.last_update = ?, country.country = ? where city.city_id=?
update city inner join country on city.country_id = country.country_id inner join address on city.city_id = address.city_id set city.city = ?, city.last_update = ?, country.country = ? where city.city_id=?
update city, country set city.city = ?, city.last_update = ?, country.country = ? where city.country_id = country.country_id and city.city_id=?
update film set length = ? where language_id = ?
insert into city (country_id) select country_id from country
insert into city (country_id) values(?+)
insert into city (country_id) values(?+)
insert into city (country_id) select ? from dual
replace into city (country_id) select country_id from country
replace into city (country_id) values(?+)
replace into city (country_id) values(?+)
replace into city (country_id) select ? from dual
select film_id from ( select film_id from ( select film_id from ( select film_id from ( select film_id from ( select film_id from ( select film_id from ( select film_id from ( select film_id from ( select film_id from ( select film_id from ( select film_id from ( select film_id from ( select film_id from ( select film_id from ( select film_id from ( select film_id from film ) film ) film ) film ) film ) film ) film ) film ) film ) film ) film ) film ) film ) film ) film ) film ) film
select * from film where language_id = (select language_id from language limit ?)
select * from city i left join country o on i.city_id=o.country_id union select * from city i right join country o on i.city_id=o.country_id
select * from (select * from actor where last_update=? and last_name=?) t where last_update=? and last_name=? group by first_name
select * from city i left join country o on i.city_id=o.country_id union select * from city i right join country o on i.city_id=o.country_id
select * from city i left join country o on i.city_id=o.country_id where o.country_id is null union select * from city i right join country o on i.city_id=o.country_id where i.city_id is null
select first_name,last_name,email from customer straight_join address on customer.address_id=address.address_id
select id,name from (select address from customer_list where sid=? order by phone limit ?,?) a join customer_list l on (a.address=l.address) join city c on (c.city=l.city) order by phone desc
select * from film where date(last_update)=?
select last_update from film group by date(last_update)
select last_update from film order by date(last_update)
select description from film where description in(?+) group by description
alter table address add index idx_city_id(city_id)
alter table inventory add index `idx_store_film` (`store_id`,`film_id`)
alter table inventory add index `idx_store_film` (`store_id`,`film_id`),add index `idx_store_film` (`store_id`,`film_id`),add index `idx_store_film` (`store_id`,`film_id`)
select date_format(t.last_update, ?), count(distinct (t.city)) from city t where t.last_update > ? and t.city like ? and t.city = ? group by date_format(t.last_update, ?) order by date_format(t.last_update, ?)
create table hello.t (id int unsigned)
select * from tb where data >= ?
alter table tb alter column id drop default
select state, COUNT(*) from Drivers where state in ('GA', 'TX') group by state order by state asc
ALTER TABLE `t2` DROP COLUMN c, DROP COLUMN d ;
select country_id from city where (col2 in (1, 2)) or col1 in (1, 3)
select sum(col1) from tbl group by col order by null
select film_id, title, description, release_year, language_id, original_language_id, rental_duration, rental_rate, length, replacement_cost, rating, special_features, last_update from film where length > 120
select country_id from city union all select country_id from country
SELECT * FROM film WHERE LENGTH = 86;
SELECT * FROM film WHERE LENGTH IS NULL;
SELECT * FROM film HAVING title = 'abc';
SELECT * FROM sakila. film WHERE LENGTH >= 60;
SELECT * FROM sakila. film WHERE LENGTH >= '60';
SELECT * FROM film WHERE LENGTH BETWEEN 60 AND 84;
SELECT * FROM film WHERE title LIKE 'AIR%';
SELECT * FROM film WHERE title IS NOT NULL;
SELECT * FROM film WHERE LENGTH = 114 AND title = 'ALABAMA DEVIL';
SELECT * FROM film WHERE LENGTH > 100 AND title = 'ALABAMA DEVIL';
SELECT * FROM film WHERE LENGTH > 100 AND language_id < 10 AND title = 'xyz';
SELECT * FROM film WHERE LENGTH > 100 AND language_id < 10;
SELECT release_year, SUM( LENGTH) FROM film WHERE LENGTH = 123 AND language_id = 1 GROUP BY release_year;
SELECT release_year, SUM( LENGTH) FROM film WHERE LENGTH >= 123 GROUP BY release_year;
SELECT release_year, language_id, SUM( LENGTH) FROM film GROUP BY release_year, language_id;
SELECT release_year, SUM( LENGTH) FROM film WHERE LENGTH = 123 GROUP BY release_year, (LENGTH+ language_id);
SELECT release_year, SUM( film_id) FROM film GROUP BY release_year;
SELECT * FROM address GROUP BY address, district;
SELECT title FROM film WHERE ABS( language_id) = 3 GROUP BY title;
SELECT language_id FROM film WHERE LENGTH = 123 GROUP BY release_year ORDER BY language_id;
SELECT release_year FROM film WHERE LENGTH = 123 GROUP BY release_year ORDER BY release_year;
SELECT * FROM film WHERE LENGTH = 123 ORDER BY release_year ASC, language_id DESC;
SELECT release_year FROM film WHERE LENGTH = 123 GROUP BY release_year ORDER BY release_year LIMIT 10;
SELECT * FROM film WHERE LENGTH = 123 ORDER BY release_year LIMIT 10;
SELECT * FROM film ORDER BY release_year LIMIT 10;
SELECT film_id FROM film ORDER BY release_year LIMIT 10;
SELECT * FROM film WHERE LENGTH > 100 ORDER BY LENGTH LIMIT 10;
SELECT * FROM film WHERE LENGTH < 100 ORDER BY LENGTH LIMIT 10;
SELECT * FROM customer WHERE address_id in (224, 510) ORDER BY last_name;
SELECT * FROM film WHERE release_year = 2016 AND LENGTH != 1 ORDER BY title;
SELECT title FROM film WHERE release_year = 1995;
SELECT title, replacement_cost FROM film WHERE language_id = 5 AND LENGTH = 70;
SELECT title FROM film WHERE language_id > 5 AND LENGTH > 70;
SELECT * FROM film WHERE LENGTH = 100 AND title = 'xyz' ORDER BY release_year;
SELECT * FROM film WHERE LENGTH > 100 AND title = 'xyz' ORDER BY release_year;
SELECT * FROM film WHERE LENGTH > 100 ORDER BY release_year;
SELECT * FROM city a INNER JOIN country b ON a. country_id= b. country_id;
SELECT * FROM city a LEFT JOIN country b ON a. country_id= b. country_id;
SELECT * FROM city a RIGHT JOIN country b ON a. country_id= b. country_id;
SELECT * FROM city a LEFT JOIN country b ON a. country_id= b. country_id WHERE b. last_update IS NULL;
SELECT * FROM city a RIGHT JOIN country b ON a. country_id= b. country_id WHERE a. last_update IS NULL;
SELECT * FROM city a LEFT JOIN country b ON a. country_id= b. country_id UNION SELECT * FROM city a RIGHT JOIN country b ON a. country_id= b. country_id;
SELECT * FROM city a RIGHT JOIN country b ON a. country_id= b. country_id WHERE a. last_update IS NULL UNION SELECT * FROM city a LEFT JOIN country b ON a. country_id= b. country_id WHERE b. last_update IS NULL;
SELECT country_id, last_update FROM city NATURAL JOIN country;
SELECT country_id, last_update FROM city NATURAL LEFT JOIN country;
SELECT country_id, last_update FROM city NATURAL RIGHT JOIN country;
SELECT a. country_id, a. last_update FROM city a STRAIGHT_JOIN country b ON a. country_id= b. country_id;
SELECT a. address, a. postal_code FROM sakila. address a WHERE a. city_id IN ( SELECT c. city_id FROM sakila. city c);
SELECT city FROM( SELECT city_id FROM city WHERE city = "A Corua (La Corua)" ORDER BY last_update DESC LIMIT 50, 10) I JOIN city ON (I. city_id = city. city_id) JOIN country ON (country. country_id = city. country_id) ORDER BY city DESC;
DELETE city, country FROM city INNER JOIN country using (country_id) WHERE city. city_id = 1;
DELETE city FROM city LEFT JOIN country ON city. country_id = country. country_id WHERE country. country IS NULL;
DELETE a1, a2 FROM city AS a1 INNER JOIN country AS a2 WHERE a1. country_id= a2. country_id;
DELETE FROM a1, a2 USING city AS a1 INNER JOIN country AS a2 WHERE a1. country_id= a2. country_id;
DELETE FROM film WHERE LENGTH > 100;
UPDATE city INNER JOIN country USING( country_id) SET city. city = 'Abha', city. last_update = '2006-02-15 04:45:25', country. country = 'Afghanistan' WHERE city. city_id= 10;
UPDATE city INNER JOIN country ON city. country_id = country. country_id INNER JOIN address ON city. city_id = address. city_id SET city. city = 'Abha', city. last_update = '2006-02-15 04:45:25', country. country = 'Afghanistan' WHERE city. city_id= 10;
UPDATE city, country SET city. city = 'Abha', city. last_update = '2006-02-15 04:45:25', country. country = 'Afghanistan' WHERE city. country_id = country. country_id AND city. city_id= 10;
UPDATE film SET LENGTH = 10 WHERE language_id = 20;
INSERT INTO city (country_id) SELECT country_id FROM country;
INSERT INTO city (country_id) VALUES (1), (2), (3);
INSERT INTO city (country_id) VALUES (10);
INSERT INTO city (country_id) SELECT 10 FROM DUAL;
REPLACE INTO city (country_id) SELECT country_id FROM country;
REPLACE INTO city (country_id) VALUES (1), (2), (3);
REPLACE INTO city (country_id) VALUES (10);
REPLACE INTO city (country_id) SELECT 10 FROM DUAL;
SELECT film_id FROM ( SELECT film_id FROM ( SELECT film_id FROM ( SELECT film_id FROM ( SELECT film_id FROM ( SELECT film_id FROM ( SELECT film_id FROM ( SELECT film_id FROM ( SELECT film_id FROM ( SELECT film_id FROM ( SELECT film_id FROM ( SELECT film_id FROM ( SELECT film_id FROM ( SELECT film_id FROM ( SELECT film_id FROM ( SELECT film_id FROM ( SELECT film_id FROM film ) film ) film ) film ) film ) film ) film ) film ) film ) film ) film ) film ) film ) film ) film ) film ) film;
SELECT * FROM film WHERE language_id = ( SELECT language_id FROM language LIMIT 1);
SELECT * FROM city i LEFT JOIN country o ON i. city_id= o. country_id UNION SELECT * FROM city i RIGHT JOIN country o ON i. city_id= o. country_id;
SELECT * FROM ( SELECT * FROM actor WHERE last_update= '2006-02-15 04:34:33' AND last_name= 'CHASE' ) t WHERE last_update= '2006-02-15 04:34:33' AND last_name= 'CHASE' GROUP BY first_name;
SELECT * FROM city i LEFT JOIN country o ON i. city_id= o. country_id UNION SELECT * FROM city i RIGHT JOIN country o ON i. city_id= o. country_id;
SELECT * FROM city i LEFT JOIN country o ON i. city_id= o. country_id WHERE o. country_id is null UNION SELECT * FROM city i RIGHT JOIN country o ON i. city_id= o. country_id WHERE i. city_id is null;
SELECT first_name, last_name, email FROM customer STRAIGHT_JOIN address ON customer. address_id= address. address_id;
SELECT ID, name FROM ( SELECT address FROM customer_list WHERE SID= 1 ORDER BY phone LIMIT 50, 10) a JOIN customer_list l ON (a. address= l. address) JOIN city c ON (c. city= l. city) ORDER BY phone desc;
SELECT * FROM film WHERE DATE( last_update) = '2006-02-15';
SELECT last_update FROM film GROUP BY DATE( last_update);
SELECT last_update FROM film ORDER BY DATE( last_update);
SELECT description FROM film WHERE description IN( 'NEWS', 'asd' ) GROUP BY description;
ALTER TABLE address ADD index idx_city_id( city_id);
ALTER TABLE inventory ADD index `idx_store_film` ( `store_id`, `film_id`);
ALTER TABLE inventory ADD index `idx_store_film` ( `store_id`, `film_id`), ADD index `idx_store_film` ( `store_id`, `film_id`), ADD index `idx_store_film` ( `store_id`, `film_id`);
SELECT DATE_FORMAT( t. last_update, '%Y-%m-%d' ), COUNT( DISTINCT ( t. city)) FROM city t WHERE t. last_update > '2018-10-22 00:00:00' AND t. city LIKE '%Chrome%' AND t. city = 'eip' GROUP BY DATE_FORMAT( t. last_update, '%Y-%m-%d' ) ORDER BY DATE_FORMAT( t. last_update, '%Y-%m-%d' );
create table hello. t (id int unsigned);
SELECT * FROM tb WHERE data >= '';
ALTER TABLE tb alter column id DROP DEFAULT;
......@@ -29,7 +29,7 @@ load test_helper
}
# 5. soar 使用 config 配置文件路径是否正确
# 13. soar -check-config 数据库连接配置检查 *
# 13. soar -check-config 数据库连接配置检查 *
# soar 数据库测试(线上、线下、-allow-online-as-test)
@test "Check config cases" {
run ${SOAR_BIN_ENV} -check-config
......@@ -61,7 +61,7 @@ load test_helper
echo "${output}"
[ $status -eq 0 ]
}
# 10. report 为 json 格式是否正常
# 10. report 为 json 格式是否正常
@test "Check soar report for json" {
${SOAR_BIN} -query "select * from film" \
-report-type json > ${BATS_TMP_DIRNAME}/${BATS_TEST_NAME}.golden
......@@ -70,7 +70,7 @@ load test_helper
[ $status -eq 0 ]
}
# 10. report 为 markdown 格式是否正常
# 10. report 为 markdown 格式是否正常
@test "Check soar report for markdown" {
${SOAR_BIN} -query "select * from film" \
-report-type markdown > ${BATS_TMP_DIRNAME}/${BATS_TEST_NAME}.golden
......@@ -89,7 +89,7 @@ load test_helper
[ $status -eq 0 ]
}
# 12. 黑名单功能是否正常
# 12. 黑名单功能是否正常
# soar 的日志和黑名单的相对路径都相对于 soar 的二进制文件路径说的
@test "Check soar blacklist" {
run ${SOAR_BIN} -blacklist ../etc/soar.blacklist -query "show processlist;"
......@@ -97,17 +97,17 @@ load test_helper
[ -z ${output} ]
}
# 13. soar -check-config 数据库连接配置检查 *
# 13. soar -check-config 数据库连接配置检查 *
# 参见 5
# 14. soar -help 检查
# 14. soar -help 检查
@test "Check soar help" {
run ${SOAR_BIN} -help
[ $status -eq 2 ]
[ "${#lines[@]}" -gt 30 ]
}
# 15. soar 数据库测试(线上、线下、-allow-online-as-test)
# 15. soar 数据库测试(线上、线下、-allow-online-as-test)
# 参见 5
# 16. 语法检查(正确)
......@@ -123,7 +123,7 @@ load test_helper
[ -n $ouput ]
}
# 17. dsn 检查
# 17. dsn 检查
@test "Check soar test dsn root:passwd@host:port/db" {
run ${SOAR_BIN} -online-dsn="root:pase@D@192.168.12.11:3306/testDB" -print-config
[ $(expr "$output" : ".*user: root") -ne 0 ]
......
......@@ -7,6 +7,7 @@ load test_helper
[ $status -eq 0 ]
}
#
@test "Check get tables from SQL" {
${SOAR_BIN} -list-test-sqls | ${SOAR_BIN} -report-type tables > ${BATS_TMP_DIRNAME}/${BATS_TEST_NAME}.golden
${SOAR_BIN} -list-test-sqls | ${SOAR_BIN} -report-type tables -test-dsn "/sakila" >> ${BATS_TMP_DIRNAME}/${BATS_TEST_NAME}.golden
......@@ -15,3 +16,158 @@ load test_helper
[ $status -eq 0 ]
}
# SQL 语法检查
# 1. soar SQL 分隔符是否正常 (-delimiter)
@test "Check Soar Delimiter" {
${SOAR_BIN} -delimiter "@" -query "select b from c @ select a from b" > ${BATS_TMP_DIRNAME}/${BATS_TEST_NAME}.golden
run golden_diff
[ $status -eq 0 ]
}
# 2. max-column-count (ddl 中才会有提示)
@test "Check Soar Max Column Count" {
${SOAR_BIN} -query "create table a (a int,b int,c int,d int)" --max-column-count 3 > ${BATS_TMP_DIRNAME}/${BATS_TEST_NAME}.golden
run golden_diff
[ $status -eq 0 ]
}
# SQL 指纹检查
# 1. 检测各种类型的 SQL 语句,以及多条 SQL 语句的情况下,指纹是否正确
@test "Check Soar SQL Fingerprint" {
${SOAR_BIN} -list-test-sqls | ${SOAR_BIN} -report-type "fingerprint" > ${BATS_TMP_DIRNAME}/${BATS_TEST_NAME}.golden
run golden_diff
[ $status -eq 0 ]
}
# 1. 检测各种类型的 SQL 语句,以及多条SQL语句的情况下,压缩是否正确
# 1. 检测各种类型的 SQL 语句,以及多条SQL语句的情况下,美化是否正确
@test "Check Soar SQL pretty And Compress " {
${SOAR_BIN} -list-test-sqls |${SOAR_BIN} -report-type "pretty"| ${SOAR_BIN} -report-type "compress" > ${BATS_TMP_DIRNAME}/${BATS_TEST_NAME}.golden
run golden_diff
[ $status -eq 0 ]
}
# SQL 改写检查
# 1. 检查 SQL 改写 dml2select
@test "Check Soar SQL Rewrite Dml2select " {
${SOAR_BIN} -report-type "rewrite" -rewrite-rules "dml2select" \
-query "DELETE FROM film WHERE length > 100" > ${BATS_TMP_DIRNAME}/${BATS_TEST_NAME}.golden
run golden_diff
[ $status -eq 0 ]
}
# 2. 检查 SQL 改写 Star2columns
@test "Check Soar SQL Rewrite Star2columns " {
${SOAR_BIN_ENV} -report-type "rewrite" -rewrite-rules "star2columns" \
-query "select * from film where length > 120" > ${BATS_TMP_DIRNAME}/${BATS_TEST_NAME}.golden
run golden_diff
[ $status -eq 0 ]
}
# 4. 检查 SQL 改写 Having
@test "Check Soar SQL Rewrite Having " {
${SOAR_BIN} -report-type "rewrite" -rewrite-rules "having" \
-query "SELECT state, COUNT(*) FROM Drivers GROUP BY state HAVING state IN ('GA', 'TX') ORDER BY state" > ${BATS_TMP_DIRNAME}/${BATS_TEST_NAME}.golden
run golden_diff
[ $status -eq 0 ]
}
# 5. 检查 SQL 改写 orderbynull
@test "Check Soar SQL Rewrite Orderbynull " {
${SOAR_BIN} -report-type "rewrite" -rewrite-rules "orderbynull" \
-query "SELECT sum(col1) FROM tbl GROUP BY col" > ${BATS_TMP_DIRNAME}/${BATS_TEST_NAME}.golden
run golden_diff
[ $status -eq 0 ]
}
# 6. 检查 SQL 改写 unionall
@test "Check Soar SQL Rewrite Unionall " {
${SOAR_BIN} -report-type "rewrite" -rewrite-rules "unionall" \
-query "select country_id from city union select country_id from country" > ${BATS_TMP_DIRNAME}/${BATS_TEST_NAME}.golden
run golden_diff
[ $status -eq 0 ]
}
# 7. 检查 SQL 改写 or2in
@test "Check Soar SQL Rewrite Or2in " {
${SOAR_BIN} -report-type "rewrite" -rewrite-rules "or2in" \
-query "select country_id from city where col1 = 1 or (col2 = 1 or col2 = 2 ) or col1 = 3;" > ${BATS_TMP_DIRNAME}/${BATS_TEST_NAME}.golden
run golden_diff
[ $status -eq 0 ]
}
# 7. 检查 SQL 改写 dmlorderby
@test "Check Soar SQL Rewrite Dmlorderby " {
${SOAR_BIN} -report-type "rewrite" -rewrite-rules "dmlorderby" \
-query "DELETE FROM tbl WHERE col1=1 ORDER BY col" > ${BATS_TMP_DIRNAME}/${BATS_TEST_NAME}.golden
run golden_diff
[ $status -eq 0 ]
}
# 8. 检查 SQL 改写 distinctstar
@test "Check Soar SQL Rewrite Distinctstar " {
${SOAR_BIN} -report-type "rewrite" -rewrite-rules "distinctstar" \
-query "SELECT DISTINCT * FROM film;" > ${BATS_TMP_DIRNAME}/${BATS_TEST_NAME}.golden
run golden_diff
[ $status -eq 0 ]
}
# 9. 检查 SQL 改写 standard
@test "Check Soar SQL Rewrite Standard " {
${SOAR_BIN} -report-type "rewrite" -rewrite-rules "standard" \
-query "SELECT sum(col1) FROM tbl GROUP BY 1;" > ${BATS_TMP_DIRNAME}/${BATS_TEST_NAME}.golden
run golden_diff
[ $status -eq 0 ]
}
# 10. 检查 SQL 改写 mergealter
@test "Check Soar SQL Rewrite Mergealter " {
${SOAR_BIN} -report-type "rewrite" -rewrite-rules "mergealter" \
-query "ALTER TABLE t2 DROP COLUMN c;ALTER TABLE t2 DROP COLUMN d;" > ${BATS_TMP_DIRNAME}/${BATS_TEST_NAME}.golden
run golden_diff
[ $status -eq 0 ]
}
# 11. 检查 SQL 改写 alwaystrue
@test "Check Soar SQL Rewrite Alwaystrue " {
${SOAR_BIN} -report-type "rewrite" -rewrite-rules "alwaystrue" \
-query "SELECT count(col) FROM tbl where 'a'= 'a' or ('b' = 'b' and a = 'b');" > ${BATS_TMP_DIRNAME}/${BATS_TEST_NAME}.golden
run golden_diff
[ $status -eq 0 ]
}
# 12. 检查 SQL 改写 countstar
@test "Check Soar SQL Rewrite Countstar " {
${SOAR_BIN} -report-type "rewrite" -rewrite-rules "countstar" \
-query "SELECT count(col) FROM tbl GROUP BY 1;" > ${BATS_TMP_DIRNAME}/${BATS_TEST_NAME}.golden
run golden_diff
[ $status -eq 0 ]
}
# 16. 检查 SQL 改写 truncate
@test "Check Soar SQL Rewrite Truncate " {
${SOAR_BIN} -report-type "rewrite" -rewrite-rules "truncate" \
-query "DELETE FROM tbl" > ${BATS_TMP_DIRNAME}/${BATS_TEST_NAME}.golden
run golden_diff
[ $status -eq 0 ]
}
# 17. 检查 SQL 改写 rmparenthesis
@test "Check Soar SQL Rewrite Rmparenthesis " {
${SOAR_BIN} -report-type "rewrite" -rewrite-rules "rmparenthesis" \
-query "select col from a where (col = 1)" > ${BATS_TMP_DIRNAME}/${BATS_TEST_NAME}.golden
run golden_diff
[ $status -eq 0 ]
}
# 18. 检查 SQL 改写 delimiter
@test "Check Soar SQL Rewrite Delimiter " {
${SOAR_BIN} -report-type "rewrite" -rewrite-rules "delimiter" \
-query "use sakila" > ${BATS_TMP_DIRNAME}/${BATS_TEST_NAME}.golden
run golden_diff
[ $status -eq 0 ]
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册