Table of Contents
A low-level client representing Amazon Athena:
import boto3
client = boto3.client('athena')
These are the available methods:
Returns the details of a single named query or a list of up to 50 queries, which you provide as an array of query ID strings. Use ListNamedQueries to get the list of named query IDs. If information could not be retrieved for a submitted query ID, information about the query ID submitted is listed under UnprocessedNamedQueryId . Named queries are different from executed queries. Use BatchGetQueryExecution to get details about each unique query execution, and ListQueryExecutions to get a list of query execution IDs.
See also: AWS API Documentation
Request Syntax
response = client.batch_get_named_query(
NamedQueryIds=[
'string',
]
)
[REQUIRED]
An array of query IDs.
{
'NamedQueries': [
{
'Name': 'string',
'Description': 'string',
'Database': 'string',
'QueryString': 'string',
'NamedQueryId': 'string'
},
],
'UnprocessedNamedQueryIds': [
{
'NamedQueryId': 'string',
'ErrorCode': 'string',
'ErrorMessage': 'string'
},
]
}
Response Structure
Information about the named query IDs submitted.
A query, where QueryString is the SQL query statements that comprise the query.
The plain-language name of the query.
A brief description of the query.
The database to which the query belongs.
The SQL query statements that comprise the query.
The unique identifier of the query.
Information about provided query IDs.
Information about a named query ID that could not be processed.
The unique identifier of the named query.
The error code returned when the processing request for the named query failed, if applicable.
The error message returned when the processing request for the named query failed, if applicable.
Returns the details of a single query execution or a list of up to 50 query executions, which you provide as an array of query execution ID strings. To get a list of query execution IDs, use ListQueryExecutions . Query executions are different from named (saved) queries. Use BatchGetNamedQuery to get details about named queries.
See also: AWS API Documentation
Request Syntax
response = client.batch_get_query_execution(
QueryExecutionIds=[
'string',
]
)
[REQUIRED]
An array of query execution IDs.
{
'QueryExecutions': [
{
'QueryExecutionId': 'string',
'Query': 'string',
'StatementType': 'DDL'|'DML'|'UTILITY',
'ResultConfiguration': {
'OutputLocation': 'string',
'EncryptionConfiguration': {
'EncryptionOption': 'SSE_S3'|'SSE_KMS'|'CSE_KMS',
'KmsKey': 'string'
}
},
'QueryExecutionContext': {
'Database': 'string'
},
'Status': {
'State': 'QUEUED'|'RUNNING'|'SUCCEEDED'|'FAILED'|'CANCELLED',
'StateChangeReason': 'string',
'SubmissionDateTime': datetime(2015, 1, 1),
'CompletionDateTime': datetime(2015, 1, 1)
},
'Statistics': {
'EngineExecutionTimeInMillis': 123,
'DataScannedInBytes': 123
}
},
],
'UnprocessedQueryExecutionIds': [
{
'QueryExecutionId': 'string',
'ErrorCode': 'string',
'ErrorMessage': 'string'
},
]
}
Response Structure
Information about a query execution.
Information about a single instance of a query execution.
The unique identifier for each query execution.
The SQL query statements which the query execution ran.
The type of query statement that was run. DDL indicates DDL query statements. DML indicates DML (Data Manipulation Language) query statements, such as CREATE TABLE AS SELECT . UTILITY indicates query statements other than DDL and DML, such as SHOW CREATE TABLE , or DESCRIBE <table> .
The location in Amazon S3 where query results were stored and the encryption option, if any, used for query results.
The location in Amazon S3 where your query results are stored, such as s3://path/to/query/bucket/ . For more information, see Queries and Query Result Files.
If query results are encrypted in Amazon S3, indicates the encryption option used (for example, SSE-KMS or CSE-KMS ) and key information.
Indicates whether Amazon S3 server-side encryption with Amazon S3-managed keys (SSE-S3 ), server-side encryption with KMS-managed keys (SSE-KMS ), or client-side encryption with KMS-managed keys (CSE-KMS) is used.
For SSE-KMS and CSE-KMS , this is the KMS key ARN or ID.
The database in which the query execution occurred.
The name of the database.
The completion date, current state, submission time, and state change reason (if applicable) for the query execution.
The state of query execution. QUEUED state is listed but is not used by Athena and is reserved for future use. RUNNING indicates that the query has been submitted to the service, and Athena will execute the query as soon as resources are available. SUCCEEDED indicates that the query completed without error. FAILED indicates that the query experienced an error and did not complete processing.``CANCELLED`` indicates that user input interrupted query execution.
Further detail about the status of the query.
The date and time that the query was submitted.
The date and time that the query completed.
The amount of data scanned during the query execution and the amount of time that it took to execute, and the type of statement that was run.
The number of milliseconds that the query took to execute.
The number of bytes in the data that was queried.
Information about the query executions that failed to run.
Describes a query execution that failed to process.
The unique identifier of the query execution.
The error code returned when the query execution failed to process, if applicable.
The error message returned when the query execution failed to process, if applicable.
Check if an operation can be paginated.
Creates a named query.
For code samples using the AWS SDK for Java, see Examples and Code Samples in the Amazon Athena User Guide .
See also: AWS API Documentation
Request Syntax
response = client.create_named_query(
Name='string',
Description='string',
Database='string',
QueryString='string',
ClientRequestToken='string'
)
[REQUIRED]
The plain language name for the query.
[REQUIRED]
The database to which the query belongs.
[REQUIRED]
The text of the query itself. In other words, all query statements.
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.
Warning
This token is listed as not required because AWS SDKs (for example the AWS SDK for Java) auto-generate the token for users. If you are not using the AWS SDK or the AWS CLI, you must provide this token or the action will fail.
This field is autopopulated if not provided.
dict
Response Syntax
{
'NamedQueryId': 'string'
}
Response Structure
(dict) --
NamedQueryId (string) --
The unique ID of the query.
Deletes a named query.
For code samples using the AWS SDK for Java, see Examples and Code Samples in the Amazon Athena User Guide .
See also: AWS API Documentation
Request Syntax
response = client.delete_named_query(
NamedQueryId='string'
)
[REQUIRED]
The unique ID of the query to delete.
This field is autopopulated if not provided.
{}
Response Structure
Generate a presigned url given a client, its method, and arguments
The presigned url
Returns information about a single query.
See also: AWS API Documentation
Request Syntax
response = client.get_named_query(
NamedQueryId='string'
)
[REQUIRED]
The unique ID of the query. Use ListNamedQueries to get query IDs.
{
'NamedQuery': {
'Name': 'string',
'Description': 'string',
'Database': 'string',
'QueryString': 'string',
'NamedQueryId': 'string'
}
}
Response Structure
Information about the query.
The plain-language name of the query.
A brief description of the query.
The database to which the query belongs.
The SQL query statements that comprise the query.
The unique identifier of the query.
Create a paginator for an operation.
Returns information about a single execution of a query. Each time a query executes, information about the query execution is saved with a unique ID.
See also: AWS API Documentation
Request Syntax
response = client.get_query_execution(
QueryExecutionId='string'
)
[REQUIRED]
The unique ID of the query execution.
{
'QueryExecution': {
'QueryExecutionId': 'string',
'Query': 'string',
'StatementType': 'DDL'|'DML'|'UTILITY',
'ResultConfiguration': {
'OutputLocation': 'string',
'EncryptionConfiguration': {
'EncryptionOption': 'SSE_S3'|'SSE_KMS'|'CSE_KMS',
'KmsKey': 'string'
}
},
'QueryExecutionContext': {
'Database': 'string'
},
'Status': {
'State': 'QUEUED'|'RUNNING'|'SUCCEEDED'|'FAILED'|'CANCELLED',
'StateChangeReason': 'string',
'SubmissionDateTime': datetime(2015, 1, 1),
'CompletionDateTime': datetime(2015, 1, 1)
},
'Statistics': {
'EngineExecutionTimeInMillis': 123,
'DataScannedInBytes': 123
}
}
}
Response Structure
Information about the query execution.
The unique identifier for each query execution.
The SQL query statements which the query execution ran.
The type of query statement that was run. DDL indicates DDL query statements. DML indicates DML (Data Manipulation Language) query statements, such as CREATE TABLE AS SELECT . UTILITY indicates query statements other than DDL and DML, such as SHOW CREATE TABLE , or DESCRIBE <table> .
The location in Amazon S3 where query results were stored and the encryption option, if any, used for query results.
The location in Amazon S3 where your query results are stored, such as s3://path/to/query/bucket/ . For more information, see Queries and Query Result Files.
If query results are encrypted in Amazon S3, indicates the encryption option used (for example, SSE-KMS or CSE-KMS ) and key information.
Indicates whether Amazon S3 server-side encryption with Amazon S3-managed keys (SSE-S3 ), server-side encryption with KMS-managed keys (SSE-KMS ), or client-side encryption with KMS-managed keys (CSE-KMS) is used.
For SSE-KMS and CSE-KMS , this is the KMS key ARN or ID.
The database in which the query execution occurred.
The name of the database.
The completion date, current state, submission time, and state change reason (if applicable) for the query execution.
The state of query execution. QUEUED state is listed but is not used by Athena and is reserved for future use. RUNNING indicates that the query has been submitted to the service, and Athena will execute the query as soon as resources are available. SUCCEEDED indicates that the query completed without error. FAILED indicates that the query experienced an error and did not complete processing.``CANCELLED`` indicates that user input interrupted query execution.
Further detail about the status of the query.
The date and time that the query was submitted.
The date and time that the query completed.
The amount of data scanned during the query execution and the amount of time that it took to execute, and the type of statement that was run.
The number of milliseconds that the query took to execute.
The number of bytes in the data that was queried.
Returns the results of a single query execution specified by QueryExecutionId . This request does not execute the query but returns results. Use StartQueryExecution to run a query.
See also: AWS API Documentation
Request Syntax
response = client.get_query_results(
QueryExecutionId='string',
NextToken='string',
MaxResults=123
)
[REQUIRED]
The unique ID of the query execution.
dict
Response Syntax
{
'UpdateCount': 123,
'ResultSet': {
'Rows': [
{
'Data': [
{
'VarCharValue': 'string'
},
]
},
],
'ResultSetMetadata': {
'ColumnInfo': [
{
'CatalogName': 'string',
'SchemaName': 'string',
'TableName': 'string',
'Name': 'string',
'Label': 'string',
'Type': 'string',
'Precision': 123,
'Scale': 123,
'Nullable': 'NOT_NULL'|'NULLABLE'|'UNKNOWN',
'CaseSensitive': True|False
},
]
}
},
'NextToken': 'string'
}
Response Structure
(dict) --
UpdateCount (integer) --
The number of rows inserted with a CREATE TABLE AS SELECT statement.
ResultSet (dict) --
The results of the query execution.
Rows (list) --
The rows in the table.
(dict) --
The rows that comprise a query result table.
Data (list) --
The data that populates a row in a query result table.
(dict) --
A piece of data (a field in the table).
VarCharValue (string) --
The value of the datum.
ResultSetMetadata (dict) --
The metadata that describes the column structure and data types of a table of query results.
ColumnInfo (list) --
Information about the columns returned in a query result metadata.
(dict) --
Information about the columns in a query execution result.
CatalogName (string) --
The catalog to which the query results belong.
SchemaName (string) --
The schema name (database name) to which the query results belong.
TableName (string) --
The table name for the query results.
Name (string) --
The name of the column.
Label (string) --
A column label.
Type (string) --
The data type of the column.
Precision (integer) --
For DECIMAL data types, specifies the total number of digits, up to 38. For performance reasons, we recommend up to 18 digits.
Scale (integer) --
For DECIMAL data types, specifies the total number of digits in the fractional part of the value. Defaults to 0.
Nullable (string) --
Indicates the column's nullable status.
CaseSensitive (boolean) --
Indicates whether values in the column are case-sensitive.
NextToken (string) --
A token to be used by the next request if this request is truncated.
Returns an object that can wait for some condition.
Provides a list of all available query IDs.
For code samples using the AWS SDK for Java, see Examples and Code Samples in the Amazon Athena User Guide .
See also: AWS API Documentation
Request Syntax
response = client.list_named_queries(
NextToken='string',
MaxResults=123
)
dict
Response Syntax
{
'NamedQueryIds': [
'string',
],
'NextToken': 'string'
}
Response Structure
(dict) --
NamedQueryIds (list) --
The list of unique query IDs.
NextToken (string) --
A token to be used by the next request if this request is truncated.
Provides a list of all available query execution IDs.
For code samples using the AWS SDK for Java, see Examples and Code Samples in the Amazon Athena User Guide .
See also: AWS API Documentation
Request Syntax
response = client.list_query_executions(
NextToken='string',
MaxResults=123
)
dict
Response Syntax
{
'QueryExecutionIds': [
'string',
],
'NextToken': 'string'
}
Response Structure
(dict) --
QueryExecutionIds (list) --
The unique IDs of each query execution as an array of strings.
NextToken (string) --
A token to be used by the next request if this request is truncated.
Runs (executes) the SQL query statements contained in the Query string.
For code samples using the AWS SDK for Java, see Examples and Code Samples in the Amazon Athena User Guide .
See also: AWS API Documentation
Request Syntax
response = client.start_query_execution(
QueryString='string',
ClientRequestToken='string',
QueryExecutionContext={
'Database': 'string'
},
ResultConfiguration={
'OutputLocation': 'string',
'EncryptionConfiguration': {
'EncryptionOption': 'SSE_S3'|'SSE_KMS'|'CSE_KMS',
'KmsKey': 'string'
}
}
)
[REQUIRED]
The SQL query statements to be executed.
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.
Warning
This token is listed as not required because AWS SDKs (for example the AWS SDK for Java) auto-generate the token for users. If you are not using the AWS SDK or the AWS CLI, you must provide this token or the action will fail.
This field is autopopulated if not provided.
The database within which the query executes.
The name of the database.
[REQUIRED]
Specifies information about where and how to save the results of the query execution.
The location in Amazon S3 where your query results are stored, such as s3://path/to/query/bucket/ . For more information, see Queries and Query Result Files.
If query results are encrypted in Amazon S3, indicates the encryption option used (for example, SSE-KMS or CSE-KMS ) and key information.
Indicates whether Amazon S3 server-side encryption with Amazon S3-managed keys (SSE-S3 ), server-side encryption with KMS-managed keys (SSE-KMS ), or client-side encryption with KMS-managed keys (CSE-KMS) is used.
For SSE-KMS and CSE-KMS , this is the KMS key ARN or ID.
dict
Response Syntax
{
'QueryExecutionId': 'string'
}
Response Structure
(dict) --
QueryExecutionId (string) --
The unique ID of the query that ran as a result of this request.
Stops a query execution.
For code samples using the AWS SDK for Java, see Examples and Code Samples in the Amazon Athena User Guide .
See also: AWS API Documentation
Request Syntax
response = client.stop_query_execution(
QueryExecutionId='string'
)
[REQUIRED]
The unique ID of the query execution to stop.
This field is autopopulated if not provided.
{}
Response Structure
The available paginators are:
paginator = client.get_paginator('get_query_results')
Creates an iterator that will paginate through responses from Athena.Client.get_query_results().
See also: AWS API Documentation
Request Syntax
response_iterator = paginator.paginate(
QueryExecutionId='string',
PaginationConfig={
'MaxItems': 123,
'PageSize': 123,
'StartingToken': 'string'
}
)
[REQUIRED]
The unique ID of the query execution.
A dictionary that provides parameters to control pagination.
The total number of items to return. If the total number of items available is more than the value specified in max-items then a NextToken will be provided in the output that you can use to resume pagination.
The size of each page.
A token to specify where to start paginating. This is the NextToken from a previous response.
dict
Response Syntax
{
'UpdateCount': 123,
'ResultSet': {
'Rows': [
{
'Data': [
{
'VarCharValue': 'string'
},
]
},
],
'ResultSetMetadata': {
'ColumnInfo': [
{
'CatalogName': 'string',
'SchemaName': 'string',
'TableName': 'string',
'Name': 'string',
'Label': 'string',
'Type': 'string',
'Precision': 123,
'Scale': 123,
'Nullable': 'NOT_NULL'|'NULLABLE'|'UNKNOWN',
'CaseSensitive': True|False
},
]
}
},
}
Response Structure
(dict) --
UpdateCount (integer) --
The number of rows inserted with a CREATE TABLE AS SELECT statement.
ResultSet (dict) --
The results of the query execution.
Rows (list) --
The rows in the table.
(dict) --
The rows that comprise a query result table.
Data (list) --
The data that populates a row in a query result table.
(dict) --
A piece of data (a field in the table).
VarCharValue (string) --
The value of the datum.
ResultSetMetadata (dict) --
The metadata that describes the column structure and data types of a table of query results.
ColumnInfo (list) --
Information about the columns returned in a query result metadata.
(dict) --
Information about the columns in a query execution result.
CatalogName (string) --
The catalog to which the query results belong.
SchemaName (string) --
The schema name (database name) to which the query results belong.
TableName (string) --
The table name for the query results.
Name (string) --
The name of the column.
Label (string) --
A column label.
Type (string) --
The data type of the column.
Precision (integer) --
For DECIMAL data types, specifies the total number of digits, up to 38. For performance reasons, we recommend up to 18 digits.
Scale (integer) --
For DECIMAL data types, specifies the total number of digits in the fractional part of the value. Defaults to 0.
Nullable (string) --
Indicates the column's nullable status.
CaseSensitive (boolean) --
Indicates whether values in the column are case-sensitive.
paginator = client.get_paginator('list_named_queries')
Creates an iterator that will paginate through responses from Athena.Client.list_named_queries().
See also: AWS API Documentation
Request Syntax
response_iterator = paginator.paginate(
PaginationConfig={
'MaxItems': 123,
'PageSize': 123,
'StartingToken': 'string'
}
)
A dictionary that provides parameters to control pagination.
The total number of items to return. If the total number of items available is more than the value specified in max-items then a NextToken will be provided in the output that you can use to resume pagination.
The size of each page.
A token to specify where to start paginating. This is the NextToken from a previous response.
{
'NamedQueryIds': [
'string',
],
}
Response Structure
The list of unique query IDs.
paginator = client.get_paginator('list_query_executions')
Creates an iterator that will paginate through responses from Athena.Client.list_query_executions().
See also: AWS API Documentation
Request Syntax
response_iterator = paginator.paginate(
PaginationConfig={
'MaxItems': 123,
'PageSize': 123,
'StartingToken': 'string'
}
)
A dictionary that provides parameters to control pagination.
The total number of items to return. If the total number of items available is more than the value specified in max-items then a NextToken will be provided in the output that you can use to resume pagination.
The size of each page.
A token to specify where to start paginating. This is the NextToken from a previous response.
{
'QueryExecutionIds': [
'string',
],
}
Response Structure
The unique IDs of each query execution as an array of strings.