betodealmeida commented on code in PR #26744: URL: https://github.com/apache/superset/pull/26744#discussion_r1462282789
########## superset/db_engine_specs/db2.py: ########## @@ -52,3 +61,49 @@ class Db2EngineSpec(BaseEngineSpec): @classmethod def epoch_to_dttm(cls) -> str: return "(TIMESTAMP('1970-01-01', '00:00:00') + {col} SECONDS)" + + @classmethod + def get_table_comment( + cls, inspector: Inspector, table_name: str, schema: Union[str, None] + ) -> Optional[str]: + """ + Get comment of table from a given schema + + Ibm Db2 return comments as tuples, so we need to get the first element + + :param inspector: SqlAlchemy Inspector instance + :param table_name: Table name + :param schema: Schema name. If omitted, uses default schema for database + :return: comment of table + """ + comment = None + try: + table_comment = inspector.get_table_comment(table_name, schema) + comment = table_comment.get("text") + return comment[0] Review Comment: I'm a fan of doing: ```python comment, other_thing = table_comment.get("text") # pylint: disable=unused-variable ``` Even if you don't use `other_thing`, because it gives more information: 1. How many elements `table_comment.get()` returns. 2. A hint of what they are. ########## superset/db_engine_specs/db2.py: ########## @@ -52,3 +61,49 @@ class Db2EngineSpec(BaseEngineSpec): @classmethod def epoch_to_dttm(cls) -> str: return "(TIMESTAMP('1970-01-01', '00:00:00') + {col} SECONDS)" + + @classmethod + def get_table_comment( + cls, inspector: Inspector, table_name: str, schema: Union[str, None] + ) -> Optional[str]: + """ + Get comment of table from a given schema + + Ibm Db2 return comments as tuples, so we need to get the first element + + :param inspector: SqlAlchemy Inspector instance + :param table_name: Table name + :param schema: Schema name. If omitted, uses default schema for database + :return: comment of table + """ + comment = None + try: + table_comment = inspector.get_table_comment(table_name, schema) + comment = table_comment.get("text") + return comment[0] + except IndexError: Review Comment: Ohhh, so the behavior depends on the library version? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@superset.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: notifications-unsubscr...@superset.apache.org For additional commands, e-mail: notifications-h...@superset.apache.org