Search in sources :

Example 1 with QueryExecutionContext

use of com.amazonaws.services.athena.model.QueryExecutionContext in project aws-doc-sdk-examples by awsdocs.

the class StartQueryExample method submitAthenaQuery.

/**
 * Submits a sample query to Athena and returns the execution ID of the query.
 */
private static String submitAthenaQuery(AmazonAthena athenaClient) {
    // The QueryExecutionContext allows us to set the Database.
    QueryExecutionContext queryExecutionContext = new QueryExecutionContext().withDatabase(ExampleConstants.ATHENA_DEFAULT_DATABASE);
    // The result configuration specifies where the results of the query should go in S3 and encryption options
    ResultConfiguration resultConfiguration = new ResultConfiguration().withOutputLocation(ExampleConstants.ATHENA_OUTPUT_BUCKET);
    // Create the StartQueryExecutionRequest to send to Athena which will start the query.
    StartQueryExecutionRequest startQueryExecutionRequest = new StartQueryExecutionRequest().withQueryString(ExampleConstants.ATHENA_SAMPLE_QUERY).withQueryExecutionContext(queryExecutionContext).withResultConfiguration(resultConfiguration);
    StartQueryExecutionResult startQueryExecutionResult = athenaClient.startQueryExecution(startQueryExecutionRequest);
    return startQueryExecutionResult.getQueryExecutionId();
}
Also used : StartQueryExecutionResult(com.amazonaws.services.athena.model.StartQueryExecutionResult) ResultConfiguration(com.amazonaws.services.athena.model.ResultConfiguration) QueryExecutionContext(com.amazonaws.services.athena.model.QueryExecutionContext) StartQueryExecutionRequest(com.amazonaws.services.athena.model.StartQueryExecutionRequest)

Example 2 with QueryExecutionContext

use of com.amazonaws.services.athena.model.QueryExecutionContext in project aws-doc-sdk-examples by awsdocs.

the class StopQueryExecutionExample method submitAthenaQuery.

/**
 * Submits an example query and returns a query execution ID of a running query to stop.
 */
public static String submitAthenaQuery(AmazonAthena athenaClient) {
    QueryExecutionContext queryExecutionContext = new QueryExecutionContext().withDatabase(ExampleConstants.ATHENA_DEFAULT_DATABASE);
    ResultConfiguration resultConfiguration = new ResultConfiguration().withOutputLocation(ExampleConstants.ATHENA_OUTPUT_BUCKET);
    StartQueryExecutionRequest startQueryExecutionRequest = new StartQueryExecutionRequest().withQueryString(ExampleConstants.ATHENA_SAMPLE_QUERY).withQueryExecutionContext(queryExecutionContext).withResultConfiguration(resultConfiguration);
    StartQueryExecutionResult startQueryExecutionResult = athenaClient.startQueryExecution(startQueryExecutionRequest);
    return startQueryExecutionResult.getQueryExecutionId();
}
Also used : StartQueryExecutionResult(com.amazonaws.services.athena.model.StartQueryExecutionResult) ResultConfiguration(com.amazonaws.services.athena.model.ResultConfiguration) QueryExecutionContext(com.amazonaws.services.athena.model.QueryExecutionContext) StartQueryExecutionRequest(com.amazonaws.services.athena.model.StartQueryExecutionRequest)

Aggregations

QueryExecutionContext (com.amazonaws.services.athena.model.QueryExecutionContext)2 ResultConfiguration (com.amazonaws.services.athena.model.ResultConfiguration)2 StartQueryExecutionRequest (com.amazonaws.services.athena.model.StartQueryExecutionRequest)2 StartQueryExecutionResult (com.amazonaws.services.athena.model.StartQueryExecutionResult)2