Skip to content

execute_query async

execute_query(
    graph_identifier: GraphIdentifier,
    query_string: str,
    language: QueryLanguage,
    *,
    config_overrides: Optional[AsyncNeptuneGraphClientConfig] = None,
    parameters: Optional[DocumentValuedMap] = None,
    plan_cache: Optional[PlanCacheType] = None,
    explain_mode: Optional[ExplainMode] = None,
    query_timeout_milliseconds: Optional[int] = None,
) -> AsyncGenerator[ExecuteQueryOutput]

Execute an openCypher query.

When invoking this operation in a Neptune Analytics cluster, the IAM user or role making the request must have a policy attached that allows one of the following IAM actions in that cluster, depending on the query:

  • neptune-graph:ReadDataViaQuery

  • neptune-graph:WriteDataViaQuery

  • neptune-graph:DeleteDataViaQuery

Parameters:

  • graph_identifier (GraphIdentifier) –

    The unique identifier of the Neptune Analytics graph.

  • query_string (str) –

    The query string to be executed.

  • language (QueryLanguage) –

    The query language the query is written in. Currently only openCypher is supported.

  • parameters (Optional[DocumentValuedMap], default: None ) –

    The data parameters the query can use in JSON format. For example: {"name": "john", "age": 20}. (optional)

  • plan_cache (Optional[PlanCacheType], default: None ) –

    Query plan cache is a feature that saves the query plan and reuses it on successive executions of the same query. This reduces query latency, and works for both READ and UPDATE queries. The plan cache is an LRU cache with a 5 minute TTL and a capacity of 1000.

  • explain_mode (Optional[ExplainMode], default: None ) –

    The explain mode parameter returns a query explain instead of the actual query results. A query explain can be used to gather insights about the query execution such as planning decisions, time spent on each operator, solutions flowing etc.

  • query_timeout_milliseconds (Optional[int], default: None ) –

    Specifies the query timeout duration, in milliseconds. (optional)

Raises:

Source code in docs_src/capo_neptune_graph/_services/async_neptune_graph.py
@asynccontextmanager
async def execute_query(
    self,
    graph_identifier: "capo_neptune_graph.types.graph_identifier.GraphIdentifier",
    query_string: str,
    language: "capo_neptune_graph.types.query_language.QueryLanguage",
    *,
    config_overrides: Optional[AsyncNeptuneGraphClientConfig] = None,
    parameters: Optional[
        "capo_neptune_graph.types.document_valued_map.DocumentValuedMap"
    ] = None,
    plan_cache: Optional[
        "capo_neptune_graph.types.plan_cache_type.PlanCacheType"
    ] = None,
    explain_mode: Optional[
        "capo_neptune_graph.types.explain_mode.ExplainMode"
    ] = None,
    query_timeout_milliseconds: Optional[int] = None,
) -> "AsyncGenerator[capo_neptune_graph.types.execute_query_output.ExecuteQueryOutput]":
    """<p>Execute an openCypher query.</p> <p> When invoking this operation in a Neptune Analytics cluster, the IAM user or role making the request must have a policy attached that allows one of the following IAM actions in that cluster, depending on the query: </p> <ul> <li> <p>neptune-graph:ReadDataViaQuery</p> </li> <li> <p>neptune-graph:WriteDataViaQuery</p> </li> <li> <p>neptune-graph:DeleteDataViaQuery</p> </li> </ul>

    Args:
        graph_identifier: <p>The unique identifier of the Neptune Analytics graph.</p>
        query_string: <p>The query string to be executed.</p>
        language: <p>The query language the query is written in. Currently only openCypher is supported.</p>
        parameters: <p>The data parameters the query can use in JSON format. For example: {"name": "john", "age": 20}. (optional) </p>
        plan_cache: <p>Query plan cache is a feature that saves the query plan and reuses it on successive executions of the same query. This reduces query latency, and works for both <code>READ</code> and <code>UPDATE</code> queries. The plan cache is an LRU cache with a 5 minute TTL and a capacity of 1000.</p>
        explain_mode: <p>The explain mode parameter returns a query explain instead of the actual query results. A query explain can be used to gather insights about the query execution such as planning decisions, time spent on each operator, solutions flowing etc.</p>
        query_timeout_milliseconds: <p>Specifies the query timeout duration, in milliseconds. (optional)</p>

    Raises:
        capo_neptune_graph.errors.access_denied_exception.AccessDeniedException: <p>Raised in case of an authentication or authorization failure.</p>
        capo_neptune_graph.errors.conflict_exception.ConflictException: <p>Raised when a conflict is encountered.</p>
        capo_neptune_graph.errors.internal_server_exception.InternalServerException: <p>A failure occurred on the server.</p>
        capo_neptune_graph.errors.throttling_exception.ThrottlingException: <p>The exception was interrupted by throttling.</p>
        capo_neptune_graph.errors.unprocessable_exception.UnprocessableException: <p>Request cannot be processed due to known reasons. Eg. partition full.</p>
        capo_neptune_graph.errors.validation_exception.ValidationException: <p>A resource could not be validated.</p>
        capo_neptune_graph.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

    async def _handler(
        req: "AsyncOperationRequest[capo_neptune_graph.types.execute_query_input.ExecuteQueryInput]",
    ) -> AsyncOperationResponse[
        "capo_neptune_graph.types.execute_query_output.ExecuteQueryOutput"
    ]:
        import capo_neptune_graph._operations.amazon_neptune_graph.execute_query

        (
            output,
            http_response,
        ) = await capo_neptune_graph._operations.amazon_neptune_graph.execute_query.async_execute_query(
            req.options, req.input
        )
        return AsyncOperationResponse(output=output, response=http_response)

    def _redact_output(
        output: "capo_neptune_graph.types.execute_query_output.ExecuteQueryOutput",
    ) -> dict[str, Any]:
        import capo_neptune_graph.types.execute_query_output

        return capo_neptune_graph.types.execute_query_output.redact_sensitive(
            output
        )

    interceptors_, options_ = self.operation_options(
        config_overrides,
        OperationLogging("ExecuteQuery", redact_output=_redact_output),
    )
    input_: capo_neptune_graph.types.execute_query_input.ExecuteQueryInput = {
        "graph_identifier": graph_identifier,
        "query_string": query_string,
        "language": language,
    }
    if parameters is not None:
        input_["parameters"] = parameters
    if plan_cache is not None:
        input_["plan_cache"] = plan_cache
    if explain_mode is not None:
        input_["explain_mode"] = explain_mode
    if query_timeout_milliseconds is not None:
        input_["query_timeout_milliseconds"] = query_timeout_milliseconds

    response = await aexecute_pipeline(
        AsyncOperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    try:
        yield response.output
    finally:
        await response.response.aclose()