Search in sources :

Example 1 with TRowSet

use of org.apache.hive.service.rpc.thrift.TRowSet in project hive by apache.

the class HiveQueryResultSet method next.

/**
   * Moves the cursor down one row from its current position.
   *
   * @see java.sql.ResultSet#next()
   * @throws SQLException
   *           if a database access error occurs.
   */
public boolean next() throws SQLException {
    if (isClosed) {
        throw new SQLException("Resultset is closed");
    }
    if (emptyResultSet || (maxRows > 0 && rowsFetched >= maxRows)) {
        return false;
    }
    /**
     * Poll on the operation status, till the operation is complete.
     * We need to wait only for HiveStatement to complete.
     * HiveDatabaseMetaData which also uses this ResultSet returns only after the RPC is complete.
     */
    if ((statement != null) && (statement instanceof HiveStatement)) {
        ((HiveStatement) statement).waitForOperationToComplete();
    }
    try {
        TFetchOrientation orientation = TFetchOrientation.FETCH_NEXT;
        if (fetchFirst) {
            // If we are asked to start from begining, clear the current fetched resultset
            orientation = TFetchOrientation.FETCH_FIRST;
            fetchedRows = null;
            fetchedRowsItr = null;
            fetchFirst = false;
        }
        if (fetchedRows == null || !fetchedRowsItr.hasNext()) {
            TFetchResultsReq fetchReq = new TFetchResultsReq(stmtHandle, orientation, fetchSize);
            TFetchResultsResp fetchResp;
            fetchResp = client.FetchResults(fetchReq);
            Utils.verifySuccessWithInfo(fetchResp.getStatus());
            TRowSet results = fetchResp.getResults();
            fetchedRows = RowSetFactory.create(results, protocol);
            fetchedRowsItr = fetchedRows.iterator();
        }
        if (fetchedRowsItr.hasNext()) {
            row = fetchedRowsItr.next();
        } else {
            return false;
        }
        rowsFetched++;
    } catch (SQLException eS) {
        throw eS;
    } catch (Exception ex) {
        ex.printStackTrace();
        throw new SQLException("Error retrieving next row", ex);
    }
    // NOTE: fetchOne doesn't throw new SQLFeatureNotSupportedException("Method not supported").
    return true;
}
Also used : TRowSet(org.apache.hive.service.rpc.thrift.TRowSet) SQLException(java.sql.SQLException) TFetchResultsResp(org.apache.hive.service.rpc.thrift.TFetchResultsResp) TFetchOrientation(org.apache.hive.service.rpc.thrift.TFetchOrientation) TFetchResultsReq(org.apache.hive.service.rpc.thrift.TFetchResultsReq) SQLFeatureNotSupportedException(java.sql.SQLFeatureNotSupportedException) SQLException(java.sql.SQLException)

Example 2 with TRowSet

use of org.apache.hive.service.rpc.thrift.TRowSet in project hive by apache.

the class RowBasedSet method toTRowSet.

public TRowSet toTRowSet() {
    TRowSet tRowSet = new TRowSet();
    tRowSet.setStartRowOffset(startOffset);
    tRowSet.setRows(new ArrayList<TRow>(rows));
    return tRowSet;
}
Also used : TRowSet(org.apache.hive.service.rpc.thrift.TRowSet) TRow(org.apache.hive.service.rpc.thrift.TRow)

Example 3 with TRowSet

use of org.apache.hive.service.rpc.thrift.TRowSet in project hive by apache.

the class ColumnBasedSet method toTRowSet.

public TRowSet toTRowSet() {
    TRowSet tRowSet = new TRowSet(startOffset, new ArrayList<TRow>());
    if (isBlobBased) {
        tRowSet.setColumns(null);
        tRowSet.setBinaryColumns(blob);
        tRowSet.setColumnCount(numColumns());
    } else {
        for (int i = 0; i < columns.size(); i++) {
            tRowSet.addToColumns(columns.get(i).toTColumn());
        }
    }
    return tRowSet;
}
Also used : TRowSet(org.apache.hive.service.rpc.thrift.TRowSet) TRow(org.apache.hive.service.rpc.thrift.TRow)

Aggregations

TRowSet (org.apache.hive.service.rpc.thrift.TRowSet)3 TRow (org.apache.hive.service.rpc.thrift.TRow)2 SQLException (java.sql.SQLException)1 SQLFeatureNotSupportedException (java.sql.SQLFeatureNotSupportedException)1 TFetchOrientation (org.apache.hive.service.rpc.thrift.TFetchOrientation)1 TFetchResultsReq (org.apache.hive.service.rpc.thrift.TFetchResultsReq)1 TFetchResultsResp (org.apache.hive.service.rpc.thrift.TFetchResultsResp)1