7
7
from trino .exceptions import TrinoUserError
8
8
9
9
import urllib3
10
+
10
11
urllib3 .disable_warnings ()
11
12
12
13
# Currently missing operation checks:
32
33
# ExecuteQuery, FilterCatalogs
33
34
{
34
35
"query" : "SHOW CATALOGS" ,
35
- "expected" : [["iceberg" ], ["lakehouse" ], ["system" ], ["tpcds" ], ["tpch" ]],
36
+ "expected" : [
37
+ ["iceberg" ],
38
+ ["lakehouse" ],
39
+ ["system" ],
40
+ ["tpcds" ],
41
+ ["tpch" ],
42
+ ],
36
43
},
37
44
# ExecuteQuery, FilterCatalogs, ImpersonateUser
38
45
{
44
51
{
45
52
"query" : "SET SESSION iceberg.test=true" ,
46
53
# 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" ,
48
55
},
49
56
# ## SCHEMA ##
50
57
# ExecuteQuery, AccessCatalog, ShowSchemas, SelectFromColumns, FilterCatalogs, FilterSchemas
51
58
{
52
59
"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
+ ],
54
72
},
55
73
# ExecuteQuery, AccessCatalog, ShowSchemas, SelectFromColumns, FilterCatalogs, FilterSchemas
56
74
{
57
75
"query" : "SHOW SCHEMAS in system" ,
58
- "expected" : [["information_schema" ], ["jdbc" ], ["metadata" ], ["runtime" ]],
76
+ "expected" : [
77
+ ["information_schema" ],
78
+ ["jdbc" ],
79
+ ["metadata" ],
80
+ ["runtime" ],
81
+ ],
59
82
},
60
83
# ExecuteQuery, AccessCatalog, CreateSchema
61
84
{
65
88
# ExecuteQuery, AccessCatalog, ShowCreateSchema
66
89
{
67
90
"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
+ ],
69
96
},
70
97
# ExecuteQuery, AccessCatalog, SetSchemaAuthorization
71
98
{
88
115
# ExecuteQuery, AccessCatalog, ShowTables, SelectFromColumns, FilterCatalogs, FilterTables
89
116
{
90
117
"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
+ ],
92
128
},
93
129
# ExecuteQuery, AccessCatalog, CreateTable
94
130
{
129
165
# ExecuteQuery, AccessCatalog, ShowColumns, SelectFromColumns, FilterCatalogs, FilterTables, FilterColumns
130
166
{
131
167
"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
+ ],
133
172
},
134
173
# ExecuteQuery, AccessCatalog, InsertIntoTable
135
174
{
194
233
# ExecuteQuery, AccessCatalog, ShowCreateTable
195
234
{
196
235
"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
+ ],
198
241
},
199
242
# ExecuteQuery, AccessCatalog, DropView
200
243
{
250
293
# ## SystemSessionProperties ##
251
294
# ExecuteQuery, SetSystemSessionProperty
252
295
{
253
- "query" : "SET SESSION optimize_hash_generation = true" ,
296
+ "query" : "SET SESSION dictionary_aggregation = true" ,
254
297
"expected" : [],
255
298
},
256
299
# ## PROCEDURES ##
266
309
"query" : "SELECT COUNT(*) FROM (SELECT * FROM system.runtime.queries LIMIT 1)" ,
267
310
"expected" : [[1 ]],
268
311
},
269
-
270
312
# ## CLEAN UP ##
271
313
# ExecuteQuery, AccessCatalog, DropSchema
272
314
{
273
315
"query" : "DROP SCHEMA iceberg.test" ,
274
316
"expected" : [],
275
317
},
276
- ]
318
+ ],
277
319
},
278
320
{
279
321
# User lakehouse can:
313
355
},
314
356
{
315
357
"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
+ ],
317
370
},
318
371
{
319
372
"query" : "SELECT * FROM tpch.tiny.customer ORDER BY name LIMIT 1" ,
323
376
# fake values, authorization is checked first
324
377
"query" : "INSERT INTO lakehouse.tiny.customer VALUES(1)" ,
325
378
"error" : "Access Denied: Cannot insert into table lakehouse.tiny.customer" ,
326
- }
327
- ]
379
+ },
380
+ ],
328
381
},
329
382
{
330
383
# User banned-user cannot do anything
337
390
"query" : "SHOW CATALOGS" ,
338
391
"error" : "Access Denied: Cannot execute query" ,
339
392
},
340
- ]
393
+ ],
341
394
},
342
395
{
343
396
# User iceberg can:
404
457
"query" : "DROP SCHEMA iceberg.test2" ,
405
458
"expected" : [],
406
459
},
407
- ]
408
- }
460
+ ],
461
+ },
409
462
]
410
463
411
464
412
465
class TestOpa :
413
-
414
466
def __init__ (self , test_data , namespace ):
415
467
self .data = test_data
416
468
self .namespace = namespace
@@ -428,7 +480,9 @@ def run(self):
428
480
impersonation = test ["impersonation" ]
429
481
430
482
# 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
+ )
432
486
433
487
if "error" in test :
434
488
error = test ["error" ]
@@ -444,8 +498,8 @@ def run(self):
444
498
print ("" )
445
499
446
500
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 } " )
449
503
450
504
def run_query (connection , query ):
451
505
cursor = connection .cursor ()
0 commit comments