Skip to content

get_query_results

get_query_results(
    query_execution_id: QueryExecutionId,
    *,
    config_overrides: Optional[AthenaClientConfig] = None,
    next_token: Optional[Token] = None,
    max_results: Optional[MaxQueryResults] = None,
    query_result_type: Optional[QueryResultType] = None,
) -> GetQueryResultsOutput

Streams the results of a single query execution specified by QueryExecutionId from the Athena query results location in Amazon S3. For more information, see Working with query results, recent queries, and output files in the Amazon Athena User Guide. This request does not execute the query but returns results. Use StartQueryExecution to run a query.

To stream query results successfully, the IAM principal with permission to call GetQueryResults also must have permissions to the Amazon S3 GetObject action for the Athena query results location.

IAM principals with permission to the Amazon S3 GetObject action for the query results location are able to retrieve query results from Amazon S3 even if permission to the GetQueryResults action is denied. To restrict user or role access, ensure that Amazon S3 permissions to the Athena query location are denied.

Parameters:

  • query_execution_id (QueryExecutionId) –

    The unique ID of the query execution.

  • next_token (Optional[Token], default: None ) –

    A token generated by the Athena service that specifies where to continue pagination if a previous request was truncated. To obtain the next set of pages, pass in the NextToken from the response object of the previous page call.

  • max_results (Optional[MaxQueryResults], default: None ) –

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

  • query_result_type (Optional[QueryResultType], default: None ) –

    When you set this to DATA_ROWS or empty, GetQueryResults returns the query results in rows. If set to DATA_MANIFEST, it returns the manifest file in rows. Only the query types CREATE TABLE AS SELECT, UNLOAD, and INSERT can generate a manifest file. If you use DATA_MANIFEST for other query types, the query will fail.

Raises:

Source code in docs_src/capo_athena/_services/athena.py
def get_query_results(
    self,
    query_execution_id: "capo_athena.types.query_execution_id.QueryExecutionId",
    *,
    config_overrides: Optional[AthenaClientConfig] = None,
    next_token: Optional["capo_athena.types.token.Token"] = None,
    max_results: Optional[
        "capo_athena.types.max_query_results.MaxQueryResults"
    ] = None,
    query_result_type: Optional[
        "capo_athena.types.query_result_type.QueryResultType"
    ] = None,
) -> "capo_athena.types.get_query_results_output.GetQueryResultsOutput":
    """<p>Streams the results of a single query execution specified by <code>QueryExecutionId</code> from the Athena query results location in Amazon S3. For more information, see <a href="https://docs.aws.amazon.com/athena/latest/ug/querying.html">Working with query results, recent queries, and output files</a> in the <i>Amazon Athena User Guide</i>. This request does not execute the query but returns results. Use <a>StartQueryExecution</a> to run a query.</p> <p>To stream query results successfully, the IAM principal with permission to call <code>GetQueryResults</code> also must have permissions to the Amazon S3 <code>GetObject</code> action for the Athena query results location.</p> <important> <p>IAM principals with permission to the Amazon S3 <code>GetObject</code> action for the query results location are able to retrieve query results from Amazon S3 even if permission to the <code>GetQueryResults</code> action is denied. To restrict user or role access, ensure that Amazon S3 permissions to the Athena query location are denied.</p> </important>

    Args:
        query_execution_id: <p>The unique ID of the query execution.</p>
        next_token: <p>A token generated by the Athena service that specifies where to continue pagination if a previous request was truncated. To obtain the next set of pages, pass in the <code>NextToken</code> from the response object of the previous page call.</p>
        max_results: <p>The maximum number of results (rows) to return in this request.</p>
        query_result_type: <p> When you set this to <code>DATA_ROWS</code> or empty, <code>GetQueryResults</code> returns the query results in rows. If set to <code>DATA_MANIFEST</code>, it returns the manifest file in rows. Only the query types <code>CREATE TABLE AS SELECT</code>, <code>UNLOAD</code>, and <code>INSERT</code> can generate a manifest file. If you use <code>DATA_MANIFEST</code> for other query types, the query will fail. </p>

    Raises:
        capo_athena.errors.internal_server_exception.InternalServerException: <p>Indicates a platform issue, which may be due to a transient condition or outage.</p>
        capo_athena.errors.invalid_request_exception.InvalidRequestException: <p>Indicates that something is wrong with the input to the request. For example, a required parameter may be missing or out of range.</p>
        capo_athena.errors.too_many_requests_exception.TooManyRequestsException: <p>Indicates that the request was throttled.</p>
        capo_athena.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

    def _handler(
        req: "OperationRequest[capo_athena.types.get_query_results_input.GetQueryResultsInput]",
    ) -> OperationResponse[
        "capo_athena.types.get_query_results_output.GetQueryResultsOutput"
    ]:
        import capo_athena._operations.amazon_athena.get_query_results

        output, http_response = (
            capo_athena._operations.amazon_athena.get_query_results.get_query_results(
                req.options, req.input
            )
        )
        return OperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("GetQueryResults")
    )
    input_: capo_athena.types.get_query_results_input.GetQueryResultsInput = {
        "query_execution_id": query_execution_id
    }
    if next_token is not None:
        input_["next_token"] = next_token
    if max_results is not None:
        input_["max_results"] = max_results
    if query_result_type is not None:
        input_["query_result_type"] = query_result_type

    response = execute_pipeline(
        OperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    response.response.close()
    return response.output