startQueryExecution method

Future<StartQueryExecutionOutput> startQueryExecution({
  1. required String queryString,
  2. String? clientRequestToken,
  3. QueryExecutionContext? queryExecutionContext,
  4. ResultConfiguration? resultConfiguration,
  5. String? workGroup,
})

Runs the SQL query statements contained in the Query. Requires you to have access to the workgroup in which the query ran. Running queries against an external catalog requires GetDataCatalog permission to the catalog. For code samples using the AWS SDK for Java, see Examples and Code Samples in the Amazon Athena User Guide.

May throw InternalServerException. May throw InvalidRequestException. May throw TooManyRequestsException.

Parameter queryString : The SQL query statements to be executed.

Parameter clientRequestToken : A unique case-sensitive string used to ensure the request to create the query is idempotent (executes only once). If another StartQueryExecution request is received, the same response is returned and another query is not created. If a parameter has changed, for example, the QueryString, an error is returned.

Parameter queryExecutionContext : The database within which the query executes.

Parameter resultConfiguration : Specifies information about where and how to save the results of the query execution. If the query runs in a workgroup, then workgroup's settings may override query settings. This affects the query results location. The workgroup settings override is specified in EnforceWorkGroupConfiguration (true/false) in the WorkGroupConfiguration. See WorkGroupConfiguration$EnforceWorkGroupConfiguration.

Parameter workGroup : The name of the workgroup in which the query is being started.

Implementation

Future<StartQueryExecutionOutput> startQueryExecution({
  required String queryString,
  String? clientRequestToken,
  QueryExecutionContext? queryExecutionContext,
  ResultConfiguration? resultConfiguration,
  String? workGroup,
}) async {
  ArgumentError.checkNotNull(queryString, 'queryString');
  _s.validateStringLength(
    'queryString',
    queryString,
    1,
    262144,
    isRequired: true,
  );
  _s.validateStringLength(
    'clientRequestToken',
    clientRequestToken,
    32,
    128,
  );
  final headers = <String, String>{
    'Content-Type': 'application/x-amz-json-1.1',
    'X-Amz-Target': 'AmazonAthena.StartQueryExecution'
  };
  final jsonResponse = await _protocol.send(
    method: 'POST',
    requestUri: '/',
    exceptionFnMap: _exceptionFns,
    // TODO queryParams
    headers: headers,
    payload: {
      'QueryString': queryString,
      'ClientRequestToken':
          clientRequestToken ?? _s.generateIdempotencyToken(),
      if (queryExecutionContext != null)
        'QueryExecutionContext': queryExecutionContext,
      if (resultConfiguration != null)
        'ResultConfiguration': resultConfiguration,
      if (workGroup != null) 'WorkGroup': workGroup,
    },
  );

  return StartQueryExecutionOutput.fromJson(jsonResponse.body);
}