Vitor-Avila commented on code in PR #26744:
URL: https://github.com/apache/superset/pull/26744#discussion_r1462413291


##########
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:
   @betodealmeida I think this would raise a `ValueError` because `text` is 
supposed to contain a tuple with a single element. Something like this:
   ``` python
   {
     "text": ("This is my table comment",)
   }
   ```
   
   I tested adding multiple comments to the same table, and it always get 
replaced (never appended). Also seems accurate with [their 
documentation](https://www.ibm.com/docs/en/db2oc?topic=statements-comment). 
   
   I just needed to override the `BaseEngineSpec` because it's [supposed to 
return a string and it doesn't account for the engine returning a 
tuple/array](https://github.com/apache/superset/blob/master/superset/db_engine_specs/base.py#L1309-L1319).
   
   



-- 
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

Reply via email to