Search in sources :

Example 1 with GetQueryResultsRequest

use of com.amazonaws.services.athena.model.GetQueryResultsRequest in project aws-doc-sdk-examples by awsdocs.

the class StartQueryExample method processResultRows.

/**
 * This code calls Athena and retrieves the results of a query.
 * The query must be in a completed state before the results can be retrieved and
 * paginated. The first row of results are the column headers.
 */
private static void processResultRows(AmazonAthena athenaClient, String queryExecutionId) {
    GetQueryResultsRequest getQueryResultsRequest = new GetQueryResultsRequest().withQueryExecutionId(queryExecutionId);
    GetQueryResultsResult getQueryResultsResult = athenaClient.getQueryResults(getQueryResultsRequest);
    List<ColumnInfo> columnInfoList = getQueryResultsResult.getResultSet().getResultSetMetadata().getColumnInfo();
    while (true) {
        List<Row> results = getQueryResultsResult.getResultSet().getRows();
        for (Row row : results) {
            // Process the row. The first row of the first page holds the column names.
            processRow(row, columnInfoList);
        }
        // If nextToken is null, there are no more pages to read. Break out of the loop.
        if (getQueryResultsResult.getNextToken() == null) {
            break;
        }
        getQueryResultsResult = athenaClient.getQueryResults(getQueryResultsRequest.withNextToken(getQueryResultsResult.getNextToken()));
    }
}
Also used : ColumnInfo(com.amazonaws.services.athena.model.ColumnInfo) Row(com.amazonaws.services.athena.model.Row) GetQueryResultsResult(com.amazonaws.services.athena.model.GetQueryResultsResult) GetQueryResultsRequest(com.amazonaws.services.athena.model.GetQueryResultsRequest)

Aggregations

ColumnInfo (com.amazonaws.services.athena.model.ColumnInfo)1 GetQueryResultsRequest (com.amazonaws.services.athena.model.GetQueryResultsRequest)1 GetQueryResultsResult (com.amazonaws.services.athena.model.GetQueryResultsResult)1 Row (com.amazonaws.services.athena.model.Row)1