createNamedQuery method

Future<CreateNamedQueryOutput> createNamedQuery({
  1. required String database,
  2. required String name,
  3. required String queryString,
  4. String? clientRequestToken,
  5. String? description,
  6. String? workGroup,
})

Creates a named query in the specified workgroup. Requires that you have access to the workgroup.

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.

Parameter database : The database to which the query belongs.

Parameter name : The query name.

Parameter queryString : The contents of the query with all query statements.

Parameter clientRequestToken : A unique case-sensitive string used to ensure the request to create the query is idempotent (executes only once). If another CreateNamedQuery 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 description : The query description.

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

Implementation

Future<CreateNamedQueryOutput> createNamedQuery({
  required String database,
  required String name,
  required String queryString,
  String? clientRequestToken,
  String? description,
  String? workGroup,
}) async {
  ArgumentError.checkNotNull(database, 'database');
  _s.validateStringLength(
    'database',
    database,
    1,
    255,
    isRequired: true,
  );
  ArgumentError.checkNotNull(name, 'name');
  _s.validateStringLength(
    'name',
    name,
    1,
    128,
    isRequired: true,
  );
  ArgumentError.checkNotNull(queryString, 'queryString');
  _s.validateStringLength(
    'queryString',
    queryString,
    1,
    262144,
    isRequired: true,
  );
  _s.validateStringLength(
    'clientRequestToken',
    clientRequestToken,
    32,
    128,
  );
  _s.validateStringLength(
    'description',
    description,
    1,
    1024,
  );
  final headers = <String, String>{
    'Content-Type': 'application/x-amz-json-1.1',
    'X-Amz-Target': 'AmazonAthena.CreateNamedQuery'
  };
  final jsonResponse = await _protocol.send(
    method: 'POST',
    requestUri: '/',
    exceptionFnMap: _exceptionFns,
    // TODO queryParams
    headers: headers,
    payload: {
      'Database': database,
      'Name': name,
      'QueryString': queryString,
      'ClientRequestToken':
          clientRequestToken ?? _s.generateIdempotencyToken(),
      if (description != null) 'Description': description,
      if (workGroup != null) 'WorkGroup': workGroup,
    },
  );

  return CreateNamedQueryOutput.fromJson(jsonResponse.body);
}