示例#1
0
    def fetch_logs(self):
        """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.
        """
        if self._state == self._STATE_NONE:
            raise ProgrammingError("No query yet")

        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)
            _check_status(response)
            assert not response.results.rows, 'expected data in columnar format'
            assert len(response.results.columns) == 1, response.results.columns
            new_logs = _unwrap_column(response.results.columns[0])
            logs += new_logs

            if not new_logs:
                break

        return logs
示例#2
0
 def _fetch_more(self):
     """Send another TFetchResultsReq and update state"""
     assert (self._state == self._STATE_RUNNING
             ), "Should be running when in _fetch_more"
     assert (self._operationHandle
             is not None), "Should have an op handle in _fetch_more"
     if not self._operationHandle.hasResultSet:
         raise ProgrammingError("No result set")
     req = ttypes.TFetchResultsReq(
         operationHandle=self._operationHandle,
         orientation=ttypes.TFetchOrientation.FETCH_NEXT,
         maxRows=self.arraysize,
     )
     response = self._connection.client.FetchResults(req)
     _check_status(response)
     schema = self.description
     assert not response.results.rows, 'expected data in columnar format'
     columns = [
         _unwrap_column(col, col_schema[1])
         for col, col_schema in zip(response.results.columns, schema)
     ]
     new_data = list(zip(*columns))
     self._data += new_data
     # response.hasMoreRows seems to always be False, so we instead check the number of rows
     # https://github.com/apache/hive/blob/release-1.2.1/service/src/java/org/apache/hive/service/cli/thrift/ThriftCLIService.java#L678
     # if not response.hasMoreRows:
     if not new_data:
         self._state = self._STATE_FINISHED
示例#3
0
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)
示例#4
0
文件: hive.py 项目: salexkidd/PyHive
 def _fetch_more(self):
     """Send another TFetchResultsReq and update state"""
     assert(self._state == self._STATE_RUNNING), "Should be running when in _fetch_more"
     assert(self._operationHandle is not None), "Should have an op handle in _fetch_more"
     if not self._operationHandle.hasResultSet:
         raise ProgrammingError("No result set")
     req = ttypes.TFetchResultsReq(
         operationHandle=self._operationHandle,
         orientation=ttypes.TFetchOrientation.FETCH_NEXT,
         maxRows=1000,
     )
     response = self._connection.client.FetchResults(req)
     _check_status(response)
     # response.hasMoreRows seems to always be False, so we instead check the number of rows
     #if not response.hasMoreRows:
     if not response.results.rows:
         self._state = self._STATE_FINISHED
     for row in response.results.rows:
         self._data.append([_unwrap_col_val(val) for val in row.colVals])
示例#5
0
    def fetch_logs(self):
        """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.
        """
        if self._state == self._STATE_NONE:
            raise ProgrammingError("No query yet")

        try:  # Older Hive instances require logs to be retrieved using GetLog
            self._connection.set_auth_setting()
            req = ttypes.TGetLogReq(operationHandle=self._operationHandle)
            logs = self._connection.client.GetLog(req).log.splitlines()
        except ttypes.TApplicationException as e:  # Otherwise, retrieve logs using newer method
            if e.type != ttypes.TApplicationException.UNKNOWN_METHOD:
                raise
            logs = []
            while True:
                self._connection.set_auth_setting()
                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)
                _check_status(response)
                assert not response.results.rows, 'expected data in columnar format'
                assert len(
                    response.results.columns) == 1, response.results.columns
                new_logs = _unwrap_column(response.results.columns[0])
                logs += new_logs

                if not new_logs:
                    break

        return logs
def fetch_logs(self,
               max_rows=1024,
               orientation=ttypes.TFetchOrientation.FETCH_NEXT):
    """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.
    """
    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):
        if self._state == self._STATE_NONE:
            raise hive.ProgrammingError('No query yet')
        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)