Amazon Athena

2018/10/11 - Amazon Athena - 3 updated api methods

Changes  1. GetQueryExecution API changes to return statementType of a submitted Athena query. 2. GetQueryResults API changes to return the number of rows added to a table when a CTAS query is executed.

BatchGetQueryExecution (updated) Link ¶
Changes (response)
{'QueryExecutions': {'StatementType': 'DDL | DML | UTILITY'}}

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

client.batch_get_query_execution(
    QueryExecutionIds=[
        'string',
    ]
)
type QueryExecutionIds

list

param QueryExecutionIds

[REQUIRED]

An array of query execution IDs.

  • (string) --

rtype

dict

returns

Response Syntax

{
    '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

  • (dict) --

    • QueryExecutions (list) --

      Information about a query execution.

      • (dict) --

        Information about a single instance of a query execution.

        • QueryExecutionId (string) --

          The unique identifier for each query execution.

        • Query (string) --

          The SQL query statements which the query execution ran.

        • StatementType (string) --

          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> .

        • ResultConfiguration (dict) --

          The location in Amazon S3 where query results were stored and the encryption option, if any, used for query results.

          • OutputLocation (string) --

            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.

          • EncryptionConfiguration (dict) --

            If query results are encrypted in Amazon S3, indicates the encryption option used (for example, SSE-KMS or CSE-KMS ) and key information.

            • EncryptionOption (string) --

              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.

            • KmsKey (string) --

              For SSE-KMS and CSE-KMS , this is the KMS key ARN or ID.

        • QueryExecutionContext (dict) --

          The database in which the query execution occurred.

          • Database (string) --

            The name of the database.

        • Status (dict) --

          The completion date, current state, submission time, and state change reason (if applicable) for the query execution.

          • State (string) --

            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.

          • StateChangeReason (string) --

            Further detail about the status of the query.

          • SubmissionDateTime (datetime) --

            The date and time that the query was submitted.

          • CompletionDateTime (datetime) --

            The date and time that the query completed.

        • Statistics (dict) --

          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.

          • EngineExecutionTimeInMillis (integer) --

            The number of milliseconds that the query took to execute.

          • DataScannedInBytes (integer) --

            The number of bytes in the data that was queried.

    • UnprocessedQueryExecutionIds (list) --

      Information about the query executions that failed to run.

      • (dict) --

        Describes a query execution that failed to process.

        • QueryExecutionId (string) --

          The unique identifier of the query execution.

        • ErrorCode (string) --

          The error code returned when the query execution failed to process, if applicable.

        • ErrorMessage (string) --

          The error message returned when the query execution failed to process, if applicable.

GetQueryExecution (updated) Link ¶
Changes (response)
{'QueryExecution': {'StatementType': 'DDL | DML | UTILITY'}}

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

client.get_query_execution(
    QueryExecutionId='string'
)
type QueryExecutionId

string

param QueryExecutionId

[REQUIRED]

The unique ID of the query execution.

rtype

dict

returns

Response Syntax

{
    '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

  • (dict) --

    • QueryExecution (dict) --

      Information about the query execution.

      • QueryExecutionId (string) --

        The unique identifier for each query execution.

      • Query (string) --

        The SQL query statements which the query execution ran.

      • StatementType (string) --

        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> .

      • ResultConfiguration (dict) --

        The location in Amazon S3 where query results were stored and the encryption option, if any, used for query results.

        • OutputLocation (string) --

          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.

        • EncryptionConfiguration (dict) --

          If query results are encrypted in Amazon S3, indicates the encryption option used (for example, SSE-KMS or CSE-KMS ) and key information.

          • EncryptionOption (string) --

            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.

          • KmsKey (string) --

            For SSE-KMS and CSE-KMS , this is the KMS key ARN or ID.

      • QueryExecutionContext (dict) --

        The database in which the query execution occurred.

        • Database (string) --

          The name of the database.

      • Status (dict) --

        The completion date, current state, submission time, and state change reason (if applicable) for the query execution.

        • State (string) --

          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.

        • StateChangeReason (string) --

          Further detail about the status of the query.

        • SubmissionDateTime (datetime) --

          The date and time that the query was submitted.

        • CompletionDateTime (datetime) --

          The date and time that the query completed.

      • Statistics (dict) --

        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.

        • EngineExecutionTimeInMillis (integer) --

          The number of milliseconds that the query took to execute.

        • DataScannedInBytes (integer) --

          The number of bytes in the data that was queried.

GetQueryResults (updated) Link ¶
Changes (response)
{'UpdateCount': 'long'}

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

client.get_query_results(
    QueryExecutionId='string',
    NextToken='string',
    MaxResults=123
)
type QueryExecutionId

string

param QueryExecutionId

[REQUIRED]

The unique ID of the query execution.

type NextToken

string

param NextToken

The token that specifies where to start pagination if a previous request was truncated.

type MaxResults

integer

param MaxResults

The maximum number of results (rows) to return in this request.

rtype

dict

returns

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.