Skip to content

Commit 03b9725

Browse files
ms32035ebyhr
authored andcommitted
Get table comment from system catalog
1 parent 7774b8a commit 03b9725

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

trino/sqlalchemy/dialect.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -229,16 +229,23 @@ def get_check_constraints(
229229
return []
230230

231231
def get_table_comment(self, connection: Connection, table_name: str, schema: str = None, **kw) -> Dict[str, Any]:
232-
properties_table = self._get_full_table(f"{table_name}$properties", schema)
233-
query = f'SELECT "comment" FROM {properties_table}'
232+
schema = schema or self._get_default_schema_name(connection)
233+
if schema is None:
234+
raise exc.NoSuchTableError("schema is required")
235+
query = dedent(
236+
"""
237+
SELECT "comment"
238+
FROM "system"."metadata"."table_comments"
239+
WHERE "schema_name" = :schema
240+
AND "table_name" = :table_name
241+
"""
242+
).strip()
234243
try:
235-
res = connection.execute(sql.text(query))
244+
res = connection.execute(sql.text(query), schema=schema, table_name=table_name)
236245
return dict(text=res.scalar())
237246
except error.TrinoQueryError as e:
238247
if e.error_name in (
239-
error.NOT_FOUND,
240-
error.COLUMN_NOT_FOUND,
241-
error.TABLE_NOT_FOUND,
248+
error.PERMISSION_DENIED,
242249
):
243250
return dict(text=None)
244251
raise

trino/sqlalchemy/error.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,5 @@
2222
MISSING_COLUMN_NAME = "MISSING_COLUMN_NAME"
2323
MISSING_SCHEMA_NAME = "MISSING_SCHEMA_NAME"
2424
MISSING_CATALOG_NAME = "MISSING_CATALOG_NAME"
25+
26+
PERMISSION_DENIED = "PERMISSION_DENIED"

0 commit comments

Comments
 (0)