diff --git a/.generator/schemas/v2/openapi.yaml b/.generator/schemas/v2/openapi.yaml index ed984a56d0..87a6ec9380 100644 --- a/.generator/schemas/v2/openapi.yaml +++ b/.generator/schemas/v2/openapi.yaml @@ -30970,6 +30970,257 @@ components: example: 1722439510282 format: int64 type: integer + DdsqlTabularQueryColumn: + description: A single column of a DDSQL tabular query result. + properties: + name: + description: Name of the column as projected by the SQL statement. + example: service + type: string + type: + description: |- + DDSQL data type of the column's values, for example `VARCHAR`, `BIGINT`, + `DECIMAL`, `BOOLEAN`, `TIMESTAMP`, `JSON`, or an array variant such as + `VARCHAR[]`. See the + [DDSQL data-types reference](https://docs.datadoghq.com/ddsql_reference/#data-types) + for the full, up-to-date list. + example: VARCHAR + type: string + values: + description: |- + Column values in row order. The element type matches the column's `type`; + for example a `VARCHAR` column carries strings, a `TIMESTAMP` column carries + Unix-millisecond integers. `null` is allowed for missing values. + example: + - web-store + - checkout + items: {} + type: array + required: + - name + - type + - values + type: object + DdsqlTabularQueryColumns: + description: |- + Column-major result set. Each element carries one column's name, type, and values, + with one value per row of the result. Set when `state` is `completed`. + items: + $ref: "#/components/schemas/DdsqlTabularQueryColumn" + type: array + DdsqlTabularQueryFetchRequest: + description: Wrapper for a DDSQL tabular query fetch request. + properties: + data: + $ref: "#/components/schemas/DdsqlTabularQueryFetchRequestData" + required: + - data + type: object + DdsqlTabularQueryFetchRequestAttributes: + description: Attributes describing which previously submitted DDSQL query to fetch. + properties: + query_id: + description: |- + Opaque token returned by an earlier execute or fetch response that carried + `state: running`. Identifies the query to poll for results. + example: "eyJxdWVyeSI6ICJTRUxFQ1QgKiBGUk9NIGxvZ3MifQ==" + type: string + required: + - query_id + type: object + DdsqlTabularQueryFetchRequestData: + description: JSON:API resource object for a DDSQL tabular query fetch request. + properties: + attributes: + $ref: "#/components/schemas/DdsqlTabularQueryFetchRequestAttributes" + type: + $ref: "#/components/schemas/DdsqlTabularQueryFetchRequestType" + required: + - type + - attributes + type: object + DdsqlTabularQueryFetchRequestType: + default: ddsql_query_fetch_request + description: JSON:API resource type for a DDSQL tabular query fetch request. + enum: + - ddsql_query_fetch_request + example: ddsql_query_fetch_request + type: string + x-enum-varnames: + - DDSQL_QUERY_FETCH_REQUEST + DdsqlTabularQueryRequest: + description: Wrapper for a DDSQL tabular query execution request. + properties: + data: + $ref: "#/components/schemas/DdsqlTabularQueryRequestData" + required: + - data + type: object + DdsqlTabularQueryRequestAttributes: + description: Attributes describing the DDSQL query to execute. + properties: + query: + description: |- + The DDSQL statement to execute. DDSQL is Datadog's SQL dialect, which is a subset + of PostgreSQL, scoped to Datadog data sources. + example: "SELECT cloud_provider, count(*) FROM dd.hosts group by cloud_provider" + type: string + row_limit: + description: |- + Cap on the number of rows returned. Defaults to 5,000 when omitted. Must be + between 1 and 10,000 inclusive; values outside this range are rejected with 400. + example: 1000 + format: int64 + maximum: 10000 + minimum: 1 + type: integer + time: + $ref: "#/components/schemas/DdsqlTabularQueryTimeWindow" + required: + - query + - time + type: object + DdsqlTabularQueryRequestData: + description: JSON:API resource object for a DDSQL tabular query execution request. + properties: + attributes: + $ref: "#/components/schemas/DdsqlTabularQueryRequestAttributes" + type: + $ref: "#/components/schemas/DdsqlTabularQueryRequestType" + required: + - type + - attributes + type: object + DdsqlTabularQueryRequestType: + default: ddsql_query_request + description: JSON:API resource type for a DDSQL tabular query request. + enum: + - ddsql_query_request + example: ddsql_query_request + type: string + x-enum-varnames: + - DDSQL_QUERY_REQUEST + DdsqlTabularQueryResponse: + description: |- + Response envelope for both the execute and fetch DDSQL tabular query endpoints. + Carries the JSON:API primary resource and a top-level `meta` block with + request-scoped observability handles. + properties: + data: + $ref: "#/components/schemas/DdsqlTabularQueryResponseData" + meta: + $ref: "#/components/schemas/DdsqlTabularQueryResponseMeta" + required: + - data + - meta + type: object + DdsqlTabularQueryResponseAttributes: + description: |- + Attributes of a DDSQL tabular query response. `query_id` is set when + `state` is `running`; `columns` is set when `state` is `completed`. + properties: + columns: + $ref: "#/components/schemas/DdsqlTabularQueryColumns" + query_id: + description: |- + Opaque token to pass to the fetch endpoint to poll for results. + Set when `state` is `running` and absent when `state` is `completed`. + example: "eyJxdWVyeSI6ICJTRUxFQ1QgKiBGUk9NIGxvZ3MifQ==" + type: string + state: + $ref: "#/components/schemas/DdsqlTabularQueryState" + warnings: + $ref: "#/components/schemas/DdsqlTabularQueryWarnings" + required: + - state + type: object + DdsqlTabularQueryResponseData: + description: JSON:API resource object for a DDSQL tabular query response. + properties: + attributes: + $ref: "#/components/schemas/DdsqlTabularQueryResponseAttributes" + id: + description: Stable identifier for the query response resource. + example: "00000000-0000-0000-0000-000000000000" + type: string + type: + $ref: "#/components/schemas/DdsqlTabularQueryResponseType" + required: + - id + - type + - attributes + type: object + DdsqlTabularQueryResponseMeta: + description: |- + Top-level JSON:API meta block accompanying every DDSQL tabular query response. + Carries standard observability handles for client-side correlation. + properties: + elapsed: + description: Server-side time spent serving this request, in milliseconds. + example: 87 + format: int64 + type: integer + request_id: + description: |- + Echo of the `DD-Request-ID` header assigned by Datadog's edge to this request, + for support correlation. + example: "req-7f3e7d2c-1a0b-4d3e-9b2a-3c4d5e6f7082" + type: string + required: + - elapsed + - request_id + type: object + DdsqlTabularQueryResponseType: + default: ddsql_query_response + description: JSON:API resource type for a DDSQL tabular query response. + enum: + - ddsql_query_response + example: ddsql_query_response + type: string + x-enum-varnames: + - DDSQL_QUERY_RESPONSE + DdsqlTabularQueryState: + description: |- + Lifecycle state of a DDSQL tabular query response. + `running` means the query is still executing and the client should poll + the fetch endpoint with the returned `query_id`. `completed` means the + result set is inlined in `columns` and no further polling is required. + enum: + - running + - completed + example: completed + type: string + x-enum-varnames: + - RUNNING + - COMPLETED + DdsqlTabularQueryTimeWindow: + description: |- + Time window scoping the underlying data sources, expressed in Unix milliseconds + since the epoch. Inclusive on `from_timestamp`, exclusive on `to_timestamp`. + Results from static tables (for example, `dd.hosts`) are not affected by the + time window, but the field must still be provided. + properties: + from_timestamp: + description: Start of the query window (inclusive), in Unix milliseconds since the epoch. + example: 1736942400000 + format: int64 + type: integer + to_timestamp: + description: End of the query window (exclusive), in Unix milliseconds since the epoch. + example: 1736946000000 + format: int64 + type: integer + required: + - from_timestamp + - to_timestamp + type: object + DdsqlTabularQueryWarnings: + description: Non-fatal messages emitted by the query engine while serving this response. + items: + description: A single non-fatal warning message. + example: "Query result was truncated at the configured row_limit." + type: string + type: array DefaultRulesetsPerLanguageData: description: The primary data object in the default rulesets per language response. properties: @@ -133778,6 +134029,231 @@ paths: x-unstable: |- **Note: Data Access is in preview. If you have any feedback, contact [Datadog support](https://docs.datadoghq.com/help/).** + /api/v2/ddsql/query/tabular: + post: + description: |- + Submit a DDSQL statement and return either a `running` state with an opaque `query_id` + for the client to poll, or a `completed` state with the column-major result set inlined + when the query finishes quickly enough to be served synchronously. + operationId: ExecuteDdsqlTabularQuery + requestBody: + content: + application/json: + examples: + default: + value: + data: + attributes: + query: "SELECT cloud_provider, count(*) FROM dd.hosts group by cloud_provider" + row_limit: 1000 + time: + from_timestamp: 1736942400000 + to_timestamp: 1736946000000 + type: ddsql_query_request + schema: + $ref: "#/components/schemas/DdsqlTabularQueryRequest" + required: true + responses: + "200": + content: + application/json: + examples: + completed: + summary: Query finished synchronously + value: + data: + attributes: + columns: + - name: service + type: VARCHAR + values: + - web-store + - checkout + - name: count + type: BIGINT + values: + - 1024 + - 512 + state: completed + id: "00000000-0000-0000-0000-000000000000" + type: ddsql_query_response + meta: + elapsed: 318 + request_id: "req-7f3e7d2c-1a0b-4d3e-9b2a-3c4d5e6f7081" + default: + summary: Query finished synchronously + value: + data: + attributes: + columns: + - name: service + type: VARCHAR + values: + - web-store + - checkout + - name: count + type: BIGINT + values: + - 1024 + - 512 + state: completed + id: "00000000-0000-0000-0000-000000000000" + type: ddsql_query_response + meta: + elapsed: 318 + request_id: "req-7f3e7d2c-1a0b-4d3e-9b2a-3c4d5e6f7081" + running: + summary: Query still executing + value: + data: + attributes: + query_id: "eyJxdWVyeSI6ICJTRUxFQ1QgKiBGUk9NIGxvZ3MifQ==" + state: running + id: "00000000-0000-0000-0000-000000000000" + type: ddsql_query_response + meta: + elapsed: 42 + request_id: "req-7f3e7d2c-1a0b-4d3e-9b2a-3c4d5e6f7081" + schema: + $ref: "#/components/schemas/DdsqlTabularQueryResponse" + description: OK + "400": + content: + application/json: + schema: + $ref: "#/components/schemas/JSONAPIErrorResponse" + description: Bad Request + "403": + content: + application/json: + schema: + $ref: "#/components/schemas/JSONAPIErrorResponse" + description: Forbidden + "429": + $ref: "#/components/responses/TooManyRequestsResponse" + "500": + content: + application/json: + schema: + $ref: "#/components/schemas/JSONAPIErrorResponse" + description: Internal Server Error + summary: Execute a tabular DDSQL query + tags: + - DDSQL + x-unstable: |- + **Note**: This endpoint is in preview and is subject to change. + If you have any feedback, contact [Datadog support](https://docs.datadoghq.com/help/). + /api/v2/ddsql/query/tabular/fetch: + post: + description: |- + Poll a previously submitted DDSQL query for results. Pass the opaque `query_id` returned + by a prior `ExecuteDdsqlTabularQuery` (or by a prior `FetchDdsqlTabularQuery` that + returned `state: running`) and the server returns either a `running` state to poll again + or a `completed` state with the column-major result set inlined. + operationId: FetchDdsqlTabularQuery + requestBody: + content: + application/json: + examples: + default: + value: + data: + attributes: + query_id: "eyJxdWVyeSI6ICJTRUxFQ1QgKiBGUk9NIGxvZ3MifQ==" + type: ddsql_query_fetch_request + schema: + $ref: "#/components/schemas/DdsqlTabularQueryFetchRequest" + required: true + responses: + "200": + content: + application/json: + examples: + completed: + summary: Query finished + value: + data: + attributes: + columns: + - name: service + type: VARCHAR + values: + - web-store + - checkout + - name: count + type: BIGINT + values: + - 1024 + - 512 + state: completed + id: "00000000-0000-0000-0000-000000000000" + type: ddsql_query_response + meta: + elapsed: 87 + request_id: "req-7f3e7d2c-1a0b-4d3e-9b2a-3c4d5e6f7082" + default: + summary: Query finished + value: + data: + attributes: + columns: + - name: service + type: VARCHAR + values: + - web-store + - checkout + - name: count + type: BIGINT + values: + - 1024 + - 512 + state: completed + id: "00000000-0000-0000-0000-000000000000" + type: ddsql_query_response + meta: + elapsed: 87 + request_id: "req-7f3e7d2c-1a0b-4d3e-9b2a-3c4d5e6f7082" + running: + summary: Query still executing + value: + data: + attributes: + query_id: "eyJxdWVyeSI6ICJTRUxFQ1QgKiBGUk9NIGxvZ3MifQ==" + state: running + id: "00000000-0000-0000-0000-000000000000" + type: ddsql_query_response + meta: + elapsed: 12 + request_id: "req-7f3e7d2c-1a0b-4d3e-9b2a-3c4d5e6f7082" + schema: + $ref: "#/components/schemas/DdsqlTabularQueryResponse" + description: OK + "400": + content: + application/json: + schema: + $ref: "#/components/schemas/JSONAPIErrorResponse" + description: Bad Request + "403": + content: + application/json: + schema: + $ref: "#/components/schemas/JSONAPIErrorResponse" + description: Forbidden + "429": + $ref: "#/components/responses/TooManyRequestsResponse" + "500": + content: + application/json: + schema: + $ref: "#/components/schemas/JSONAPIErrorResponse" + description: Internal Server Error + summary: Fetch the result of a DDSQL query + tags: + - DDSQL + x-unstable: |- + **Note**: This endpoint is in preview and is subject to change. + If you have any feedback, contact [Datadog support](https://docs.datadoghq.com/help/). /api/v2/deletion/data/{product}: post: description: Creates a data deletion request by providing a query and a timeframe targeting the proper data. @@ -201794,6 +202270,12 @@ tags: Programmatic management of a customer's Datadog organization. Use this API to perform self-service organization lifecycle actions such as disabling the authenticated org. name: Customer Org + - description: |- + Execute DDSQL queries against the Datadog data catalog and poll for their results. + Queries are dispatched asynchronously: the initial request may return a `running` state with + a `query_id`, and clients poll the fetch endpoint until the response transitions to + `completed` with a column-major result set. + name: DDSQL - description: |- Search, send, or delete events for DORA Metrics to measure and improve your software delivery performance. See the [DORA Metrics page](https://docs.datadoghq.com/dora_metrics/) for more information. diff --git a/docs/datadog_api_client.v2.api.rst b/docs/datadog_api_client.v2.api.rst index 1ed9c22103..6a00bda396 100644 --- a/docs/datadog_api_client.v2.api.rst +++ b/docs/datadog_api_client.v2.api.rst @@ -305,6 +305,13 @@ datadog\_api\_client.v2.api.datasets\_api module :members: :show-inheritance: +datadog\_api\_client.v2.api.ddsql\_api module +--------------------------------------------- + +.. automodule:: datadog_api_client.v2.api.ddsql_api + :members: + :show-inheritance: + datadog\_api\_client.v2.api.deployment\_gates\_api module --------------------------------------------------------- diff --git a/docs/datadog_api_client.v2.model.rst b/docs/datadog_api_client.v2.model.rst index 8ecba11fd3..94679e180c 100644 --- a/docs/datadog_api_client.v2.model.rst +++ b/docs/datadog_api_client.v2.model.rst @@ -11771,6 +11771,118 @@ datadog\_api\_client.v2.model.datastore\_trigger\_wrapper module :members: :show-inheritance: +datadog\_api\_client.v2.model.ddsql\_tabular\_query\_column module +------------------------------------------------------------------ + +.. automodule:: datadog_api_client.v2.model.ddsql_tabular_query_column + :members: + :show-inheritance: + +datadog\_api\_client.v2.model.ddsql\_tabular\_query\_fetch\_request module +-------------------------------------------------------------------------- + +.. automodule:: datadog_api_client.v2.model.ddsql_tabular_query_fetch_request + :members: + :show-inheritance: + +datadog\_api\_client.v2.model.ddsql\_tabular\_query\_fetch\_request\_attributes module +-------------------------------------------------------------------------------------- + +.. automodule:: datadog_api_client.v2.model.ddsql_tabular_query_fetch_request_attributes + :members: + :show-inheritance: + +datadog\_api\_client.v2.model.ddsql\_tabular\_query\_fetch\_request\_data module +-------------------------------------------------------------------------------- + +.. automodule:: datadog_api_client.v2.model.ddsql_tabular_query_fetch_request_data + :members: + :show-inheritance: + +datadog\_api\_client.v2.model.ddsql\_tabular\_query\_fetch\_request\_type module +-------------------------------------------------------------------------------- + +.. automodule:: datadog_api_client.v2.model.ddsql_tabular_query_fetch_request_type + :members: + :show-inheritance: + +datadog\_api\_client.v2.model.ddsql\_tabular\_query\_request module +------------------------------------------------------------------- + +.. automodule:: datadog_api_client.v2.model.ddsql_tabular_query_request + :members: + :show-inheritance: + +datadog\_api\_client.v2.model.ddsql\_tabular\_query\_request\_attributes module +------------------------------------------------------------------------------- + +.. automodule:: datadog_api_client.v2.model.ddsql_tabular_query_request_attributes + :members: + :show-inheritance: + +datadog\_api\_client.v2.model.ddsql\_tabular\_query\_request\_data module +------------------------------------------------------------------------- + +.. automodule:: datadog_api_client.v2.model.ddsql_tabular_query_request_data + :members: + :show-inheritance: + +datadog\_api\_client.v2.model.ddsql\_tabular\_query\_request\_type module +------------------------------------------------------------------------- + +.. automodule:: datadog_api_client.v2.model.ddsql_tabular_query_request_type + :members: + :show-inheritance: + +datadog\_api\_client.v2.model.ddsql\_tabular\_query\_response module +-------------------------------------------------------------------- + +.. automodule:: datadog_api_client.v2.model.ddsql_tabular_query_response + :members: + :show-inheritance: + +datadog\_api\_client.v2.model.ddsql\_tabular\_query\_response\_attributes module +-------------------------------------------------------------------------------- + +.. automodule:: datadog_api_client.v2.model.ddsql_tabular_query_response_attributes + :members: + :show-inheritance: + +datadog\_api\_client.v2.model.ddsql\_tabular\_query\_response\_data module +-------------------------------------------------------------------------- + +.. automodule:: datadog_api_client.v2.model.ddsql_tabular_query_response_data + :members: + :show-inheritance: + +datadog\_api\_client.v2.model.ddsql\_tabular\_query\_response\_meta module +-------------------------------------------------------------------------- + +.. automodule:: datadog_api_client.v2.model.ddsql_tabular_query_response_meta + :members: + :show-inheritance: + +datadog\_api\_client.v2.model.ddsql\_tabular\_query\_response\_type module +-------------------------------------------------------------------------- + +.. automodule:: datadog_api_client.v2.model.ddsql_tabular_query_response_type + :members: + :show-inheritance: + +datadog\_api\_client.v2.model.ddsql\_tabular\_query\_state module +----------------------------------------------------------------- + +.. automodule:: datadog_api_client.v2.model.ddsql_tabular_query_state + :members: + :show-inheritance: + +datadog\_api\_client.v2.model.ddsql\_tabular\_query\_time\_window module +------------------------------------------------------------------------ + +.. automodule:: datadog_api_client.v2.model.ddsql_tabular_query_time_window + :members: + :show-inheritance: + datadog\_api\_client.v2.model.default\_rulesets\_per\_language\_data module --------------------------------------------------------------------------- diff --git a/examples/v2/ddsql/ExecuteDdsqlTabularQuery.py b/examples/v2/ddsql/ExecuteDdsqlTabularQuery.py new file mode 100644 index 0000000000..72d44ebe3f --- /dev/null +++ b/examples/v2/ddsql/ExecuteDdsqlTabularQuery.py @@ -0,0 +1,33 @@ +""" +Execute a tabular DDSQL query returns "OK" response +""" + +from datadog_api_client import ApiClient, Configuration +from datadog_api_client.v2.api.ddsql_api import DDSQLApi +from datadog_api_client.v2.model.ddsql_tabular_query_request import DdsqlTabularQueryRequest +from datadog_api_client.v2.model.ddsql_tabular_query_request_attributes import DdsqlTabularQueryRequestAttributes +from datadog_api_client.v2.model.ddsql_tabular_query_request_data import DdsqlTabularQueryRequestData +from datadog_api_client.v2.model.ddsql_tabular_query_request_type import DdsqlTabularQueryRequestType +from datadog_api_client.v2.model.ddsql_tabular_query_time_window import DdsqlTabularQueryTimeWindow + +body = DdsqlTabularQueryRequest( + data=DdsqlTabularQueryRequestData( + attributes=DdsqlTabularQueryRequestAttributes( + query="SELECT cloud_provider, count(*) FROM dd.hosts group by cloud_provider", + row_limit=1000, + time=DdsqlTabularQueryTimeWindow( + from_timestamp=1736942400000, + to_timestamp=1736946000000, + ), + ), + type=DdsqlTabularQueryRequestType.DDSQL_QUERY_REQUEST, + ), +) + +configuration = Configuration() +configuration.unstable_operations["execute_ddsql_tabular_query"] = True +with ApiClient(configuration) as api_client: + api_instance = DDSQLApi(api_client) + response = api_instance.execute_ddsql_tabular_query(body=body) + + print(response) diff --git a/examples/v2/ddsql/FetchDdsqlTabularQuery.py b/examples/v2/ddsql/FetchDdsqlTabularQuery.py new file mode 100644 index 0000000000..ad9b9752dc --- /dev/null +++ b/examples/v2/ddsql/FetchDdsqlTabularQuery.py @@ -0,0 +1,29 @@ +""" +Fetch the result of a DDSQL query returns "OK" response +""" + +from datadog_api_client import ApiClient, Configuration +from datadog_api_client.v2.api.ddsql_api import DDSQLApi +from datadog_api_client.v2.model.ddsql_tabular_query_fetch_request import DdsqlTabularQueryFetchRequest +from datadog_api_client.v2.model.ddsql_tabular_query_fetch_request_attributes import ( + DdsqlTabularQueryFetchRequestAttributes, +) +from datadog_api_client.v2.model.ddsql_tabular_query_fetch_request_data import DdsqlTabularQueryFetchRequestData +from datadog_api_client.v2.model.ddsql_tabular_query_fetch_request_type import DdsqlTabularQueryFetchRequestType + +body = DdsqlTabularQueryFetchRequest( + data=DdsqlTabularQueryFetchRequestData( + attributes=DdsqlTabularQueryFetchRequestAttributes( + query_id="eyJxdWVyeSI6ICJTRUxFQ1QgKiBGUk9NIGxvZ3MifQ==", + ), + type=DdsqlTabularQueryFetchRequestType.DDSQL_QUERY_FETCH_REQUEST, + ), +) + +configuration = Configuration() +configuration.unstable_operations["fetch_ddsql_tabular_query"] = True +with ApiClient(configuration) as api_client: + api_instance = DDSQLApi(api_client) + response = api_instance.fetch_ddsql_tabular_query(body=body) + + print(response) diff --git a/src/datadog_api_client/configuration.py b/src/datadog_api_client/configuration.py index 6999357559..653a99954b 100644 --- a/src/datadog_api_client/configuration.py +++ b/src/datadog_api_client/configuration.py @@ -525,6 +525,8 @@ def __init__( "v2.get_all_datasets": False, "v2.get_dataset": False, "v2.update_dataset": False, + "v2.execute_ddsql_tabular_query": False, + "v2.fetch_ddsql_tabular_query": False, "v2.cancel_data_deletion_request": False, "v2.create_data_deletion_request": False, "v2.get_data_deletion_requests": False, diff --git a/src/datadog_api_client/v2/api/ddsql_api.py b/src/datadog_api_client/v2/api/ddsql_api.py new file mode 100644 index 0000000000..64e94bdc04 --- /dev/null +++ b/src/datadog_api_client/v2/api/ddsql_api.py @@ -0,0 +1,103 @@ +# Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. +# This product includes software developed at Datadog (https://www.datadoghq.com/). +# Copyright 2019-Present Datadog, Inc. +from __future__ import annotations + +from typing import Any, Dict + +from datadog_api_client.api_client import ApiClient, Endpoint as _Endpoint +from datadog_api_client.configuration import Configuration +from datadog_api_client.v2.model.ddsql_tabular_query_response import DdsqlTabularQueryResponse +from datadog_api_client.v2.model.ddsql_tabular_query_request import DdsqlTabularQueryRequest +from datadog_api_client.v2.model.ddsql_tabular_query_fetch_request import DdsqlTabularQueryFetchRequest + + +class DDSQLApi: + """ + Execute DDSQL queries against the Datadog data catalog and poll for their results. + Queries are dispatched asynchronously: the initial request may return a ``running`` state with + a ``query_id`` , and clients poll the fetch endpoint until the response transitions to + ``completed`` with a column-major result set. + """ + + def __init__(self, api_client=None): + if api_client is None: + api_client = ApiClient(Configuration()) + self.api_client = api_client + + self._execute_ddsql_tabular_query_endpoint = _Endpoint( + settings={ + "response_type": (DdsqlTabularQueryResponse,), + "auth": ["apiKeyAuth", "appKeyAuth"], + "endpoint_path": "/api/v2/ddsql/query/tabular", + "operation_id": "execute_ddsql_tabular_query", + "http_method": "POST", + "version": "v2", + }, + params_map={ + "body": { + "required": True, + "openapi_types": (DdsqlTabularQueryRequest,), + "location": "body", + }, + }, + headers_map={"accept": ["application/json"], "content_type": ["application/json"]}, + api_client=api_client, + ) + + self._fetch_ddsql_tabular_query_endpoint = _Endpoint( + settings={ + "response_type": (DdsqlTabularQueryResponse,), + "auth": ["apiKeyAuth", "appKeyAuth"], + "endpoint_path": "/api/v2/ddsql/query/tabular/fetch", + "operation_id": "fetch_ddsql_tabular_query", + "http_method": "POST", + "version": "v2", + }, + params_map={ + "body": { + "required": True, + "openapi_types": (DdsqlTabularQueryFetchRequest,), + "location": "body", + }, + }, + headers_map={"accept": ["application/json"], "content_type": ["application/json"]}, + api_client=api_client, + ) + + def execute_ddsql_tabular_query( + self, + body: DdsqlTabularQueryRequest, + ) -> DdsqlTabularQueryResponse: + """Execute a tabular DDSQL query. + + Submit a DDSQL statement and return either a ``running`` state with an opaque ``query_id`` + for the client to poll, or a ``completed`` state with the column-major result set inlined + when the query finishes quickly enough to be served synchronously. + + :type body: DdsqlTabularQueryRequest + :rtype: DdsqlTabularQueryResponse + """ + kwargs: Dict[str, Any] = {} + kwargs["body"] = body + + return self._execute_ddsql_tabular_query_endpoint.call_with_http_info(**kwargs) + + def fetch_ddsql_tabular_query( + self, + body: DdsqlTabularQueryFetchRequest, + ) -> DdsqlTabularQueryResponse: + """Fetch the result of a DDSQL query. + + Poll a previously submitted DDSQL query for results. Pass the opaque ``query_id`` returned + by a prior ``ExecuteDdsqlTabularQuery`` (or by a prior ``FetchDdsqlTabularQuery`` that + returned ``state: running`` ) and the server returns either a ``running`` state to poll again + or a ``completed`` state with the column-major result set inlined. + + :type body: DdsqlTabularQueryFetchRequest + :rtype: DdsqlTabularQueryResponse + """ + kwargs: Dict[str, Any] = {} + kwargs["body"] = body + + return self._fetch_ddsql_tabular_query_endpoint.call_with_http_info(**kwargs) diff --git a/src/datadog_api_client/v2/apis/__init__.py b/src/datadog_api_client/v2/apis/__init__.py index 401f93f3bb..52e811b35a 100644 --- a/src/datadog_api_client/v2/apis/__init__.py +++ b/src/datadog_api_client/v2/apis/__init__.py @@ -34,6 +34,7 @@ from datadog_api_client.v2.api.container_images_api import ContainerImagesApi from datadog_api_client.v2.api.containers_api import ContainersApi from datadog_api_client.v2.api.customer_org_api import CustomerOrgApi +from datadog_api_client.v2.api.ddsql_api import DDSQLApi from datadog_api_client.v2.api.dora_metrics_api import DORAMetricsApi from datadog_api_client.v2.api.dashboard_lists_api import DashboardListsApi from datadog_api_client.v2.api.dashboard_secure_embed_api import DashboardSecureEmbedApi @@ -175,6 +176,7 @@ "ContainerImagesApi", "ContainersApi", "CustomerOrgApi", + "DDSQLApi", "DORAMetricsApi", "DashboardListsApi", "DashboardSecureEmbedApi", diff --git a/src/datadog_api_client/v2/model/ddsql_tabular_query_column.py b/src/datadog_api_client/v2/model/ddsql_tabular_query_column.py new file mode 100644 index 0000000000..ab778d989d --- /dev/null +++ b/src/datadog_api_client/v2/model/ddsql_tabular_query_column.py @@ -0,0 +1,56 @@ +# Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. +# This product includes software developed at Datadog (https://www.datadoghq.com/). +# Copyright 2019-Present Datadog, Inc. +from __future__ import annotations + +from typing import Any, List + +from datadog_api_client.model_utils import ( + ModelNormal, + cached_property, + date, + datetime, + none_type, + UUID, +) + + +class DdsqlTabularQueryColumn(ModelNormal): + @cached_property + def openapi_types(_): + return { + "name": (str,), + "type": (str,), + "values": ([bool, date, datetime, dict, float, int, list, str, UUID, none_type],), + } + + attribute_map = { + "name": "name", + "type": "type", + "values": "values", + } + + def __init__(self_, name: str, type: str, values: List[Any], **kwargs): + """ + A single column of a DDSQL tabular query result. + + :param name: Name of the column as projected by the SQL statement. + :type name: str + + :param type: DDSQL data type of the column's values, for example ``VARCHAR`` , ``BIGINT`` , + ``DECIMAL`` , ``BOOLEAN`` , ``TIMESTAMP`` , ``JSON`` , or an array variant such as + ``VARCHAR[]``. See the + `DDSQL data-types reference `_ + for the full, up-to-date list. + :type type: str + + :param values: Column values in row order. The element type matches the column's ``type`` ; + for example a ``VARCHAR`` column carries strings, a ``TIMESTAMP`` column carries + Unix-millisecond integers. ``null`` is allowed for missing values. + :type values: [bool, date, datetime, dict, float, int, list, str, UUID, none_type] + """ + super().__init__(kwargs) + + self_.name = name + self_.type = type + self_.values = values diff --git a/src/datadog_api_client/v2/model/ddsql_tabular_query_fetch_request.py b/src/datadog_api_client/v2/model/ddsql_tabular_query_fetch_request.py new file mode 100644 index 0000000000..d97f7eded2 --- /dev/null +++ b/src/datadog_api_client/v2/model/ddsql_tabular_query_fetch_request.py @@ -0,0 +1,40 @@ +# Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. +# This product includes software developed at Datadog (https://www.datadoghq.com/). +# Copyright 2019-Present Datadog, Inc. +from __future__ import annotations + +from typing import TYPE_CHECKING + +from datadog_api_client.model_utils import ( + ModelNormal, + cached_property, +) + + +if TYPE_CHECKING: + from datadog_api_client.v2.model.ddsql_tabular_query_fetch_request_data import DdsqlTabularQueryFetchRequestData + + +class DdsqlTabularQueryFetchRequest(ModelNormal): + @cached_property + def openapi_types(_): + from datadog_api_client.v2.model.ddsql_tabular_query_fetch_request_data import DdsqlTabularQueryFetchRequestData + + return { + "data": (DdsqlTabularQueryFetchRequestData,), + } + + attribute_map = { + "data": "data", + } + + def __init__(self_, data: DdsqlTabularQueryFetchRequestData, **kwargs): + """ + Wrapper for a DDSQL tabular query fetch request. + + :param data: JSON:API resource object for a DDSQL tabular query fetch request. + :type data: DdsqlTabularQueryFetchRequestData + """ + super().__init__(kwargs) + + self_.data = data diff --git a/src/datadog_api_client/v2/model/ddsql_tabular_query_fetch_request_attributes.py b/src/datadog_api_client/v2/model/ddsql_tabular_query_fetch_request_attributes.py new file mode 100644 index 0000000000..243f1ea6b6 --- /dev/null +++ b/src/datadog_api_client/v2/model/ddsql_tabular_query_fetch_request_attributes.py @@ -0,0 +1,34 @@ +# Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. +# This product includes software developed at Datadog (https://www.datadoghq.com/). +# Copyright 2019-Present Datadog, Inc. +from __future__ import annotations + + +from datadog_api_client.model_utils import ( + ModelNormal, + cached_property, +) + + +class DdsqlTabularQueryFetchRequestAttributes(ModelNormal): + @cached_property + def openapi_types(_): + return { + "query_id": (str,), + } + + attribute_map = { + "query_id": "query_id", + } + + def __init__(self_, query_id: str, **kwargs): + """ + Attributes describing which previously submitted DDSQL query to fetch. + + :param query_id: Opaque token returned by an earlier execute or fetch response that carried + ``state: running``. Identifies the query to poll for results. + :type query_id: str + """ + super().__init__(kwargs) + + self_.query_id = query_id diff --git a/src/datadog_api_client/v2/model/ddsql_tabular_query_fetch_request_data.py b/src/datadog_api_client/v2/model/ddsql_tabular_query_fetch_request_data.py new file mode 100644 index 0000000000..d9407d5acd --- /dev/null +++ b/src/datadog_api_client/v2/model/ddsql_tabular_query_fetch_request_data.py @@ -0,0 +1,54 @@ +# Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. +# This product includes software developed at Datadog (https://www.datadoghq.com/). +# Copyright 2019-Present Datadog, Inc. +from __future__ import annotations + +from typing import TYPE_CHECKING + +from datadog_api_client.model_utils import ( + ModelNormal, + cached_property, +) + + +if TYPE_CHECKING: + from datadog_api_client.v2.model.ddsql_tabular_query_fetch_request_attributes import ( + DdsqlTabularQueryFetchRequestAttributes, + ) + from datadog_api_client.v2.model.ddsql_tabular_query_fetch_request_type import DdsqlTabularQueryFetchRequestType + + +class DdsqlTabularQueryFetchRequestData(ModelNormal): + @cached_property + def openapi_types(_): + from datadog_api_client.v2.model.ddsql_tabular_query_fetch_request_attributes import ( + DdsqlTabularQueryFetchRequestAttributes, + ) + from datadog_api_client.v2.model.ddsql_tabular_query_fetch_request_type import DdsqlTabularQueryFetchRequestType + + return { + "attributes": (DdsqlTabularQueryFetchRequestAttributes,), + "type": (DdsqlTabularQueryFetchRequestType,), + } + + attribute_map = { + "attributes": "attributes", + "type": "type", + } + + def __init__( + self_, attributes: DdsqlTabularQueryFetchRequestAttributes, type: DdsqlTabularQueryFetchRequestType, **kwargs + ): + """ + JSON:API resource object for a DDSQL tabular query fetch request. + + :param attributes: Attributes describing which previously submitted DDSQL query to fetch. + :type attributes: DdsqlTabularQueryFetchRequestAttributes + + :param type: JSON:API resource type for a DDSQL tabular query fetch request. + :type type: DdsqlTabularQueryFetchRequestType + """ + super().__init__(kwargs) + + self_.attributes = attributes + self_.type = type diff --git a/src/datadog_api_client/v2/model/ddsql_tabular_query_fetch_request_type.py b/src/datadog_api_client/v2/model/ddsql_tabular_query_fetch_request_type.py new file mode 100644 index 0000000000..da33fee932 --- /dev/null +++ b/src/datadog_api_client/v2/model/ddsql_tabular_query_fetch_request_type.py @@ -0,0 +1,37 @@ +# Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. +# This product includes software developed at Datadog (https://www.datadoghq.com/). +# Copyright 2019-Present Datadog, Inc. +from __future__ import annotations + + +from datadog_api_client.model_utils import ( + ModelSimple, + cached_property, +) + +from typing import ClassVar + + +class DdsqlTabularQueryFetchRequestType(ModelSimple): + """ + JSON:API resource type for a DDSQL tabular query fetch request. + + :param value: If omitted defaults to "ddsql_query_fetch_request". Must be one of ["ddsql_query_fetch_request"]. + :type value: str + """ + + allowed_values = { + "ddsql_query_fetch_request", + } + DDSQL_QUERY_FETCH_REQUEST: ClassVar["DdsqlTabularQueryFetchRequestType"] + + @cached_property + def openapi_types(_): + return { + "value": (str,), + } + + +DdsqlTabularQueryFetchRequestType.DDSQL_QUERY_FETCH_REQUEST = DdsqlTabularQueryFetchRequestType( + "ddsql_query_fetch_request" +) diff --git a/src/datadog_api_client/v2/model/ddsql_tabular_query_request.py b/src/datadog_api_client/v2/model/ddsql_tabular_query_request.py new file mode 100644 index 0000000000..1a6e1d0482 --- /dev/null +++ b/src/datadog_api_client/v2/model/ddsql_tabular_query_request.py @@ -0,0 +1,40 @@ +# Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. +# This product includes software developed at Datadog (https://www.datadoghq.com/). +# Copyright 2019-Present Datadog, Inc. +from __future__ import annotations + +from typing import TYPE_CHECKING + +from datadog_api_client.model_utils import ( + ModelNormal, + cached_property, +) + + +if TYPE_CHECKING: + from datadog_api_client.v2.model.ddsql_tabular_query_request_data import DdsqlTabularQueryRequestData + + +class DdsqlTabularQueryRequest(ModelNormal): + @cached_property + def openapi_types(_): + from datadog_api_client.v2.model.ddsql_tabular_query_request_data import DdsqlTabularQueryRequestData + + return { + "data": (DdsqlTabularQueryRequestData,), + } + + attribute_map = { + "data": "data", + } + + def __init__(self_, data: DdsqlTabularQueryRequestData, **kwargs): + """ + Wrapper for a DDSQL tabular query execution request. + + :param data: JSON:API resource object for a DDSQL tabular query execution request. + :type data: DdsqlTabularQueryRequestData + """ + super().__init__(kwargs) + + self_.data = data diff --git a/src/datadog_api_client/v2/model/ddsql_tabular_query_request_attributes.py b/src/datadog_api_client/v2/model/ddsql_tabular_query_request_attributes.py new file mode 100644 index 0000000000..915a81b76f --- /dev/null +++ b/src/datadog_api_client/v2/model/ddsql_tabular_query_request_attributes.py @@ -0,0 +1,69 @@ +# Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. +# This product includes software developed at Datadog (https://www.datadoghq.com/). +# Copyright 2019-Present Datadog, Inc. +from __future__ import annotations + +from typing import Union, TYPE_CHECKING + +from datadog_api_client.model_utils import ( + ModelNormal, + cached_property, + unset, + UnsetType, +) + + +if TYPE_CHECKING: + from datadog_api_client.v2.model.ddsql_tabular_query_time_window import DdsqlTabularQueryTimeWindow + + +class DdsqlTabularQueryRequestAttributes(ModelNormal): + validations = { + "row_limit": { + "inclusive_maximum": 10000, + "inclusive_minimum": 1, + }, + } + + @cached_property + def openapi_types(_): + from datadog_api_client.v2.model.ddsql_tabular_query_time_window import DdsqlTabularQueryTimeWindow + + return { + "query": (str,), + "row_limit": (int,), + "time": (DdsqlTabularQueryTimeWindow,), + } + + attribute_map = { + "query": "query", + "row_limit": "row_limit", + "time": "time", + } + + def __init__( + self_, query: str, time: DdsqlTabularQueryTimeWindow, row_limit: Union[int, UnsetType] = unset, **kwargs + ): + """ + Attributes describing the DDSQL query to execute. + + :param query: The DDSQL statement to execute. DDSQL is Datadog's SQL dialect, which is a subset + of PostgreSQL, scoped to Datadog data sources. + :type query: str + + :param row_limit: Cap on the number of rows returned. Defaults to 5,000 when omitted. Must be + between 1 and 10,000 inclusive; values outside this range are rejected with 400. + :type row_limit: int, optional + + :param time: Time window scoping the underlying data sources, expressed in Unix milliseconds + since the epoch. Inclusive on ``from_timestamp`` , exclusive on ``to_timestamp``. + Results from static tables (for example, ``dd.hosts`` ) are not affected by the + time window, but the field must still be provided. + :type time: DdsqlTabularQueryTimeWindow + """ + if row_limit is not unset: + kwargs["row_limit"] = row_limit + super().__init__(kwargs) + + self_.query = query + self_.time = time diff --git a/src/datadog_api_client/v2/model/ddsql_tabular_query_request_data.py b/src/datadog_api_client/v2/model/ddsql_tabular_query_request_data.py new file mode 100644 index 0000000000..411afb5e8e --- /dev/null +++ b/src/datadog_api_client/v2/model/ddsql_tabular_query_request_data.py @@ -0,0 +1,50 @@ +# Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. +# This product includes software developed at Datadog (https://www.datadoghq.com/). +# Copyright 2019-Present Datadog, Inc. +from __future__ import annotations + +from typing import TYPE_CHECKING + +from datadog_api_client.model_utils import ( + ModelNormal, + cached_property, +) + + +if TYPE_CHECKING: + from datadog_api_client.v2.model.ddsql_tabular_query_request_attributes import DdsqlTabularQueryRequestAttributes + from datadog_api_client.v2.model.ddsql_tabular_query_request_type import DdsqlTabularQueryRequestType + + +class DdsqlTabularQueryRequestData(ModelNormal): + @cached_property + def openapi_types(_): + from datadog_api_client.v2.model.ddsql_tabular_query_request_attributes import ( + DdsqlTabularQueryRequestAttributes, + ) + from datadog_api_client.v2.model.ddsql_tabular_query_request_type import DdsqlTabularQueryRequestType + + return { + "attributes": (DdsqlTabularQueryRequestAttributes,), + "type": (DdsqlTabularQueryRequestType,), + } + + attribute_map = { + "attributes": "attributes", + "type": "type", + } + + def __init__(self_, attributes: DdsqlTabularQueryRequestAttributes, type: DdsqlTabularQueryRequestType, **kwargs): + """ + JSON:API resource object for a DDSQL tabular query execution request. + + :param attributes: Attributes describing the DDSQL query to execute. + :type attributes: DdsqlTabularQueryRequestAttributes + + :param type: JSON:API resource type for a DDSQL tabular query request. + :type type: DdsqlTabularQueryRequestType + """ + super().__init__(kwargs) + + self_.attributes = attributes + self_.type = type diff --git a/src/datadog_api_client/v2/model/ddsql_tabular_query_request_type.py b/src/datadog_api_client/v2/model/ddsql_tabular_query_request_type.py new file mode 100644 index 0000000000..be3cae6672 --- /dev/null +++ b/src/datadog_api_client/v2/model/ddsql_tabular_query_request_type.py @@ -0,0 +1,35 @@ +# Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. +# This product includes software developed at Datadog (https://www.datadoghq.com/). +# Copyright 2019-Present Datadog, Inc. +from __future__ import annotations + + +from datadog_api_client.model_utils import ( + ModelSimple, + cached_property, +) + +from typing import ClassVar + + +class DdsqlTabularQueryRequestType(ModelSimple): + """ + JSON:API resource type for a DDSQL tabular query request. + + :param value: If omitted defaults to "ddsql_query_request". Must be one of ["ddsql_query_request"]. + :type value: str + """ + + allowed_values = { + "ddsql_query_request", + } + DDSQL_QUERY_REQUEST: ClassVar["DdsqlTabularQueryRequestType"] + + @cached_property + def openapi_types(_): + return { + "value": (str,), + } + + +DdsqlTabularQueryRequestType.DDSQL_QUERY_REQUEST = DdsqlTabularQueryRequestType("ddsql_query_request") diff --git a/src/datadog_api_client/v2/model/ddsql_tabular_query_response.py b/src/datadog_api_client/v2/model/ddsql_tabular_query_response.py new file mode 100644 index 0000000000..7973dd07b8 --- /dev/null +++ b/src/datadog_api_client/v2/model/ddsql_tabular_query_response.py @@ -0,0 +1,51 @@ +# Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. +# This product includes software developed at Datadog (https://www.datadoghq.com/). +# Copyright 2019-Present Datadog, Inc. +from __future__ import annotations + +from typing import TYPE_CHECKING + +from datadog_api_client.model_utils import ( + ModelNormal, + cached_property, +) + + +if TYPE_CHECKING: + from datadog_api_client.v2.model.ddsql_tabular_query_response_data import DdsqlTabularQueryResponseData + from datadog_api_client.v2.model.ddsql_tabular_query_response_meta import DdsqlTabularQueryResponseMeta + + +class DdsqlTabularQueryResponse(ModelNormal): + @cached_property + def openapi_types(_): + from datadog_api_client.v2.model.ddsql_tabular_query_response_data import DdsqlTabularQueryResponseData + from datadog_api_client.v2.model.ddsql_tabular_query_response_meta import DdsqlTabularQueryResponseMeta + + return { + "data": (DdsqlTabularQueryResponseData,), + "meta": (DdsqlTabularQueryResponseMeta,), + } + + attribute_map = { + "data": "data", + "meta": "meta", + } + + def __init__(self_, data: DdsqlTabularQueryResponseData, meta: DdsqlTabularQueryResponseMeta, **kwargs): + """ + Response envelope for both the execute and fetch DDSQL tabular query endpoints. + Carries the JSON:API primary resource and a top-level ``meta`` block with + request-scoped observability handles. + + :param data: JSON:API resource object for a DDSQL tabular query response. + :type data: DdsqlTabularQueryResponseData + + :param meta: Top-level JSON:API meta block accompanying every DDSQL tabular query response. + Carries standard observability handles for client-side correlation. + :type meta: DdsqlTabularQueryResponseMeta + """ + super().__init__(kwargs) + + self_.data = data + self_.meta = meta diff --git a/src/datadog_api_client/v2/model/ddsql_tabular_query_response_attributes.py b/src/datadog_api_client/v2/model/ddsql_tabular_query_response_attributes.py new file mode 100644 index 0000000000..7f383aa3e0 --- /dev/null +++ b/src/datadog_api_client/v2/model/ddsql_tabular_query_response_attributes.py @@ -0,0 +1,78 @@ +# Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. +# This product includes software developed at Datadog (https://www.datadoghq.com/). +# Copyright 2019-Present Datadog, Inc. +from __future__ import annotations + +from typing import List, Union, TYPE_CHECKING + +from datadog_api_client.model_utils import ( + ModelNormal, + cached_property, + unset, + UnsetType, +) + + +if TYPE_CHECKING: + from datadog_api_client.v2.model.ddsql_tabular_query_column import DdsqlTabularQueryColumn + from datadog_api_client.v2.model.ddsql_tabular_query_state import DdsqlTabularQueryState + + +class DdsqlTabularQueryResponseAttributes(ModelNormal): + @cached_property + def openapi_types(_): + from datadog_api_client.v2.model.ddsql_tabular_query_column import DdsqlTabularQueryColumn + from datadog_api_client.v2.model.ddsql_tabular_query_state import DdsqlTabularQueryState + + return { + "columns": ([DdsqlTabularQueryColumn],), + "query_id": (str,), + "state": (DdsqlTabularQueryState,), + "warnings": ([str],), + } + + attribute_map = { + "columns": "columns", + "query_id": "query_id", + "state": "state", + "warnings": "warnings", + } + + def __init__( + self_, + state: DdsqlTabularQueryState, + columns: Union[List[DdsqlTabularQueryColumn], UnsetType] = unset, + query_id: Union[str, UnsetType] = unset, + warnings: Union[List[str], UnsetType] = unset, + **kwargs, + ): + """ + Attributes of a DDSQL tabular query response. ``query_id`` is set when + ``state`` is ``running`` ; ``columns`` is set when ``state`` is ``completed``. + + :param columns: Column-major result set. Each element carries one column's name, type, and values, + with one value per row of the result. Set when ``state`` is ``completed``. + :type columns: [DdsqlTabularQueryColumn], optional + + :param query_id: Opaque token to pass to the fetch endpoint to poll for results. + Set when ``state`` is ``running`` and absent when ``state`` is ``completed``. + :type query_id: str, optional + + :param state: Lifecycle state of a DDSQL tabular query response. + ``running`` means the query is still executing and the client should poll + the fetch endpoint with the returned ``query_id``. ``completed`` means the + result set is inlined in ``columns`` and no further polling is required. + :type state: DdsqlTabularQueryState + + :param warnings: Non-fatal messages emitted by the query engine while serving this response. + :type warnings: [str], optional + """ + if columns is not unset: + kwargs["columns"] = columns + if query_id is not unset: + kwargs["query_id"] = query_id + if warnings is not unset: + kwargs["warnings"] = warnings + super().__init__(kwargs) + + self_.state = state diff --git a/src/datadog_api_client/v2/model/ddsql_tabular_query_response_data.py b/src/datadog_api_client/v2/model/ddsql_tabular_query_response_data.py new file mode 100644 index 0000000000..ab5381582f --- /dev/null +++ b/src/datadog_api_client/v2/model/ddsql_tabular_query_response_data.py @@ -0,0 +1,59 @@ +# Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. +# This product includes software developed at Datadog (https://www.datadoghq.com/). +# Copyright 2019-Present Datadog, Inc. +from __future__ import annotations + +from typing import TYPE_CHECKING + +from datadog_api_client.model_utils import ( + ModelNormal, + cached_property, +) + + +if TYPE_CHECKING: + from datadog_api_client.v2.model.ddsql_tabular_query_response_attributes import DdsqlTabularQueryResponseAttributes + from datadog_api_client.v2.model.ddsql_tabular_query_response_type import DdsqlTabularQueryResponseType + + +class DdsqlTabularQueryResponseData(ModelNormal): + @cached_property + def openapi_types(_): + from datadog_api_client.v2.model.ddsql_tabular_query_response_attributes import ( + DdsqlTabularQueryResponseAttributes, + ) + from datadog_api_client.v2.model.ddsql_tabular_query_response_type import DdsqlTabularQueryResponseType + + return { + "attributes": (DdsqlTabularQueryResponseAttributes,), + "id": (str,), + "type": (DdsqlTabularQueryResponseType,), + } + + attribute_map = { + "attributes": "attributes", + "id": "id", + "type": "type", + } + + def __init__( + self_, attributes: DdsqlTabularQueryResponseAttributes, id: str, type: DdsqlTabularQueryResponseType, **kwargs + ): + """ + JSON:API resource object for a DDSQL tabular query response. + + :param attributes: Attributes of a DDSQL tabular query response. ``query_id`` is set when + ``state`` is ``running`` ; ``columns`` is set when ``state`` is ``completed``. + :type attributes: DdsqlTabularQueryResponseAttributes + + :param id: Stable identifier for the query response resource. + :type id: str + + :param type: JSON:API resource type for a DDSQL tabular query response. + :type type: DdsqlTabularQueryResponseType + """ + super().__init__(kwargs) + + self_.attributes = attributes + self_.id = id + self_.type = type diff --git a/src/datadog_api_client/v2/model/ddsql_tabular_query_response_meta.py b/src/datadog_api_client/v2/model/ddsql_tabular_query_response_meta.py new file mode 100644 index 0000000000..cce9e944ba --- /dev/null +++ b/src/datadog_api_client/v2/model/ddsql_tabular_query_response_meta.py @@ -0,0 +1,41 @@ +# Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. +# This product includes software developed at Datadog (https://www.datadoghq.com/). +# Copyright 2019-Present Datadog, Inc. +from __future__ import annotations + + +from datadog_api_client.model_utils import ( + ModelNormal, + cached_property, +) + + +class DdsqlTabularQueryResponseMeta(ModelNormal): + @cached_property + def openapi_types(_): + return { + "elapsed": (int,), + "request_id": (str,), + } + + attribute_map = { + "elapsed": "elapsed", + "request_id": "request_id", + } + + def __init__(self_, elapsed: int, request_id: str, **kwargs): + """ + Top-level JSON:API meta block accompanying every DDSQL tabular query response. + Carries standard observability handles for client-side correlation. + + :param elapsed: Server-side time spent serving this request, in milliseconds. + :type elapsed: int + + :param request_id: Echo of the ``DD-Request-ID`` header assigned by Datadog's edge to this request, + for support correlation. + :type request_id: str + """ + super().__init__(kwargs) + + self_.elapsed = elapsed + self_.request_id = request_id diff --git a/src/datadog_api_client/v2/model/ddsql_tabular_query_response_type.py b/src/datadog_api_client/v2/model/ddsql_tabular_query_response_type.py new file mode 100644 index 0000000000..c0c83ee476 --- /dev/null +++ b/src/datadog_api_client/v2/model/ddsql_tabular_query_response_type.py @@ -0,0 +1,35 @@ +# Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. +# This product includes software developed at Datadog (https://www.datadoghq.com/). +# Copyright 2019-Present Datadog, Inc. +from __future__ import annotations + + +from datadog_api_client.model_utils import ( + ModelSimple, + cached_property, +) + +from typing import ClassVar + + +class DdsqlTabularQueryResponseType(ModelSimple): + """ + JSON:API resource type for a DDSQL tabular query response. + + :param value: If omitted defaults to "ddsql_query_response". Must be one of ["ddsql_query_response"]. + :type value: str + """ + + allowed_values = { + "ddsql_query_response", + } + DDSQL_QUERY_RESPONSE: ClassVar["DdsqlTabularQueryResponseType"] + + @cached_property + def openapi_types(_): + return { + "value": (str,), + } + + +DdsqlTabularQueryResponseType.DDSQL_QUERY_RESPONSE = DdsqlTabularQueryResponseType("ddsql_query_response") diff --git a/src/datadog_api_client/v2/model/ddsql_tabular_query_state.py b/src/datadog_api_client/v2/model/ddsql_tabular_query_state.py new file mode 100644 index 0000000000..fde332335e --- /dev/null +++ b/src/datadog_api_client/v2/model/ddsql_tabular_query_state.py @@ -0,0 +1,41 @@ +# Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. +# This product includes software developed at Datadog (https://www.datadoghq.com/). +# Copyright 2019-Present Datadog, Inc. +from __future__ import annotations + + +from datadog_api_client.model_utils import ( + ModelSimple, + cached_property, +) + +from typing import ClassVar + + +class DdsqlTabularQueryState(ModelSimple): + """ + Lifecycle state of a DDSQL tabular query response. + `running` means the query is still executing and the client should poll + the fetch endpoint with the returned `query_id`. `completed` means the + result set is inlined in `columns` and no further polling is required. + + :param value: Must be one of ["running", "completed"]. + :type value: str + """ + + allowed_values = { + "running", + "completed", + } + RUNNING: ClassVar["DdsqlTabularQueryState"] + COMPLETED: ClassVar["DdsqlTabularQueryState"] + + @cached_property + def openapi_types(_): + return { + "value": (str,), + } + + +DdsqlTabularQueryState.RUNNING = DdsqlTabularQueryState("running") +DdsqlTabularQueryState.COMPLETED = DdsqlTabularQueryState("completed") diff --git a/src/datadog_api_client/v2/model/ddsql_tabular_query_time_window.py b/src/datadog_api_client/v2/model/ddsql_tabular_query_time_window.py new file mode 100644 index 0000000000..f803849083 --- /dev/null +++ b/src/datadog_api_client/v2/model/ddsql_tabular_query_time_window.py @@ -0,0 +1,42 @@ +# Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. +# This product includes software developed at Datadog (https://www.datadoghq.com/). +# Copyright 2019-Present Datadog, Inc. +from __future__ import annotations + + +from datadog_api_client.model_utils import ( + ModelNormal, + cached_property, +) + + +class DdsqlTabularQueryTimeWindow(ModelNormal): + @cached_property + def openapi_types(_): + return { + "from_timestamp": (int,), + "to_timestamp": (int,), + } + + attribute_map = { + "from_timestamp": "from_timestamp", + "to_timestamp": "to_timestamp", + } + + def __init__(self_, from_timestamp: int, to_timestamp: int, **kwargs): + """ + Time window scoping the underlying data sources, expressed in Unix milliseconds + since the epoch. Inclusive on ``from_timestamp`` , exclusive on ``to_timestamp``. + Results from static tables (for example, ``dd.hosts`` ) are not affected by the + time window, but the field must still be provided. + + :param from_timestamp: Start of the query window (inclusive), in Unix milliseconds since the epoch. + :type from_timestamp: int + + :param to_timestamp: End of the query window (exclusive), in Unix milliseconds since the epoch. + :type to_timestamp: int + """ + super().__init__(kwargs) + + self_.from_timestamp = from_timestamp + self_.to_timestamp = to_timestamp diff --git a/src/datadog_api_client/v2/models/__init__.py b/src/datadog_api_client/v2/models/__init__.py index 7db779d266..ba4df809e1 100644 --- a/src/datadog_api_client/v2/models/__init__.py +++ b/src/datadog_api_client/v2/models/__init__.py @@ -2259,6 +2259,24 @@ from datadog_api_client.v2.model.datastore_primary_key_generation_strategy import DatastorePrimaryKeyGenerationStrategy from datadog_api_client.v2.model.datastore_trigger import DatastoreTrigger from datadog_api_client.v2.model.datastore_trigger_wrapper import DatastoreTriggerWrapper +from datadog_api_client.v2.model.ddsql_tabular_query_column import DdsqlTabularQueryColumn +from datadog_api_client.v2.model.ddsql_tabular_query_fetch_request import DdsqlTabularQueryFetchRequest +from datadog_api_client.v2.model.ddsql_tabular_query_fetch_request_attributes import ( + DdsqlTabularQueryFetchRequestAttributes, +) +from datadog_api_client.v2.model.ddsql_tabular_query_fetch_request_data import DdsqlTabularQueryFetchRequestData +from datadog_api_client.v2.model.ddsql_tabular_query_fetch_request_type import DdsqlTabularQueryFetchRequestType +from datadog_api_client.v2.model.ddsql_tabular_query_request import DdsqlTabularQueryRequest +from datadog_api_client.v2.model.ddsql_tabular_query_request_attributes import DdsqlTabularQueryRequestAttributes +from datadog_api_client.v2.model.ddsql_tabular_query_request_data import DdsqlTabularQueryRequestData +from datadog_api_client.v2.model.ddsql_tabular_query_request_type import DdsqlTabularQueryRequestType +from datadog_api_client.v2.model.ddsql_tabular_query_response import DdsqlTabularQueryResponse +from datadog_api_client.v2.model.ddsql_tabular_query_response_attributes import DdsqlTabularQueryResponseAttributes +from datadog_api_client.v2.model.ddsql_tabular_query_response_data import DdsqlTabularQueryResponseData +from datadog_api_client.v2.model.ddsql_tabular_query_response_meta import DdsqlTabularQueryResponseMeta +from datadog_api_client.v2.model.ddsql_tabular_query_response_type import DdsqlTabularQueryResponseType +from datadog_api_client.v2.model.ddsql_tabular_query_state import DdsqlTabularQueryState +from datadog_api_client.v2.model.ddsql_tabular_query_time_window import DdsqlTabularQueryTimeWindow from datadog_api_client.v2.model.default_rulesets_per_language_data import DefaultRulesetsPerLanguageData from datadog_api_client.v2.model.default_rulesets_per_language_data_attributes import ( DefaultRulesetsPerLanguageDataAttributes, @@ -11593,6 +11611,22 @@ "DatastorePrimaryKeyGenerationStrategy", "DatastoreTrigger", "DatastoreTriggerWrapper", + "DdsqlTabularQueryColumn", + "DdsqlTabularQueryFetchRequest", + "DdsqlTabularQueryFetchRequestAttributes", + "DdsqlTabularQueryFetchRequestData", + "DdsqlTabularQueryFetchRequestType", + "DdsqlTabularQueryRequest", + "DdsqlTabularQueryRequestAttributes", + "DdsqlTabularQueryRequestData", + "DdsqlTabularQueryRequestType", + "DdsqlTabularQueryResponse", + "DdsqlTabularQueryResponseAttributes", + "DdsqlTabularQueryResponseData", + "DdsqlTabularQueryResponseMeta", + "DdsqlTabularQueryResponseType", + "DdsqlTabularQueryState", + "DdsqlTabularQueryTimeWindow", "DefaultRulesetsPerLanguageData", "DefaultRulesetsPerLanguageDataAttributes", "DefaultRulesetsPerLanguageDataType", diff --git a/tests/v2/features/ddsql.feature b/tests/v2/features/ddsql.feature new file mode 100644 index 0000000000..69d646eb2a --- /dev/null +++ b/tests/v2/features/ddsql.feature @@ -0,0 +1,44 @@ +@endpoint(ddsql) @endpoint(ddsql-v2) +Feature: DDSQL + Execute DDSQL queries against the Datadog data catalog and poll for their + results. Queries are dispatched asynchronously: the initial request may + return a `running` state with a `query_id`, and clients poll the fetch + endpoint until the response transitions to `completed` with a column-major + result set. + + Background: + Given a valid "apiKeyAuth" key in the system + And a valid "appKeyAuth" key in the system + And an instance of "DDSQL" API + + @generated @skip @team:DataDog/query-apis + Scenario: Execute a tabular DDSQL query returns "Bad Request" response + Given operation "ExecuteDdsqlTabularQuery" enabled + And new "ExecuteDdsqlTabularQuery" request + And body with value {"data": {"attributes": {"query": "SELECT cloud_provider, count(*) FROM dd.hosts group by cloud_provider", "row_limit": 1000, "time": {"from_timestamp": 1736942400000, "to_timestamp": 1736946000000}}, "type": "ddsql_query_request"}} + When the request is sent + Then the response status is 400 Bad Request + + @generated @skip @team:DataDog/query-apis + Scenario: Execute a tabular DDSQL query returns "OK" response + Given operation "ExecuteDdsqlTabularQuery" enabled + And new "ExecuteDdsqlTabularQuery" request + And body with value {"data": {"attributes": {"query": "SELECT cloud_provider, count(*) FROM dd.hosts group by cloud_provider", "row_limit": 1000, "time": {"from_timestamp": 1736942400000, "to_timestamp": 1736946000000}}, "type": "ddsql_query_request"}} + When the request is sent + Then the response status is 200 OK + + @generated @skip @team:DataDog/query-apis + Scenario: Fetch the result of a DDSQL query returns "Bad Request" response + Given operation "FetchDdsqlTabularQuery" enabled + And new "FetchDdsqlTabularQuery" request + And body with value {"data": {"attributes": {"query_id": "eyJxdWVyeSI6ICJTRUxFQ1QgKiBGUk9NIGxvZ3MifQ=="}, "type": "ddsql_query_fetch_request"}} + When the request is sent + Then the response status is 400 Bad Request + + @generated @skip @team:DataDog/query-apis + Scenario: Fetch the result of a DDSQL query returns "OK" response + Given operation "FetchDdsqlTabularQuery" enabled + And new "FetchDdsqlTabularQuery" request + And body with value {"data": {"attributes": {"query_id": "eyJxdWVyeSI6ICJTRUxFQ1QgKiBGUk9NIGxvZ3MifQ=="}, "type": "ddsql_query_fetch_request"}} + When the request is sent + Then the response status is 200 OK diff --git a/tests/v2/features/undo.json b/tests/v2/features/undo.json index f7316aecda..57e16ea1a6 100644 --- a/tests/v2/features/undo.json +++ b/tests/v2/features/undo.json @@ -2285,6 +2285,18 @@ "type": "idempotent" } }, + "ExecuteDdsqlTabularQuery": { + "tag": "DDSQL", + "undo": { + "type": "idempotent" + } + }, + "FetchDdsqlTabularQuery": { + "tag": "DDSQL", + "undo": { + "type": "safe" + } + }, "CreateDataDeletionRequest": { "tag": "Data Deletion", "undo": {