You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by "betodealmeida (via GitHub)" <gi...@apache.org> on 2023/02/13 17:58:10 UTC

[GitHub] [superset] betodealmeida commented on a diff in pull request #22444: chore: remove db_engines

betodealmeida commented on code in PR #22444:
URL: https://github.com/apache/superset/pull/22444#discussion_r1104840800


##########
superset/db_engine_specs/hive.py:
##########
@@ -611,3 +612,50 @@ def get_view_names(
             cursor.execute(sql)
             results = cursor.fetchall()
             return {row[0] for row in results}
+
+
+# TODO: contribute back to pyhive.
+def fetch_logs(  # pylint: disable=protected-access
+    self: "Cursor",
+    _max_rows: int = 1024,
+    orientation: Optional["TFetchOrientation"] = None,
+) -> str:
+    """Mocked. Retrieve the logs produced by the execution of the query.
+    Can be called multiple times to fetch the logs produced after
+    the previous call.
+    :returns: list<str>
+    :raises: ``ProgrammingError`` when no query has been started
+    .. note::
+        This is not a part of DB-API.
+    """
+    # pylint: disable=import-outside-toplevel
+    from pyhive import hive
+    from TCLIService import ttypes
+    from thrift import Thrift
+
+    orientation = orientation or ttypes.TFetchOrientation.FETCH_NEXT
+    try:
+        req = ttypes.TGetLogReq(operationHandle=self._operationHandle)
+        logs = self._connection.client.GetLog(req).log
+        return logs
+    # raised if Hive is used
+    except (ttypes.TApplicationException, Thrift.TApplicationException) as ex:
+        if self._state == self._STATE_NONE:
+            raise hive.ProgrammingError("No query yet") from ex
+        logs = []
+        while True:
+            req = ttypes.TFetchResultsReq(
+                operationHandle=self._operationHandle,
+                orientation=ttypes.TFetchOrientation.FETCH_NEXT,
+                maxRows=self.arraysize,
+                fetchType=1,  # 0: results, 1: logs
+            )
+            response = self._connection.client.FetchResults(req)
+            hive._check_status(response)
+            assert not response.results.rows, "expected data in columnar format"
+            assert len(response.results.columns) == 1, response.results.columns
+            new_logs = hive._unwrap_column(response.results.columns[0])
+            logs += new_logs
+            if not new_logs:
+                break
+        return "\n".join(logs)

Review Comment:
   ```suggestion
           return "\n".join(logs)
   ```



-- 
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-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org