/** * 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(AmazonAthenaClient athenaClient, String queryExecutionId) { GetQueryResultsRequest getQueryResultsRequest = new GetQueryResultsRequest() { // Max Results can be set but if its not set, it will choose the maximum page size // As of the writing of this code, the maximum value is 1000 // MaxResults = 1000 QueryExecutionId = queryExecutionId }; var getQueryResultsResponse = athenaClient.GetQueryResults(getQueryResultsRequest); while (true) { var results = getQueryResultsResponse.ResultSet.Rows; foreach (Row row in results) { // Process the row. The first row of the first page holds the column names. processRow(row, getQueryResultsResponse.ResultSet.ResultSetMetadata.ColumnInfo); } // If nextToken is null, there are no more pages to read. Break out of the loop. if (String.IsNullOrEmpty(getQueryResultsResponse.NextToken)) { break; } getQueryResultsRequest.NextToken = getQueryResultsResponse.NextToken; getQueryResultsResponse = athenaClient.GetQueryResults(getQueryResultsRequest); } }
public override void Invoke(AWSCredentials creds, RegionEndpoint region, int maxItems) { AmazonAthenaConfig config = new AmazonAthenaConfig(); config.RegionEndpoint = region; ConfigureClient(config); AmazonAthenaClient client = new AmazonAthenaClient(creds, config); GetQueryResultsResponse resp = new GetQueryResultsResponse(); do { GetQueryResultsRequest req = new GetQueryResultsRequest { NextToken = resp.NextToken , MaxResults = maxItems }; resp = client.GetQueryResults(req); CheckError(resp.HttpStatusCode, "200"); foreach (var obj in resp.UpdateCount) { AddObject(obj); } foreach (var obj in resp.ResultSet) { AddObject(obj); } }while (!string.IsNullOrEmpty(resp.NextToken)); }