Example usage for com.amazonaws.services.athena.model StartQueryExecutionResult getQueryExecutionId

List of usage examples for com.amazonaws.services.athena.model StartQueryExecutionResult getQueryExecutionId

Introduction

In this page you can find the example usage for com.amazonaws.services.athena.model StartQueryExecutionResult getQueryExecutionId.

Prototype


public String getQueryExecutionId() 

Source Link

Document

The unique ID of the query that ran as a result of this request.

Usage

From source file:com.nike.cerberus.lambda.waf.AthenaQuery.java

License:Apache License

/**
 * Executes an Athena query and waits for it to finish returning the results
 */// ww w  . jav a 2  s  .c o  m
private GetQueryResultsResult executeAthenaQuery(String query) throws InterruptedException {

    logger.info("QUERY: " + query);

    AmazonAthena athena = AmazonAthenaClient.builder().withRegion(Regions.US_WEST_2)
            .withCredentials(DefaultAWSCredentialsProviderChain.getInstance()).build();

    StartQueryExecutionResult result = athena.startQueryExecution(new StartQueryExecutionRequest()
            .withQueryString(query).withResultConfiguration(new ResultConfiguration().withOutputLocation(
                    "s3://aws-athena-query-results-933764306573-us-west-2/ip-address-translator")));

    String id = result.getQueryExecutionId();

    String state;
    do {
        state = athena.getQueryExecution(new GetQueryExecutionRequest().withQueryExecutionId(id))
                .getQueryExecution().getStatus().getState();
        logger.info(String.format("Polling for query to finish: current status: %s", state));
        Thread.sleep(1000);
    } while (state.equals("RUNNING"));

    logger.info(String.format("The query: %s is in state: %s, fetching results", id, state));

    return athena.getQueryResults(new GetQueryResultsRequest().withQueryExecutionId(id));
}