Search in sources :

Example 1 with GetQueryResultsResult

use of com.amazonaws.services.athena.model.GetQueryResultsResult in project aws-athena-query-federation by awslabs.

the class IntegrationTestBase method startQueryExecution.

/**
 * Sends a DB query via Athena and returns the query results.
 * @param query - The query string to be processed by Athena.
 * @return The query results object containing the metadata and row information.
 * @throws RuntimeException The Query is cancelled or has failed.
 */
public GetQueryResultsResult startQueryExecution(String query) throws RuntimeException {
    StartQueryExecutionRequest startQueryExecutionRequest = new StartQueryExecutionRequest().withWorkGroup(athenaWorkgroup).withQueryString(query);
    String queryExecutionId = sendAthenaQuery(startQueryExecutionRequest);
    logger.info("Query: [{}], Query Id: [{}]", query, queryExecutionId);
    waitForAthenaQueryResults(queryExecutionId);
    GetQueryResultsResult getQueryResultsResult = getAthenaQueryResults(queryExecutionId);
    return getQueryResultsResult;
}
Also used : StartQueryExecutionRequest(com.amazonaws.services.athena.model.StartQueryExecutionRequest) GetQueryResultsResult(com.amazonaws.services.athena.model.GetQueryResultsResult)

Example 2 with GetQueryResultsResult

use of com.amazonaws.services.athena.model.GetQueryResultsResult 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

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