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()));
}
}
Aggregations