17
17
18
18
import json
19
19
import time
20
+ import logging
20
21
import textwrap
21
22
from urllib .parse import urlparse
22
23
35
36
from desktop .lib .rest .resource import Resource
36
37
from notebook .connectors .base import Api , ExecutionWrapper , QueryError , ResultWrapper
37
38
39
+ LOG = logging .getLogger ()
40
+
38
41
39
42
def query_error_handler (func ):
40
43
def decorator (* args , ** kwargs ):
@@ -297,12 +300,18 @@ def _show_databases(self):
297
300
databases = []
298
301
299
302
for catalog in catalogs :
300
- query_client = TrinoQuery (self .trino_request , 'SHOW SCHEMAS FROM ' + catalog )
301
- response = query_client .execute ()
302
- databases += [f'{ catalog } .{ item } ' for sublist in response .rows for item in sublist ]
303
+ try :
304
+ query_client = TrinoQuery (self .trino_request , 'SHOW SCHEMAS FROM ' + catalog )
305
+ response = query_client .execute ()
306
+ databases += [f'{ catalog } .{ item } ' for sublist in response .rows for item in sublist ]
307
+ except Exception as e :
308
+ # Log the exception and continue with the next catalog
309
+ LOG .error (f"Failed to fetch schemas from catalog { catalog } : { str (e )} " )
310
+ continue
303
311
304
312
return databases
305
313
314
+ @query_error_handler
306
315
def _show_catalogs (self ):
307
316
query_client = TrinoQuery (self .trino_request , 'SHOW CATALOGS' )
308
317
response = query_client .execute ()
@@ -311,6 +320,7 @@ def _show_catalogs(self):
311
320
312
321
return catalogs
313
322
323
+ @query_error_handler
314
324
def _show_tables (self , database ):
315
325
database = self ._format_identifier (database , is_db = True )
316
326
query_client = TrinoQuery (self .trino_request , 'USE ' + database )
@@ -326,6 +336,7 @@ def _show_tables(self, database):
326
336
for table in tables
327
337
]
328
338
339
+ @query_error_handler
329
340
def _get_columns (self , database , table ):
330
341
database = self ._format_identifier (database , is_db = True )
331
342
query_client = TrinoQuery (self .trino_request , 'USE ' + database )
0 commit comments