@@ -262,19 +262,26 @@ def get_check_constraints(
262
262
return []
263
263
264
264
def get_table_comment (self , connection : Connection , table_name : str , schema : str = None , ** kw ) -> Dict [str , Any ]:
265
- schema = schema or self ._get_default_schema_name (connection )
266
- if schema is None :
265
+ catalog_name = self ._get_default_catalog_name (connection )
266
+ if catalog_name is None :
267
+ raise exc .NoSuchTableError ("catalog is required in connection" )
268
+ schema_name = schema or self ._get_default_schema_name (connection )
269
+ if schema_name is None :
267
270
raise exc .NoSuchTableError ("schema is required" )
268
271
query = dedent (
269
272
"""
270
273
SELECT "comment"
271
274
FROM "system"."metadata"."table_comments"
272
- WHERE "schema_name" = :schema
273
- AND "table_name" = :table_name
275
+ WHERE "catalog_name" = :catalog_name
276
+ AND "schema_name" = :schema_name
277
+ AND "table_name" = :table_name
274
278
"""
275
279
).strip ()
276
280
try :
277
- res = connection .execute (sql .text (query ), schema = schema , table_name = table_name )
281
+ res = connection .execute (
282
+ sql .text (query ),
283
+ catalog_name = catalog_name , schema_name = schema_name , table_name = table_name
284
+ )
278
285
return dict (text = res .scalar ())
279
286
except error .TrinoQueryError as e :
280
287
if e .error_name in (
@@ -323,6 +330,10 @@ def _get_server_version_info(self, connection: Connection) -> Any:
323
330
logger .debug (f"Failed to get server version: { e .orig .message } " )
324
331
return None
325
332
333
+ def _get_default_catalog_name (self , connection : Connection ) -> Optional [str ]:
334
+ dbapi_connection : trino_dbapi .Connection = connection .connection
335
+ return dbapi_connection .catalog
336
+
326
337
def _get_default_schema_name (self , connection : Connection ) -> Optional [str ]:
327
338
dbapi_connection : trino_dbapi .Connection = connection .connection
328
339
return dbapi_connection .schema
0 commit comments