示例#1
0
 def get_results_metadata(self, handle):
     operation_handle = handle.get_rpc_handle()
     if operation_handle.hasResultSet:
         meta_req = TGetResultSetMetadataReq(
             operationHandle=operation_handle)
         metadata = self._client.call(
             self._client._client.GetResultSetMetadata, meta_req)
         return ResultMetaCompatible(schema=metadata.schema,
                                     status=metadata.status)
     return ResultMetaCompatible()
示例#2
0
  def fetch_result(self, operation_handle, orientation=TFetchOrientation.FETCH_NEXT, max_rows=100):
    fetch_req = TFetchResultsReq(operationHandle=operation_handle, orientation=orientation, maxRows=max_rows)
    res = self.call(self._client.FetchResults, fetch_req)

    if operation_handle.hasResultSet:
      meta_req = TGetResultSetMetadataReq(operationHandle=operation_handle)
      schema = self.call(self._client.GetResultSetMetadata, meta_req)
    else:
      schema = None

    return res, schema
示例#3
0
  def fetch_result(self, operation_handle, orientation=TFetchOrientation.FETCH_FIRST, max_rows=1000):
    if operation_handle.hasResultSet:
      fetch_req = TFetchResultsReq(operationHandle=operation_handle, orientation=orientation, maxRows=max_rows)
      res = self.call(self._client.FetchResults, fetch_req)
    else:
      res = TFetchResultsResp(results=TRowSet(startRowOffset=0, rows=[], columns=[]))

    if operation_handle.hasResultSet and TFetchOrientation.FETCH_FIRST: # Only fetch for the first call that should be with start_over
      meta_req = TGetResultSetMetadataReq(operationHandle=operation_handle)
      schema = self.call(self._client.GetResultSetMetadata, meta_req)
    else:
      schema = None

    return res, schema
示例#4
0
文件: cursor.py 项目: zzhcs/pyhs2
 def getSchema(self):
     if self.operationHandle:
         req = TGetResultSetMetadataReq(self.operationHandle)
         res = self.client.GetResultSetMetadata(req)
         if res.schema is not None:
             cols = []
             for c in self.client.GetResultSetMetadata(req).schema.columns:
                 col = {}
                 col['type'] = get_type(c.typeDesc)
                 col['columnName'] = c.columnName
                 col['comment'] = c.comment
                 cols.append(col)
             return cols
     return None
示例#5
0
    def fetch_result(self,
                     operation_handle,
                     orientation=TFetchOrientation.FETCH_NEXT,
                     max_rows=1000,
                     fetchType=0):
        if operation_handle.hasResultSet:
            fetch_req = TFetchResultsReq(operationHandle=operation_handle,
                                         orientation=orientation,
                                         maxRows=max_rows,
                                         fetchType=fetchType)
            res = self.call(self._client.FetchResults, fetch_req)
        else:
            res = TFetchResultsResp(
                results=TRowSet(startRowOffset=0, rows=[], columns=[]))

        if operation_handle.hasResultSet and fetchType == 0:
            meta_req = TGetResultSetMetadataReq(
                operationHandle=operation_handle)
            schema = self.call(self._client.GetResultSetMetadata, meta_req)
        else:
            schema = None

        return res, schema
示例#6
0
    print('-' * 32)
    for row in resultsRes.results.rows:
        print row.colVals[0].stringVal.value
    print('-' * 32)

    # 4) try execute HQL
    print "\n4) Executing Test HQL: %s..." % test_hql
    query = TExecuteStatementReq(session, statement=test_hql, confOverlay={})
    response = client.ExecuteStatement(query)
    opHandle = response.operationHandle

    print('-' * 32)
    meta = []
    if opHandle.hasResultSet:
        metaReq = TGetResultSetMetadataReq(operationHandle=opHandle)
        schema = client.GetResultSetMetadata(metaReq).schema
        for i, col in enumerate(schema.columns):
            type = get_type(col.typeDesc)
            name = col.columnName
            meta.append(type)
            if i == 0:
                print name,
            else:
                print ', ' + name,
        print

    print('-' * 32)
    fetchReq = TFetchResultsReq(operationHandle=opHandle,
                                orientation=TFetchOrientation.FETCH_NEXT,
                                maxRows=100)