@@ -24,81 +24,111 @@ suite("test_external_sql_block_rule", "external_docker,hive,external_docker_hive
2424
2525 String externalEnvIp = context. config. otherConfigs. get(" externalEnvIp" )
2626 String hms_port = context. config. otherConfigs. get(" hive2HmsPort" )
27+ String catalog_name = " test_hive2_external_sql_block_rule"
2728
28- sql """ drop catalog if exists test_hive2_external_sql_block_rule """
29+ sql """ drop catalog if exists ${ catalog_name } """
2930
30- sql """ CREATE CATALOG test_hive2_external_sql_block_rule PROPERTIES (
31+ sql """ CREATE CATALOG ${ catalog_name } PROPERTIES (
3132 'type'='hms',
3233 'hive.metastore.uris' = 'thrift://${ externalEnvIp} :${ hms_port} ',
3334 'hadoop.username' = 'hive'
3435 );"""
3536
36- sql " use test_hive2_external_sql_block_rule .`default`" ;
37+ sql " use ${ catalog_name } .`default`" ;
3738 qt_sql01 """ select * from parquet_partition_table order by l_linenumber,l_orderkey limit 10;"""
3839
39- sql """ drop sql_block_rule if exists external_hive_partition"""
40- sql """ create sql_block_rule external_hive_partition properties("partition_num" = "3", "global" = "false");"""
41- sql """ drop sql_block_rule if exists external_hive_partition2"""
42- sql """ create sql_block_rule external_hive_partition2 properties("tablet_num" = "3", "global" = "false");"""
43- sql """ drop sql_block_rule if exists external_hive_partition3"""
44- sql """ create sql_block_rule external_hive_partition3 properties("cardinality" = "3", "global" = "false");"""
45- // create 3 users
46- sql """ drop user if exists external_block_user1"""
47- sql """ create user external_block_user1;"""
48- sql """ SET PROPERTY FOR 'external_block_user1' 'sql_block_rules' = 'external_hive_partition';"""
49- sql """ grant all on *.*.* to external_block_user1;"""
50- // cloud-mode
51- if (isCloudMode()) {
52- def clusters = sql " SHOW CLUSTERS; "
53- assertTrue (! clusters. isEmpty())
54- def validCluster = clusters[0 ][0 ]
55- sql """ GRANT USAGE_PRIV ON CLUSTER `${ validCluster} ` TO external_block_user1;""" ;
56- }
40+ // Clean up existing rules and users
41+ sql """ drop sql_block_rule if exists hive_partition_rule"""
42+ sql """ drop sql_block_rule if exists hive_split_rule"""
43+ sql """ drop sql_block_rule if exists hive_cardinality_rule"""
44+ sql """ drop sql_block_rule if exists hive_regex_rule"""
45+ sql """ drop user if exists hive_block_user1"""
46+ sql """ drop user if exists hive_block_user2"""
47+ sql """ drop user if exists hive_block_user3"""
48+ sql """ drop user if exists hive_block_user4"""
49+
50+ // Create non-global rules (won't affect other parallel tests)
51+ sql """ create sql_block_rule hive_partition_rule properties("partition_num" = "3", "global" = "false");"""
52+ sql """ create sql_block_rule hive_split_rule properties("tablet_num" = "3", "global" = "false");"""
53+ sql """ create sql_block_rule hive_cardinality_rule properties("cardinality" = "3", "global" = "false");"""
54+ sql """ create sql_block_rule hive_regex_rule properties("sql" = "SELECT \\\\ *", "global" = "false");"""
55+
56+ // Create test users and bind rules
57+ sql """ create user hive_block_user1;"""
58+ sql """ SET PROPERTY FOR 'hive_block_user1' 'sql_block_rules' = 'hive_partition_rule';"""
59+ sql """ grant all on *.*.* to hive_block_user1;"""
60+
61+ sql """ create user hive_block_user2;"""
62+ sql """ SET PROPERTY FOR 'hive_block_user2' 'sql_block_rules' = 'hive_split_rule';"""
63+ sql """ grant all on *.*.* to hive_block_user2;"""
64+
65+ sql """ create user hive_block_user3;"""
66+ sql """ SET PROPERTY FOR 'hive_block_user3' 'sql_block_rules' = 'hive_cardinality_rule';"""
67+ sql """ grant all on *.*.* to hive_block_user3;"""
68+
69+ sql """ create user hive_block_user4;"""
70+ sql """ SET PROPERTY FOR 'hive_block_user4' 'sql_block_rules' = 'hive_regex_rule';"""
71+ sql """ grant all on *.*.* to hive_block_user4;"""
5772
58- sql """ drop user if exists external_block_user2"""
59- sql """ create user external_block_user2;"""
60- sql """ SET PROPERTY FOR 'external_block_user2' 'sql_block_rules' = 'external_hive_partition2';"""
61- sql """ grant all on *.*.* to external_block_user2;"""
62- // cloud-mode
73+ // cloud-mode: grant cluster privileges
6374 if (isCloudMode()) {
6475 def clusters = sql " SHOW CLUSTERS; "
6576 assertTrue (! clusters. isEmpty())
6677 def validCluster = clusters[0 ][0 ]
67- sql """ GRANT USAGE_PRIV ON CLUSTER `${ validCluster} ` TO external_block_user2;""" ;
78+ sql """ GRANT USAGE_PRIV ON CLUSTER `${ validCluster} ` TO hive_block_user1;"""
79+ sql """ GRANT USAGE_PRIV ON CLUSTER `${ validCluster} ` TO hive_block_user2;"""
80+ sql """ GRANT USAGE_PRIV ON CLUSTER `${ validCluster} ` TO hive_block_user3;"""
81+ sql """ GRANT USAGE_PRIV ON CLUSTER `${ validCluster} ` TO hive_block_user4;"""
6882 }
6983
70- sql """ drop user if exists external_block_user3"""
71- sql """ create user external_block_user3;"""
72- sql """ SET PROPERTY FOR 'external_block_user3' 'sql_block_rules' = 'external_hive_partition3';"""
73- sql """ grant all on *.*.* to external_block_user3;"""
74- // cloud-mode
75- if (isCloudMode()) {
76- def clusters = sql " SHOW CLUSTERS; "
77- assertTrue (! clusters. isEmpty())
78- def validCluster = clusters[0 ][0 ]
79- sql """ GRANT USAGE_PRIV ON CLUSTER `${ validCluster} ` TO external_block_user3;""" ;
84+ // Test 1: partition_num rule
85+ connect(' hive_block_user1' , ' ' , context. config. jdbcUrl) {
86+ test {
87+ sql """ select * from ${ catalog_name} .`default`.parquet_partition_table order by l_linenumber limit 10;"""
88+ exception """ sql hits sql block rule: hive_partition_rule, reach partition_num : 3"""
89+ }
90+ // Test EXPLAIN should not be blocked
91+ sql """ explain select * from ${ catalog_name} .`default`.parquet_partition_table order by l_linenumber limit 10;"""
8092 }
8193
82- // login as external_block_user1
83- def result1 = connect(' external_block_user1 ' , ' ' , context. config. jdbcUrl) {
94+ // Test 2: tablet_num (split) rule
95+ connect(' hive_block_user2 ' , ' ' , context. config. jdbcUrl) {
8496 test {
85- sql """ select * from test_hive2_external_sql_block_rule .`default`.parquet_partition_table order by l_linenumber limit 10;"""
86- exception """ sql hits sql block rule: external_hive_partition , reach partition_num : 3"""
97+ sql """ select * from ${ catalog_name } .`default`.parquet_partition_table order by l_linenumber limit 10;"""
98+ exception """ sql hits sql block rule: hive_split_rule , reach tablet_num : 3"""
8799 }
100+ // Test EXPLAIN should not be blocked
101+ sql """ explain select * from ${ catalog_name} .`default`.parquet_partition_table order by l_linenumber limit 10;"""
88102 }
89- // login as external_block_user2
90- def result2 = connect(' external_block_user2' , ' ' , context. config. jdbcUrl) {
103+
104+ // Test 3: cardinality rule
105+ connect(' hive_block_user3' , ' ' , context. config. jdbcUrl) {
91106 test {
92- sql """ select * from test_hive2_external_sql_block_rule .`default`.parquet_partition_table order by l_linenumber limit 10;"""
93- exception """ sql hits sql block rule: external_hive_partition2 , reach tablet_num : 3"""
107+ sql """ select * from ${ catalog_name } .`default`.parquet_partition_table order by l_linenumber limit 10;"""
108+ exception """ sql hits sql block rule: hive_cardinality_rule , reach cardinality : 3"""
94109 }
110+ // Test EXPLAIN should not be blocked
111+ sql """ explain select * from ${ catalog_name} .`default`.parquet_partition_table order by l_linenumber limit 10;"""
95112 }
96- // login as external_block_user3
97- def result3 = connect(' external_block_user3' , ' ' , context. config. jdbcUrl) {
113+
114+ // Test 4: regex rule
115+ connect(' hive_block_user4' , ' ' , context. config. jdbcUrl) {
98116 test {
99- sql """ select * from test_hive2_external_sql_block_rule .`default`.parquet_partition_table order by l_linenumber limit 10;"""
100- exception """ sql hits sql block rule: external_hive_partition3, reach cardinality : 3 """
117+ sql """ SELECT * FROM ${ catalog_name } .`default`.parquet_partition_table limit 10;"""
118+ exception """ sql match regex sql block rule: hive_regex_rule """
101119 }
120+ // Test EXPLAIN should not be blocked by regex rule
121+ sql """ EXPLAIN SELECT * FROM ${ catalog_name} .`default`.parquet_partition_table limit 10;"""
102122 }
103- }
104123
124+ // Cleanup
125+ sql """ drop user if exists hive_block_user1"""
126+ sql """ drop user if exists hive_block_user2"""
127+ sql """ drop user if exists hive_block_user3"""
128+ sql """ drop user if exists hive_block_user4"""
129+ sql """ drop sql_block_rule if exists hive_partition_rule"""
130+ sql """ drop sql_block_rule if exists hive_split_rule"""
131+ sql """ drop sql_block_rule if exists hive_cardinality_rule"""
132+ sql """ drop sql_block_rule if exists hive_regex_rule"""
133+ sql """ drop catalog if exists ${ catalog_name} """
134+ }
0 commit comments