77from trino .exceptions import TrinoUserError
88
99import urllib3
10+
1011urllib3 .disable_warnings ()
1112
1213# Currently missing operation checks:
3233 # ExecuteQuery, FilterCatalogs
3334 {
3435 "query" : "SHOW CATALOGS" ,
35- "expected" : [["iceberg" ], ["lakehouse" ], ["system" ], ["tpcds" ], ["tpch" ]],
36+ "expected" : [
37+ ["iceberg" ],
38+ ["lakehouse" ],
39+ ["system" ],
40+ ["tpcds" ],
41+ ["tpch" ],
42+ ],
3643 },
3744 # ExecuteQuery, FilterCatalogs, ImpersonateUser
3845 {
4451 {
4552 "query" : "SET SESSION iceberg.test=true" ,
4653 # The requests are authorized, just a fake property
47- "error" : "Session property ' iceberg.test' does not exist" ,
54+ "error" : "Session property iceberg.test does not exist" ,
4855 },
4956 # ## SCHEMA ##
5057 # ExecuteQuery, AccessCatalog, ShowSchemas, SelectFromColumns, FilterCatalogs, FilterSchemas
5158 {
5259 "query" : "SHOW SCHEMAS in tpch" ,
53- "expected" : [["information_schema" ], ["sf1" ], ["sf100" ], ["sf1000" ], ["sf10000" ], ["sf100000" ], ["sf300" ], ["sf3000" ], ["sf30000" ], ["tiny" ]],
60+ "expected" : [
61+ ["information_schema" ],
62+ ["sf1" ],
63+ ["sf100" ],
64+ ["sf1000" ],
65+ ["sf10000" ],
66+ ["sf100000" ],
67+ ["sf300" ],
68+ ["sf3000" ],
69+ ["sf30000" ],
70+ ["tiny" ],
71+ ],
5472 },
5573 # ExecuteQuery, AccessCatalog, ShowSchemas, SelectFromColumns, FilterCatalogs, FilterSchemas
5674 {
5775 "query" : "SHOW SCHEMAS in system" ,
58- "expected" : [["information_schema" ], ["jdbc" ], ["metadata" ], ["runtime" ]],
76+ "expected" : [
77+ ["information_schema" ],
78+ ["jdbc" ],
79+ ["metadata" ],
80+ ["runtime" ],
81+ ],
5982 },
6083 # ExecuteQuery, AccessCatalog, CreateSchema
6184 {
6588 # ExecuteQuery, AccessCatalog, ShowCreateSchema
6689 {
6790 "query" : "SHOW CREATE SCHEMA iceberg.test" ,
68- "expected" : [["CREATE SCHEMA iceberg.test\n AUTHORIZATION USER admin\n WITH (\n location = 's3a://trino/iceberg/test'\n )" ]],
91+ "expected" : [
92+ [
93+ "CREATE SCHEMA iceberg.test\n AUTHORIZATION USER admin\n WITH (\n location = 's3a://trino/iceberg/test'\n )"
94+ ]
95+ ],
6996 },
7097 # ExecuteQuery, AccessCatalog, SetSchemaAuthorization
7198 {
88115 # ExecuteQuery, AccessCatalog, ShowTables, SelectFromColumns, FilterCatalogs, FilterTables
89116 {
90117 "query" : "SHOW TABLES in tpch.sf1" ,
91- "expected" : [["customer" ], ["lineitem" ], ["nation" ], ["orders" ], ["part" ], ["partsupp" ], ["region" ], ["supplier" ]],
118+ "expected" : [
119+ ["customer" ],
120+ ["lineitem" ],
121+ ["nation" ],
122+ ["orders" ],
123+ ["part" ],
124+ ["partsupp" ],
125+ ["region" ],
126+ ["supplier" ],
127+ ],
92128 },
93129 # ExecuteQuery, AccessCatalog, CreateTable
94130 {
129165 # ExecuteQuery, AccessCatalog, ShowColumns, SelectFromColumns, FilterCatalogs, FilterTables, FilterColumns
130166 {
131167 "query" : "DESCRIBE iceberg.test.test" ,
132- "expected" : [["col1" , "bigint" , "" , "This is a column comment!" ], ["col2" , "bigint" , "" , "" ]],
168+ "expected" : [
169+ ["col1" , "bigint" , "" , "This is a column comment!" ],
170+ ["col2" , "bigint" , "" , "" ],
171+ ],
133172 },
134173 # ExecuteQuery, AccessCatalog, InsertIntoTable
135174 {
194233 # ExecuteQuery, AccessCatalog, ShowCreateTable
195234 {
196235 "query" : "SHOW CREATE VIEW iceberg.test.v_customer_renamed" ,
197- "expected" : [["CREATE VIEW iceberg.test.v_customer_renamed COMMENT 'This is a test view!' SECURITY DEFINER AS\n SELECT\n name\n , address\n FROM\n tpch.sf1.customer" ]],
236+ "expected" : [
237+ [
238+ "CREATE VIEW iceberg.test.v_customer_renamed COMMENT 'This is a test view!' SECURITY DEFINER AS\n SELECT\n name\n , address\n FROM\n tpch.sf1.customer"
239+ ]
240+ ],
198241 },
199242 # ExecuteQuery, AccessCatalog, DropView
200243 {
250293 # ## SystemSessionProperties ##
251294 # ExecuteQuery, SetSystemSessionProperty
252295 {
253- "query" : "SET SESSION optimize_hash_generation = true" ,
296+ "query" : "SET SESSION dictionary_aggregation = true" ,
254297 "expected" : [],
255298 },
256299 # ## PROCEDURES ##
266309 "query" : "SELECT COUNT(*) FROM (SELECT * FROM system.runtime.queries LIMIT 1)" ,
267310 "expected" : [[1 ]],
268311 },
269-
270312 # ## CLEAN UP ##
271313 # ExecuteQuery, AccessCatalog, DropSchema
272314 {
273315 "query" : "DROP SCHEMA iceberg.test" ,
274316 "expected" : [],
275317 },
276- ]
318+ ],
277319 },
278320 {
279321 # User lakehouse can:
313355 },
314356 {
315357 "query" : "SELECT * FROM lakehouse.sf1.customer ORDER BY name LIMIT 1" ,
316- "expected" : [[1 , 'Customer#000000001' , 'IVhzIApeRb ot,c,E' , 15 , '25-989-741-2988' , 711.56 , 'BUILDING' , 'to the even, regular platelets. regular, ironic epitaphs nag e' ]],
358+ "expected" : [
359+ [
360+ 1 ,
361+ "Customer#000000001" ,
362+ "IVhzIApeRb ot,c,E" ,
363+ 15 ,
364+ "25-989-741-2988" ,
365+ 711.56 ,
366+ "BUILDING" ,
367+ "to the even, regular platelets. regular, ironic epitaphs nag e" ,
368+ ]
369+ ],
317370 },
318371 {
319372 "query" : "SELECT * FROM tpch.tiny.customer ORDER BY name LIMIT 1" ,
323376 # fake values, authorization is checked first
324377 "query" : "INSERT INTO lakehouse.tiny.customer VALUES(1)" ,
325378 "error" : "Access Denied: Cannot insert into table lakehouse.tiny.customer" ,
326- }
327- ]
379+ },
380+ ],
328381 },
329382 {
330383 # User banned-user cannot do anything
337390 "query" : "SHOW CATALOGS" ,
338391 "error" : "Access Denied: Cannot execute query" ,
339392 },
340- ]
393+ ],
341394 },
342395 {
343396 # User iceberg can:
404457 "query" : "DROP SCHEMA iceberg.test2" ,
405458 "expected" : [],
406459 },
407- ]
408- }
460+ ],
461+ },
409462]
410463
411464
412465class TestOpa :
413-
414466 def __init__ (self , test_data , namespace ):
415467 self .data = test_data
416468 self .namespace = namespace
@@ -428,7 +480,9 @@ def run(self):
428480 impersonation = test ["impersonation" ]
429481
430482 # could be optimized to not create a connection for every call (currently due to user impersonation)
431- connection = TestOpa .get_connection (user , password , self .namespace , impersonation )
483+ connection = TestOpa .get_connection (
484+ user , password , self .namespace , impersonation
485+ )
432486
433487 if "error" in test :
434488 error = test ["error" ]
@@ -444,8 +498,8 @@ def run(self):
444498 print ("" )
445499
446500 def log (user , query ):
447- timestamp = datetime .utcnow ().isoformat (sep = ' ' , timespec = ' milliseconds' )
448- print (f' [{ timestamp } ] - { user :20s} -> { query } ' )
501+ timestamp = datetime .utcnow ().isoformat (sep = " " , timespec = " milliseconds" )
502+ print (f" [{ timestamp } ] - { user :20s} -> { query } " )
449503
450504 def run_query (connection , query ):
451505 cursor = connection .cursor ()
0 commit comments