javav2/example_code/athena/src/main/java/aws/example/athena/StartQueryExample.java
/**
     * Wait for an Athena query to complete, fail or to be cancelled. This is done by polling Athena over an
     * interval of time. If a query fails or is cancelled, then it will throw an exception.
     */
Wait for an Athena query to complete, fail or to be cancelled. This is done by polling Athena over an
interval of time. If a query fails or is cancelled, then it will throw an exception.
Wait for an Athena query to complete fail or to be cancelled . This is done by polling Athena over an interval of time . If a query fails or is cancelled then it will throw an exception .
private static void waitForQueryToComplete(AthenaClient athenaClient, String queryExecutionId) throws InterruptedException {
        GetQueryExecutionRequest getQueryExecutionRequest = GetQueryExecutionRequest.builder()
                .queryExecutionId(queryExecutionId).build();
        GetQueryExecutionResponse getQueryExecutionResponse;
        boolean isQueryStillRunning = true;
        while (isQueryStillRunning) {
            getQueryExecutionResponse = athenaClient.getQueryExecution(getQueryExecutionRequest);
            String queryState = getQueryExecutionResponse.queryExecution().status().state().toString();
            if (queryState.equals(QueryExecutionState.FAILED.toString())) {
                throw new RuntimeException("Query Failed to run with Error Message: " + getQueryExecutionResponse
                        .queryExecution().status().stateChangeReason());
            } else if (queryState.equals(QueryExecutionState.CANCELLED.toString())) {
                throw new RuntimeException("Query was cancelled.");
            } else if (queryState.equals(QueryExecutionState.SUCCEEDED.toString())) {
                isQueryStillRunning = false;
            } else {
                Thread.sleep(ExampleConstants.SLEEP_AMOUNT_IN_MS);
            }
            System.out.println("Current Status is: " + queryState);
        }
    }
private static void waitForQueryToComplete ( AthenaClient athenaClient , String queryExecutionId ) throws InterruptedException { GetQueryExecutionRequest getQueryExecutionRequest = GetQueryExecutionRequest . builder ( ) . queryExecutionId ( queryExecutionId ) . build ( ) ; GetQueryExecutionResponse getQueryExecutionResponse ; boolean isQueryStillRunning = true ; while ( isQueryStillRunning ) { getQueryExecutionResponse = athenaClient . getQueryExecution ( getQueryExecutionRequest ) ; String queryState = getQueryExecutionResponse . queryExecution ( ) . status ( ) . state ( ) . toString ( ) ; if ( queryState . equals ( QueryExecutionState . FAILED . toString ( ) ) ) { throw new RuntimeException ( "Query Failed to run with Error Message: " + getQueryExecutionResponse . queryExecution ( ) . status ( ) . stateChangeReason ( ) ) ; } else if ( queryState . equals ( QueryExecutionState . CANCELLED . toString ( ) ) ) { throw new RuntimeException ( "Query was cancelled." ) ; } else if ( queryState . equals ( QueryExecutionState . SUCCEEDED . toString ( ) ) ) { isQueryStillRunning = false ; } else { Thread . sleep ( ExampleConstants . SLEEP_AMOUNT_IN_MS ) ; } System . out . println ( "Current Status is: " + queryState ) ; } }
Wait for an Athena query to complete, fail or to be cancelled.
Wait for an Athena query to complete fail or to be cancelled .
// Sleep an amount of time before retrying again.