Skip to content

Commit ae8a5da

Browse files
[BugFix] SQLTester strict empty result validation for SQL statements (backport #71982) (#71993)
Signed-off-by: trueeyu <lxhhust350@qq.com> Co-authored-by: trueeyu <lxhhust350@qq.com>
1 parent 65e2279 commit ae8a5da

16 files changed

Lines changed: 132 additions & 80 deletions

File tree

test/lib/skip.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@
2525
skip_res_cmd = [
2626
"show backends",
2727
"show backends;",
28-
"select connection_id()",
29-
"select connection_id();",
28+
"select connection_id\\(\\)",
29+
"select connection_id\\(\\);",
3030
".*explain costs select.*",
31-
"rand()",
31+
"rand\\(\\)",
3232
"show stats meta",
3333
"SHOW RESOURCES",
3434
"show alter table column",
@@ -46,7 +46,7 @@
4646
"SELECT DISTINCT k1 FROM aggregate_par_tbl LIMIT 1",
4747
"select.* db_id.*",
4848
"select.* table_id.*",
49-
"SELECT * FROM unnest_es_external_table limit 1",
49+
"SELECT \\* FROM unnest_es_external_table limit 1",
5050
"select last_query_id",
5151
"select uuid",
5252
"select unix_timestamp",
@@ -58,6 +58,7 @@
5858
"select current_time\\(\\)",
5959
"select curdate\\(\\)",
6060
"select current_date\\(\\)",
61+
"^result=.*",
6162
"refresh materialized view.*",
6263
"REFRESH MATERIALIZED VIEW.*"
6364
]

test/lib/sr_sql_lib.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1375,17 +1375,17 @@ def check(sql_id, sql, exp, act, order=False, ori_sql=None):
13751375
log.info("[%s.check] only check with no Error" % sql_id)
13761376
tools.assert_equal(0, act[0], "shell %s error: %s" % (sql, act))
13771377
elif not sql.startswith(FUNCTION_FLAG):
1378-
# Function, without error msg
1379-
log.info("[%s.check] only check with no Error" % sql_id)
1378+
# Explicit empty result block: verify no error and result is empty
1379+
log.info("[%s.check] check no Error and empty result" % sql_id)
13801380
tools.assert_false(str(act).startswith("E: "), "sql result not match: actual with E(%s)" % str(act))
1381+
if not any(re.search(c, sql) for c in skip.skip_res_cmd):
1382+
tools.assert_equal("", act, "sql result not match: expected empty but got (%s)" % str(act))
13811383
else:
1382-
# SQL, with empty result
1384+
# function call with empty result
13831385
exp = []
13841386
return
13851387

1386-
if any(re.compile(condition).search(sql) is not None for condition in skip.skip_res_cmd) or any(
1387-
condition in sql for condition in skip.skip_res_cmd
1388-
):
1388+
if any(re.search(condition, sql) for condition in skip.skip_res_cmd):
13891389
log.info("[%s.check] skip check" % sql_id)
13901390
return
13911391

test/sql/test_agg/R/test_serialize_key_agg

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ create table t0 (
99
select distinct c0, c1 from t0 order by c0, c1 desc limit 10;
1010
-- result:
1111
-- !result
12-
select distinct c0, c1 from (select * from t0 union all select space(1000000) as c0, space(1000000) as c1, space(1000000) as c2) tb order by c0, c1 desc limit 10;
13-
-- result:
14-
-- !result
12+
[UC]select distinct c0, c1 from (select * from t0 union all select space(1000000) as c0, space(1000000) as c1, space(1000000) as c2) tb order by c0, c1 desc limit 10;
1513
select length(c0), max(length(c1)), max(length(c2)) from (select * from t0 union all select space(1000000) as c0, space(1000000) as c1, space(1000000) as c2) tb group by c0 order by 1, 2 desc limit 10;
1614
-- result:
1715
1000000 1000000 1000000

test/sql/test_agg/T/test_serialize_key_agg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ create table t0 (
66
) DUPLICATE KEY(c0) DISTRIBUTED BY HASH(c0) BUCKETS 3 PROPERTIES('replication_num' = '1');
77

88
select distinct c0, c1 from t0 order by c0, c1 desc limit 10;
9-
select distinct c0, c1 from (select * from t0 union all select space(1000000) as c0, space(1000000) as c1, space(1000000) as c2) tb order by c0, c1 desc limit 10;
9+
[UC]select distinct c0, c1 from (select * from t0 union all select space(1000000) as c0, space(1000000) as c1, space(1000000) as c2) tb order by c0, c1 desc limit 10;
1010
select length(c0), max(length(c1)), max(length(c2)) from (select * from t0 union all select space(1000000) as c0, space(1000000) as c1, space(1000000) as c2) tb group by c0 order by 1, 2 desc limit 10;
1111
insert into t0 SELECT generate_series, 4096 - generate_series, generate_series FROM TABLE(generate_series(1, 4096));
1212

test/sql/test_array/R/test_array

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,7 @@ select array_generate(3,3);
320320
-- !result
321321
select array_generate(3,2,1);
322322
-- result:
323+
[]
323324
-- !result
324325

325326
-- name: test_array_repeat
@@ -333,6 +334,7 @@ select array_repeat([1,2],3);
333334
-- !result
334335
select array_repeat(1,-1);
335336
-- result:
337+
[]
336338
-- !result
337339
CREATE TABLE IF NOT EXISTS repeat_test (COLA INT, COLB INT) PROPERTIES ("replication_num"="1");
338340
-- result:

test/sql/test_bitmap_functions/R/test_bitmap_to_array

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ insert into t1 select 1, bitmap_empty();
1616
-- !result
1717
select bitmap_to_array(c2) from t1;
1818
-- result:
19+
[]
1920
-- !result
2021
truncate table t1;
2122
-- result:

test/sql/test_deltalake/R/test_deltalake_analyze

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,18 @@ analyze table delta_test_${uuid0}.delta_oss_db.t_partition_timestamp_ntz;
5353
-- !result
5454
select column_name, row_count, data_size, hll_cardinality(ndv), `max`, `min` from default_catalog._statistics_.external_column_statistics
5555
where catalog_name="delta_test_${uuid0}" and db_name="delta_oss_db" and table_name="t_partition_timestamp_ntz"
56-
order by column_name;
56+
order by column_name, max;
5757
-- result:
58+
col_int 1 4 1 1 1
59+
col_int 1 4 1 2 2
60+
col_int 1 4 1 3 3
61+
col_int 1 4 1 4 4
62+
col_int 1 4 1 5 5
63+
col_timestamp_ntz 1 8 1 2024-01-02 01:02:03 2024-01-02 01:02:03
64+
col_timestamp_ntz 1 8 1 2024-01-03 04:05:06 2024-01-03 04:05:06
65+
col_timestamp_ntz 1 8 1 2024-01-04 01:02:03 2024-01-04 01:02:03
66+
col_timestamp_ntz 1 8 1 2024-01-05 04:05:06 2024-01-05 04:05:06
67+
col_timestamp_ntz 1 8 0
5868
-- !result
5969
drop catalog delta_test_${uuid0}
6070
-- result:

test/sql/test_deltalake/T/test_deltalake_analyze

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ select column_name, row_count, data_size, hll_cardinality(ndv), `max`, `min` fro
2626
analyze table delta_test_${uuid0}.delta_oss_db.t_partition_timestamp_ntz;
2727
select column_name, row_count, data_size, hll_cardinality(ndv), `max`, `min` from default_catalog._statistics_.external_column_statistics
2828
where catalog_name="delta_test_${uuid0}" and db_name="delta_oss_db" and table_name="t_partition_timestamp_ntz"
29-
order by column_name;
29+
order by column_name, max;
3030

3131
-- drop catalog
3232
drop catalog delta_test_${uuid0}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,75 @@
11
-- name: test_applicable_roles
22
CREATE DATABASE db_${uuid0};
3+
-- result:
4+
-- !result
35
USE db_${uuid0};
6+
-- result:
7+
-- !result
48

59
SELECT * FROM information_schema.applicable_roles ORDER BY ROLE_NAME ASC;
10+
-- result:
11+
root % root % root % NO NO NO
12+
-- !result
613

714
SELECT * FROM information_schema.applicable_roles WHERE ROLE_NAME = 'root';
15+
-- result:
16+
root % root % root % NO NO NO
17+
-- !result
818

919
SELECT * FROM information_schema.applicable_roles WHERE IS_GRANTABLE = 'NO';
20+
-- result:
21+
root % root % root % NO NO NO
22+
-- !result
1023

1124
SELECT * FROM information_schema.applicable_roles WHERE IS_DEFAULT = 'NO';
25+
-- result:
26+
root % root % root % NO NO NO
27+
-- !result
1228

1329
SELECT * FROM information_schema.applicable_roles WHERE IS_MANDATORY = 'NO';
30+
-- result:
31+
root % root % root % NO NO NO
32+
-- !result
1433

1534
SELECT * FROM information_schema.applicable_roles WHERE ROLE_NAME LIKE 'r%' ORDER BY ROLE_NAME ASC;
35+
-- result:
36+
root % root % root % NO NO NO
37+
-- !result
1638

1739
SELECT * FROM information_schema.applicable_roles WHERE ROLE_NAME IN ('root', 'admin') ORDER BY ROLE_NAME ASC;
40+
-- result:
41+
root % root % root % NO NO NO
42+
-- !result
1843

1944
SELECT * FROM information_schema.applicable_roles ORDER BY IS_DEFAULT DESC, ROLE_NAME ASC;
45+
-- result:
46+
root % root % root % NO NO NO
47+
-- !result
2048

2149
SELECT * FROM information_schema.applicable_roles WHERE ROLE_NAME = 'NON_EXISTENT_ROLE';
50+
-- result:
51+
-- !result
2252

2353
DROP USER IF EXISTS test_user;
54+
-- result:
55+
-- !result
2456
CREATE USER test_user IDENTIFIED BY 'password';
57+
-- result:
58+
-- !result
2559

2660
GRANT SELECT ON information_schema.applicable_roles TO test_user;
61+
-- result:
62+
-- !result
2763

2864
SELECT * FROM information_schema.applicable_roles;
65+
-- result:
66+
root % root % root % NO NO NO
67+
-- !result
2968

3069
DROP USER test_user;
70+
-- result:
71+
-- !result
3172

3273
DROP DATABASE db_${uuid0};
74+
-- result:
75+
-- !result

test/sql/test_information_schema/R/test_keywords

Lines changed: 54 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,48 +8,80 @@ USE db_${uuid0};
88

99
SELECT * FROM information_schema.keywords ORDER BY word ASC;
1010
-- result:
11+
DELETE 1
12+
INDEX 1
13+
INSERT 1
14+
PASSWORD 0
15+
SELECT 1
16+
TABLE 1
17+
UPDATE 1
18+
USER 0
19+
VIEW 1
1120
-- !result
12-
-- WORD | RESERVED
13-
-- ---------|---------
14-
-- DELETE | true
15-
-- INDEX | true
16-
-- INSERT | true
17-
-- PASSWORD | false
18-
-- SELECT | true
19-
-- TABLE | true
20-
-- UPDATE | true
21-
-- USER | false
22-
-- VIEW | true
2321

2422
SELECT * FROM information_schema.keywords WHERE RESERVED = true ORDER BY word ASC;
2523
-- result:
24+
DELETE 1
25+
INDEX 1
26+
INSERT 1
27+
SELECT 1
28+
TABLE 1
29+
UPDATE 1
30+
VIEW 1
2631
-- !result
2732

2833
SELECT * FROM information_schema.keywords WHERE RESERVED = false ORDER BY word ASC;
2934
-- result:
35+
PASSWORD 0
36+
USER 0
3037
-- !result
3138

3239
SELECT * FROM information_schema.keywords ORDER BY word ASC LIMIT 3 OFFSET 2;
3340
-- result:
41+
INSERT 1
42+
PASSWORD 0
43+
SELECT 1
3444
-- !result
3545

3646
SELECT * FROM information_schema.keywords WHERE word LIKE 'S%' ORDER BY word ASC;
3747
-- result:
48+
SELECT 1
3849
-- !result
3950

4051
SELECT * FROM information_schema.keywords WHERE word IN ('SELECT', 'USER', 'TABLE') ORDER BY word ASC;
4152
-- result:
53+
SELECT 1
54+
TABLE 1
55+
USER 0
4256
-- !result
4357

4458
SELECT * FROM information_schema.keywords ORDER BY RESERVED DESC, word ASC;
4559
-- result:
60+
DELETE 1
61+
INDEX 1
62+
INSERT 1
63+
SELECT 1
64+
TABLE 1
65+
UPDATE 1
66+
VIEW 1
67+
PASSWORD 0
68+
USER 0
4669
-- !result
4770

4871
ADMIN SET FRONTEND CONFIG("max_get_partitions_meta_result_count" = "1");
4972
-- result:
5073
-- !result
5174
SELECT * FROM information_schema.keywords ORDER BY word ASC;
5275
-- result:
76+
DELETE 1
77+
INDEX 1
78+
INSERT 1
79+
PASSWORD 0
80+
SELECT 1
81+
TABLE 1
82+
UPDATE 1
83+
USER 0
84+
VIEW 1
5385
-- !result
5486
ADMIN SET FRONTEND CONFIG("max_get_partitions_meta_result_count" = "100000");
5587
-- result:
@@ -66,13 +98,22 @@ CREATE USER test_user IDENTIFIED BY 'password';
6698
GRANT SELECT ON information_schema.keywords TO test_user;
6799
-- result:
68100
-- !result
69-
SELECT * FROM information_schema.keywords;
101+
SELECT * FROM information_schema.keywords ORDER BY word ASC;
70102
-- result:
103+
DELETE 1
104+
INDEX 1
105+
INSERT 1
106+
PASSWORD 0
107+
SELECT 1
108+
TABLE 1
109+
UPDATE 1
110+
USER 0
111+
VIEW 1
71112
-- !result
72113
DROP USER test_user;
73114
-- result:
74115
-- !result
75116

76117
DROP DATABASE db_${uuid0};
77118
-- result:
78-
-- !result
119+
-- !result

0 commit comments

Comments
 (0)