Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: remove db_engines #22444

Merged
merged 3 commits into from
Feb 13, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 51 additions & 3 deletions superset/db_engine_specs/hive.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@

if TYPE_CHECKING:
# prevent circular imports
from pyhive.hive import Cursor
from TCLIService.ttypes import TFetchOrientation

from superset.models.core import Database

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -139,12 +142,10 @@ def patch(cls) -> None:
ttypes as patched_ttypes,
)

from superset.db_engines import hive as patched_hive

hive.TCLIService = patched_TCLIService
hive.constants = patched_constants
hive.ttypes = patched_ttypes
hive.Cursor.fetch_logs = patched_hive.fetch_logs
hive.Cursor.fetch_logs = fetch_logs

@classmethod
def fetch_data(
Expand Down Expand Up @@ -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)
betodealmeida marked this conversation as resolved.
Show resolved Hide resolved
16 changes: 0 additions & 16 deletions superset/db_engines/__init__.py

This file was deleted.

67 changes: 0 additions & 67 deletions superset/db_engines/hive.py

This file was deleted.