Пример #1
0
  def fetch_log(self, operation_handle, orientation=TFetchOrientation.FETCH_NEXT, max_rows=1000):
    req = TFetchResultsReq(operationHandle=operation_handle, orientation=orientation,
                           maxRows=max_rows, fetchType=1)
    res = self.call(self._client.FetchResults, req)

    lines = imap(lambda r: r.colVals[0].stringVal.value, res.results.rows)
    return '\n'.join(lines)
Пример #2
0
 def fetchSet(self):
     rows = []
     fetchReq = TFetchResultsReq(operationHandle=self.operationHandle,
                                 orientation=TFetchOrientation.FETCH_NEXT,
                                 maxRows=10000)
     self._fetch(rows, fetchReq)
     return rows
Пример #3
0
  def fetch_log(self, operation_handle, orientation=TFetchOrientation.FETCH_NEXT, max_rows=1000):
    req = TFetchResultsReq(operationHandle=operation_handle, orientation=orientation, maxRows=max_rows, fetchType=1)
    res = self.call(self._client.FetchResults, req)

    if beeswax_conf.THRIFT_VERSION.get() >= 7:
      lines = res.results.columns[0].stringVal.values
    else:
      lines = imap(lambda r: r.colVals[0].stringVal.value, res.results.rows)

    return '\n'.join(lines)
Пример #4
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
Пример #5
0
 def fetch(self):    
     fetchReq = TFetchResultsReq(operationHandle=self.operationHandle,
                                 orientation=TFetchOrientation.FETCH_NEXT,
                                 maxRows=10000)
     while True:
         resultsRes = self.client.FetchResults(fetchReq)
         for row in resultsRes.results.rows:
             rowData= []
             for col in row.colVals:
                 rowData.append(get_value(col))
             yield rowData
         if len(resultsRes.results.rows) == 0:
             break
Пример #6
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
Пример #7
0
    def _fetchBlock(self):
        """ internal use only.
	 get a block of rows from the server and put in standby block.
         future enhancements:
         (1) locks for multithreaded access (protect from multiple calls)
         (2) allow for prefetch by use of separate thread
        """
        # make sure that another block request is not standing
        if self._blockRequestInProgress :
           # need to wait here before returning... (TODO)
           return

        # make sure another block request has not completed meanwhile
        if self._standbyBlock is not None: 
           return

        self._blockRequestInProgress = True
        fetchReq = TFetchResultsReq(operationHandle=self.operationHandle,
                                    orientation=TFetchOrientation.FETCH_NEXT,
                                    maxRows=self.arraysize)
        self._standbyBlock = self._fetch([],fetchReq)
        self._blockRequestInProgress = False
        return
Пример #8
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
Пример #9
0
 transport = TSocket.TSocket( sys.argv[1], int(sys.argv[2]))
 transport = TTransport.TBufferedTransport(transport)
 protocol = TBinaryProtocol.TBinaryProtocol(transport)    
 client = TCLIService.Client(protocol)
 transport.open()
 openReq = TOpenSessionReq()
 openResp = client.OpenSession(openReq)
 m_sessHandle = openResp.sessionHandle
 execReq =  TExecuteStatementReq()    
 execReq.sessionHandle = m_sessHandle
 execReq.statement = "create external table IF NOT EXISTS AdventureWorks_Person_Contact(contactid int,fullname string,age int,emailaddress string,phoneno string,modifieddate string) ROW FORMAT DELIMITED FIELDS TERMINATED BY ',' LOCATION '/Data/AdventureWorks'"
 execResp = client.ExecuteStatement(execReq)     
 execReq.statement = 'select * from AdventureWorks_Person_Contact'
 execResp = client.ExecuteStatement(execReq)     
 stmtHandle = execResp.operationHandle
 fetchReq = TFetchResultsReq()
 fetchReq.operationHandle = stmtHandle
 fetchReq.orientation = TFetchOrientation.FETCH_NEXT
 fetchReq.maxRows = 100
 resultsResp = client.FetchResults(fetchReq)
 resultsSet = resultsResp.results
 tableResult = []
 if resultsSet.columns != None: 
   if len(resultsSet.columns) != 0:
     resultColumns = resultsSet.columns
     for i in range(0,len(resultColumns)):
         resultRow = resultColumns[i]
         if resultRow.binaryVal != None:
             result = resultRow.binaryVal.values 
         elif resultRow.boolVal != None:
             result = resultRow.boolVal.values
Пример #10
0
    print "\n2) Opening Session..."
    res = client.OpenSession(
        TOpenSessionReq(username=username, password=password))
    session = res.sessionHandle
    print('Session opened. ( %s )' % session.sessionId)

    ## 3) Show tables
    print "\n3) Try fetching table list..."
    query = TExecuteStatementReq(session,
                                 statement="show tables",
                                 confOverlay={})
    response = client.ExecuteStatement(query)
    opHandle = response.operationHandle

    fetchReq = TFetchResultsReq(operationHandle=opHandle,
                                orientation=TFetchOrientation.FETCH_NEXT,
                                maxRows=100)
    resultsRes = client.FetchResults(fetchReq)

    ## close operation && release lock
    req = TCloseOperationReq(operationHandle=opHandle)
    client.CloseOperation(req)

    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={})