def fetch_results(service, operation_handle, hs2_protocol_version, schema=None, max_rows=1024, orientation=TFetchOrientation.FETCH_NEXT): # pylint: disable=too-many-locals,too-many-branches,protected-access if not operation_handle.hasResultSet: log.debug('fetch_results: operation_handle.hasResultSet=False') return None # the schema is necessary to pull the proper values (i.e., coalesce) if schema is None: schema = get_result_schema(service, operation_handle) req = TFetchResultsReq(operationHandle=operation_handle, orientation=orientation, maxRows=max_rows) log.debug( 'fetch_results: hs2_protocol_version=%s max_rows=%s ' 'orientation=%s req=%s', hs2_protocol_version, max_rows, orientation, req) resp = service.FetchResults(req) err_if_rpc_not_ok(resp) if _is_columnar_protocol(hs2_protocol_version): log.debug('fetch_results: constructing CBatch') return CBatch(resp.results, schema) elif _is_precolumnar_protocol(hs2_protocol_version): log.debug('fetch_results: constructing RBatch') return RBatch(resp.results, schema) else: raise HiveServer2Error( "Got HiveServer2 version {0}; expected V1 - V6".format( TProtocolVersion._VALUES_TO_NAMES[hs2_protocol_version]))
def get_log(self, max_rows=1024, orientation=TFetchOrientation.FETCH_NEXT): try: req = TGetLogReq(operationHandle=self.handle) log = self._rpc('GetLog', req).log except TApplicationException as e: # raised if Hive is used if not e.type == TApplicationException.UNKNOWN_METHOD: raise req = TFetchResultsReq(operationHandle=self.handle, orientation=orientation, maxRows=max_rows, fetchType=1) resp = self._rpc('FetchResults', req) schema = [('Log', 'STRING', None, None, None, None, None)] log = self._wrap_results(resp.results, schema, convert_types=True) log = '\n'.join(l[0] for l in log) return log
def fetch(self, schema=None, max_rows=1024, orientation=TFetchOrientation.FETCH_NEXT, convert_types=True): if not self.has_result_set: log.debug('fetch_results: operation_handle.hasResultSet=False') return None # the schema is necessary to pull the proper values (i.e., coalesce) if schema is None: schema = self.get_result_schema() req = TFetchResultsReq(operationHandle=self.handle, orientation=orientation, maxRows=max_rows) resp = self._rpc('FetchResults', req) return self._wrap_results(resp.results, schema, convert_types=convert_types)