From 24c342c217181f382b11a1b42effb151a2c46f36 Mon Sep 17 00:00:00 2001 From: "ci.datadog-api-spec" Date: Tue, 21 Jul 2026 09:42:54 +0000 Subject: [PATCH] Regenerate client from commit 86a61b6 of spec repo --- .generator/schemas/v2/openapi.yaml | 482 ++++++++++++++++++ LICENSE-3rdparty.csv | 2 +- src/datadog/configuration.rs | 2 + src/datadogV2/api/api_ddsql.rs | 444 ++++++++++++++++ src/datadogV2/api/mod.rs | 1 + src/datadogV2/mod.rs | 1 + src/datadogV2/model/mod.rs | 32 ++ .../model/model_ddsql_tabular_query_column.rs | 122 +++++ ...model_ddsql_tabular_query_fetch_request.rs | 95 ++++ ..._tabular_query_fetch_request_attributes.rs | 93 ++++ ..._ddsql_tabular_query_fetch_request_data.rs | 116 +++++ ..._ddsql_tabular_query_fetch_request_type.rs | 48 ++ .../model_ddsql_tabular_query_request.rs | 94 ++++ ..._ddsql_tabular_query_request_attributes.rs | 127 +++++ .../model_ddsql_tabular_query_request_data.rs | 115 +++++ .../model_ddsql_tabular_query_request_type.rs | 48 ++ .../model_ddsql_tabular_query_response.rs | 108 ++++ ...ddsql_tabular_query_response_attributes.rs | 160 ++++++ ...model_ddsql_tabular_query_response_data.rs | 128 +++++ ...model_ddsql_tabular_query_response_meta.rs | 104 ++++ ...model_ddsql_tabular_query_response_type.rs | 48 ++ .../model/model_ddsql_tabular_query_state.rs | 51 ++ .../model_ddsql_tabular_query_time_window.rs | 109 ++++ tests/scenarios/function_mappings.rs | 72 +++ 24 files changed, 2601 insertions(+), 1 deletion(-) create mode 100644 src/datadogV2/api/api_ddsql.rs create mode 100644 src/datadogV2/model/model_ddsql_tabular_query_column.rs create mode 100644 src/datadogV2/model/model_ddsql_tabular_query_fetch_request.rs create mode 100644 src/datadogV2/model/model_ddsql_tabular_query_fetch_request_attributes.rs create mode 100644 src/datadogV2/model/model_ddsql_tabular_query_fetch_request_data.rs create mode 100644 src/datadogV2/model/model_ddsql_tabular_query_fetch_request_type.rs create mode 100644 src/datadogV2/model/model_ddsql_tabular_query_request.rs create mode 100644 src/datadogV2/model/model_ddsql_tabular_query_request_attributes.rs create mode 100644 src/datadogV2/model/model_ddsql_tabular_query_request_data.rs create mode 100644 src/datadogV2/model/model_ddsql_tabular_query_request_type.rs create mode 100644 src/datadogV2/model/model_ddsql_tabular_query_response.rs create mode 100644 src/datadogV2/model/model_ddsql_tabular_query_response_attributes.rs create mode 100644 src/datadogV2/model/model_ddsql_tabular_query_response_data.rs create mode 100644 src/datadogV2/model/model_ddsql_tabular_query_response_meta.rs create mode 100644 src/datadogV2/model/model_ddsql_tabular_query_response_type.rs create mode 100644 src/datadogV2/model/model_ddsql_tabular_query_state.rs create mode 100644 src/datadogV2/model/model_ddsql_tabular_query_time_window.rs diff --git a/.generator/schemas/v2/openapi.yaml b/.generator/schemas/v2/openapi.yaml index 61320cada..dc7fca455 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: @@ -133799,6 +134050,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. @@ -201815,6 +202291,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/LICENSE-3rdparty.csv b/LICENSE-3rdparty.csv index 5358f4f86..278616173 100644 --- a/LICENSE-3rdparty.csv +++ b/LICENSE-3rdparty.csv @@ -82,7 +82,7 @@ jni-sys,https://github.com/jni-rs/jni-sys,MIT OR Apache-2.0,"Steven Fackler js-sys,https://github.com/wasm-bindgen/wasm-bindgen/tree/master/crates/js-sys,MIT OR Apache-2.0,The wasm-bindgen Developers lazy_static,https://github.com/rust-lang-nursery/lazy-static.rs,MIT OR Apache-2.0,Marvin Löbel -libc,https://github.com/rust-lang/libc,MIT OR Apache-2.0,The Rust Project Developers +libc,https://github.com/rust-lang/libc,MIT OR Apache-2.0,The libc Authors linux-raw-sys,https://github.com/sunfishcode/linux-raw-sys,Apache-2.0 WITH LLVM-exception OR Apache-2.0 OR MIT,Dan Gohman litemap,https://github.com/unicode-org/icu4x,Unicode-3.0,The ICU4X Project Developers lock_api,https://github.com/Amanieu/parking_lot,MIT OR Apache-2.0,Amanieu d'Antras diff --git a/src/datadog/configuration.rs b/src/datadog/configuration.rs index 0f430b0dd..14b321eae 100644 --- a/src/datadog/configuration.rs +++ b/src/datadog/configuration.rs @@ -547,6 +547,8 @@ impl Default for Configuration { ("v2.get_all_datasets".to_owned(), false), ("v2.get_dataset".to_owned(), false), ("v2.update_dataset".to_owned(), false), + ("v2.execute_ddsql_tabular_query".to_owned(), false), + ("v2.fetch_ddsql_tabular_query".to_owned(), false), ("v2.cancel_data_deletion_request".to_owned(), false), ("v2.create_data_deletion_request".to_owned(), false), ("v2.get_data_deletion_requests".to_owned(), false), diff --git a/src/datadogV2/api/api_ddsql.rs b/src/datadogV2/api/api_ddsql.rs new file mode 100644 index 000000000..8bfbf4568 --- /dev/null +++ b/src/datadogV2/api/api_ddsql.rs @@ -0,0 +1,444 @@ +// 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. +use crate::datadog; +use flate2::{ + write::{GzEncoder, ZlibEncoder}, + Compression, +}; +use log::warn; +use reqwest::header::{HeaderMap, HeaderValue}; +use serde::{Deserialize, Serialize}; +use std::io::Write; + +/// ExecuteDdsqlTabularQueryError is a struct for typed errors of method [`DDSQLAPI::execute_ddsql_tabular_query`] +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(untagged)] +pub enum ExecuteDdsqlTabularQueryError { + JSONAPIErrorResponse(crate::datadogV2::model::JSONAPIErrorResponse), + APIErrorResponse(crate::datadogV2::model::APIErrorResponse), + UnknownValue(serde_json::Value), +} + +/// FetchDdsqlTabularQueryError is a struct for typed errors of method [`DDSQLAPI::fetch_ddsql_tabular_query`] +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(untagged)] +pub enum FetchDdsqlTabularQueryError { + JSONAPIErrorResponse(crate::datadogV2::model::JSONAPIErrorResponse), + APIErrorResponse(crate::datadogV2::model::APIErrorResponse), + UnknownValue(serde_json::Value), +} + +/// 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. +#[derive(Debug, Clone)] +pub struct DDSQLAPI { + config: datadog::Configuration, + client: reqwest_middleware::ClientWithMiddleware, +} + +impl Default for DDSQLAPI { + fn default() -> Self { + Self::with_config(datadog::Configuration::default()) + } +} + +impl DDSQLAPI { + pub fn new() -> Self { + Self::default() + } + pub fn with_config(config: datadog::Configuration) -> Self { + let reqwest_client_builder = { + let builder = reqwest::Client::builder(); + #[cfg(not(target_arch = "wasm32"))] + let builder = if let Some(proxy_url) = &config.proxy_url { + builder.proxy(reqwest::Proxy::all(proxy_url).expect("Failed to parse proxy URL")) + } else { + builder + }; + builder + }; + + let middleware_client_builder = { + let builder = + reqwest_middleware::ClientBuilder::new(reqwest_client_builder.build().unwrap()); + #[cfg(feature = "retry")] + let builder = if config.enable_retry { + struct RetryableStatus; + impl reqwest_retry::RetryableStrategy for RetryableStatus { + fn handle( + &self, + res: &Result, + ) -> Option { + match res { + Ok(success) => reqwest_retry::default_on_request_success(success), + Err(_) => None, + } + } + } + let backoff_policy = reqwest_retry::policies::ExponentialBackoff::builder() + .build_with_max_retries(config.max_retries); + + let retry_middleware = + reqwest_retry::RetryTransientMiddleware::new_with_policy_and_strategy( + backoff_policy, + RetryableStatus, + ); + + builder.with(retry_middleware) + } else { + builder + }; + builder + }; + + let client = middleware_client_builder.build(); + + Self { config, client } + } + + pub fn with_client_and_config( + config: datadog::Configuration, + client: reqwest_middleware::ClientWithMiddleware, + ) -> Self { + Self { config, client } + } + + /// 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. + pub async fn execute_ddsql_tabular_query( + &self, + body: crate::datadogV2::model::DdsqlTabularQueryRequest, + ) -> Result< + crate::datadogV2::model::DdsqlTabularQueryResponse, + datadog::Error, + > { + match self.execute_ddsql_tabular_query_with_http_info(body).await { + Ok(response_content) => { + if let Some(e) = response_content.entity { + Ok(e) + } else { + Err(datadog::Error::Serde(serde::de::Error::custom( + "response content was None", + ))) + } + } + Err(err) => Err(err), + } + } + + /// 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. + pub async fn execute_ddsql_tabular_query_with_http_info( + &self, + body: crate::datadogV2::model::DdsqlTabularQueryRequest, + ) -> Result< + datadog::ResponseContent, + datadog::Error, + > { + let local_configuration = &self.config; + let operation_id = "v2.execute_ddsql_tabular_query"; + if local_configuration.is_unstable_operation_enabled(operation_id) { + warn!("Using unstable operation {operation_id}"); + } else { + let local_error = datadog::UnstableOperationDisabledError { + msg: "Operation 'v2.execute_ddsql_tabular_query' is not enabled".to_string(), + }; + return Err(datadog::Error::UnstableOperationDisabledError(local_error)); + } + + let local_client = &self.client; + + let local_uri_str = format!( + "{}/api/v2/ddsql/query/tabular", + local_configuration.get_operation_host(operation_id) + ); + let mut local_req_builder = + local_client.request(reqwest::Method::POST, local_uri_str.as_str()); + + // build headers + let mut headers = HeaderMap::new(); + headers.insert("Content-Type", HeaderValue::from_static("application/json")); + headers.insert("Accept", HeaderValue::from_static("application/json")); + + // build user agent + match HeaderValue::from_str(local_configuration.user_agent.as_str()) { + Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent), + Err(e) => { + log::warn!("Failed to parse user agent header: {e}, falling back to default"); + headers.insert( + reqwest::header::USER_AGENT, + HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()), + ) + } + }; + + // build auth + if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") { + headers.insert( + "DD-API-KEY", + HeaderValue::from_str(local_key.key.as_str()) + .expect("failed to parse DD-API-KEY header"), + ); + }; + if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") { + headers.insert( + "DD-APPLICATION-KEY", + HeaderValue::from_str(local_key.key.as_str()) + .expect("failed to parse DD-APPLICATION-KEY header"), + ); + }; + + // build body parameters + let output = Vec::new(); + let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter); + if body.serialize(&mut ser).is_ok() { + if let Some(content_encoding) = headers.get("Content-Encoding") { + match content_encoding.to_str().unwrap_or_default() { + "gzip" => { + let mut enc = GzEncoder::new(Vec::new(), Compression::default()); + let _ = enc.write_all(ser.into_inner().as_slice()); + match enc.finish() { + Ok(buf) => { + local_req_builder = local_req_builder.body(buf); + } + Err(e) => return Err(datadog::Error::Io(e)), + } + } + "deflate" => { + let mut enc = ZlibEncoder::new(Vec::new(), Compression::default()); + let _ = enc.write_all(ser.into_inner().as_slice()); + match enc.finish() { + Ok(buf) => { + local_req_builder = local_req_builder.body(buf); + } + Err(e) => return Err(datadog::Error::Io(e)), + } + } + #[cfg(feature = "zstd")] + "zstd1" => { + let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap(); + let _ = enc.write_all(ser.into_inner().as_slice()); + match enc.finish() { + Ok(buf) => { + local_req_builder = local_req_builder.body(buf); + } + Err(e) => return Err(datadog::Error::Io(e)), + } + } + _ => { + local_req_builder = local_req_builder.body(ser.into_inner()); + } + } + } else { + local_req_builder = local_req_builder.body(ser.into_inner()); + } + } + + local_req_builder = local_req_builder.headers(headers); + let local_req = local_req_builder.build()?; + log::debug!("request content: {:?}", local_req.body()); + let local_resp = local_client.execute(local_req).await?; + + let local_status = local_resp.status(); + let local_content = local_resp.text().await?; + log::debug!("response content: {}", local_content); + + if !local_status.is_client_error() && !local_status.is_server_error() { + match serde_json::from_str::( + &local_content, + ) { + Ok(e) => { + return Ok(datadog::ResponseContent { + status: local_status, + content: local_content, + entity: Some(e), + }) + } + Err(e) => return Err(datadog::Error::Serde(e)), + }; + } else { + let local_entity: Option = + serde_json::from_str(&local_content).ok(); + let local_error = datadog::ResponseContent { + status: local_status, + content: local_content, + entity: local_entity, + }; + Err(datadog::Error::ResponseError(local_error)) + } + } + + /// 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. + pub async fn fetch_ddsql_tabular_query( + &self, + body: crate::datadogV2::model::DdsqlTabularQueryFetchRequest, + ) -> Result< + crate::datadogV2::model::DdsqlTabularQueryResponse, + datadog::Error, + > { + match self.fetch_ddsql_tabular_query_with_http_info(body).await { + Ok(response_content) => { + if let Some(e) = response_content.entity { + Ok(e) + } else { + Err(datadog::Error::Serde(serde::de::Error::custom( + "response content was None", + ))) + } + } + Err(err) => Err(err), + } + } + + /// 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. + pub async fn fetch_ddsql_tabular_query_with_http_info( + &self, + body: crate::datadogV2::model::DdsqlTabularQueryFetchRequest, + ) -> Result< + datadog::ResponseContent, + datadog::Error, + > { + let local_configuration = &self.config; + let operation_id = "v2.fetch_ddsql_tabular_query"; + if local_configuration.is_unstable_operation_enabled(operation_id) { + warn!("Using unstable operation {operation_id}"); + } else { + let local_error = datadog::UnstableOperationDisabledError { + msg: "Operation 'v2.fetch_ddsql_tabular_query' is not enabled".to_string(), + }; + return Err(datadog::Error::UnstableOperationDisabledError(local_error)); + } + + let local_client = &self.client; + + let local_uri_str = format!( + "{}/api/v2/ddsql/query/tabular/fetch", + local_configuration.get_operation_host(operation_id) + ); + let mut local_req_builder = + local_client.request(reqwest::Method::POST, local_uri_str.as_str()); + + // build headers + let mut headers = HeaderMap::new(); + headers.insert("Content-Type", HeaderValue::from_static("application/json")); + headers.insert("Accept", HeaderValue::from_static("application/json")); + + // build user agent + match HeaderValue::from_str(local_configuration.user_agent.as_str()) { + Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent), + Err(e) => { + log::warn!("Failed to parse user agent header: {e}, falling back to default"); + headers.insert( + reqwest::header::USER_AGENT, + HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()), + ) + } + }; + + // build auth + if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") { + headers.insert( + "DD-API-KEY", + HeaderValue::from_str(local_key.key.as_str()) + .expect("failed to parse DD-API-KEY header"), + ); + }; + if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") { + headers.insert( + "DD-APPLICATION-KEY", + HeaderValue::from_str(local_key.key.as_str()) + .expect("failed to parse DD-APPLICATION-KEY header"), + ); + }; + + // build body parameters + let output = Vec::new(); + let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter); + if body.serialize(&mut ser).is_ok() { + if let Some(content_encoding) = headers.get("Content-Encoding") { + match content_encoding.to_str().unwrap_or_default() { + "gzip" => { + let mut enc = GzEncoder::new(Vec::new(), Compression::default()); + let _ = enc.write_all(ser.into_inner().as_slice()); + match enc.finish() { + Ok(buf) => { + local_req_builder = local_req_builder.body(buf); + } + Err(e) => return Err(datadog::Error::Io(e)), + } + } + "deflate" => { + let mut enc = ZlibEncoder::new(Vec::new(), Compression::default()); + let _ = enc.write_all(ser.into_inner().as_slice()); + match enc.finish() { + Ok(buf) => { + local_req_builder = local_req_builder.body(buf); + } + Err(e) => return Err(datadog::Error::Io(e)), + } + } + #[cfg(feature = "zstd")] + "zstd1" => { + let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap(); + let _ = enc.write_all(ser.into_inner().as_slice()); + match enc.finish() { + Ok(buf) => { + local_req_builder = local_req_builder.body(buf); + } + Err(e) => return Err(datadog::Error::Io(e)), + } + } + _ => { + local_req_builder = local_req_builder.body(ser.into_inner()); + } + } + } else { + local_req_builder = local_req_builder.body(ser.into_inner()); + } + } + + local_req_builder = local_req_builder.headers(headers); + let local_req = local_req_builder.build()?; + log::debug!("request content: {:?}", local_req.body()); + let local_resp = local_client.execute(local_req).await?; + + let local_status = local_resp.status(); + let local_content = local_resp.text().await?; + log::debug!("response content: {}", local_content); + + if !local_status.is_client_error() && !local_status.is_server_error() { + match serde_json::from_str::( + &local_content, + ) { + Ok(e) => { + return Ok(datadog::ResponseContent { + status: local_status, + content: local_content, + entity: Some(e), + }) + } + Err(e) => return Err(datadog::Error::Serde(e)), + }; + } else { + let local_entity: Option = + serde_json::from_str(&local_content).ok(); + let local_error = datadog::ResponseContent { + status: local_status, + content: local_content, + entity: local_entity, + }; + Err(datadog::Error::ResponseError(local_error)) + } + } +} diff --git a/src/datadogV2/api/mod.rs b/src/datadogV2/api/mod.rs index 107e6724e..1bb4db19d 100644 --- a/src/datadogV2/api/mod.rs +++ b/src/datadogV2/api/mod.rs @@ -45,6 +45,7 @@ pub mod api_dashboards; pub mod api_data_deletion; pub mod api_data_observability; pub mod api_datasets; +pub mod api_ddsql; pub mod api_deployment_gates; pub mod api_domain_allowlist; pub mod api_dora_metrics; diff --git a/src/datadogV2/mod.rs b/src/datadogV2/mod.rs index c451fe6e8..cf3a37a3a 100644 --- a/src/datadogV2/mod.rs +++ b/src/datadogV2/mod.rs @@ -46,6 +46,7 @@ pub use self::api::api_dashboards; pub use self::api::api_data_deletion; pub use self::api::api_data_observability; pub use self::api::api_datasets; +pub use self::api::api_ddsql; pub use self::api::api_deployment_gates; pub use self::api::api_domain_allowlist; pub use self::api::api_dora_metrics; diff --git a/src/datadogV2/model/mod.rs b/src/datadogV2/model/mod.rs index 448df5bc7..23e11356f 100644 --- a/src/datadogV2/model/mod.rs +++ b/src/datadogV2/model/mod.rs @@ -3460,6 +3460,38 @@ pub mod model_dataset_response_single; pub use self::model_dataset_response_single::DatasetResponseSingle; pub mod model_dataset_update_request; pub use self::model_dataset_update_request::DatasetUpdateRequest; +pub mod model_ddsql_tabular_query_request; +pub use self::model_ddsql_tabular_query_request::DdsqlTabularQueryRequest; +pub mod model_ddsql_tabular_query_request_data; +pub use self::model_ddsql_tabular_query_request_data::DdsqlTabularQueryRequestData; +pub mod model_ddsql_tabular_query_request_attributes; +pub use self::model_ddsql_tabular_query_request_attributes::DdsqlTabularQueryRequestAttributes; +pub mod model_ddsql_tabular_query_time_window; +pub use self::model_ddsql_tabular_query_time_window::DdsqlTabularQueryTimeWindow; +pub mod model_ddsql_tabular_query_request_type; +pub use self::model_ddsql_tabular_query_request_type::DdsqlTabularQueryRequestType; +pub mod model_ddsql_tabular_query_response; +pub use self::model_ddsql_tabular_query_response::DdsqlTabularQueryResponse; +pub mod model_ddsql_tabular_query_response_data; +pub use self::model_ddsql_tabular_query_response_data::DdsqlTabularQueryResponseData; +pub mod model_ddsql_tabular_query_response_attributes; +pub use self::model_ddsql_tabular_query_response_attributes::DdsqlTabularQueryResponseAttributes; +pub mod model_ddsql_tabular_query_column; +pub use self::model_ddsql_tabular_query_column::DdsqlTabularQueryColumn; +pub mod model_ddsql_tabular_query_state; +pub use self::model_ddsql_tabular_query_state::DdsqlTabularQueryState; +pub mod model_ddsql_tabular_query_response_type; +pub use self::model_ddsql_tabular_query_response_type::DdsqlTabularQueryResponseType; +pub mod model_ddsql_tabular_query_response_meta; +pub use self::model_ddsql_tabular_query_response_meta::DdsqlTabularQueryResponseMeta; +pub mod model_ddsql_tabular_query_fetch_request; +pub use self::model_ddsql_tabular_query_fetch_request::DdsqlTabularQueryFetchRequest; +pub mod model_ddsql_tabular_query_fetch_request_data; +pub use self::model_ddsql_tabular_query_fetch_request_data::DdsqlTabularQueryFetchRequestData; +pub mod model_ddsql_tabular_query_fetch_request_attributes; +pub use self::model_ddsql_tabular_query_fetch_request_attributes::DdsqlTabularQueryFetchRequestAttributes; +pub mod model_ddsql_tabular_query_fetch_request_type; +pub use self::model_ddsql_tabular_query_fetch_request_type::DdsqlTabularQueryFetchRequestType; pub mod model_create_data_deletion_request_body; pub use self::model_create_data_deletion_request_body::CreateDataDeletionRequestBody; pub mod model_create_data_deletion_request_body_data; diff --git a/src/datadogV2/model/model_ddsql_tabular_query_column.rs b/src/datadogV2/model/model_ddsql_tabular_query_column.rs new file mode 100644 index 000000000..9f48802b2 --- /dev/null +++ b/src/datadogV2/model/model_ddsql_tabular_query_column.rs @@ -0,0 +1,122 @@ +// 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. +use serde::de::{Error, MapAccess, Visitor}; +use serde::{Deserialize, Deserializer, Serialize}; +use serde_with::skip_serializing_none; +use std::fmt::{self, Formatter}; + +/// A single column of a DDSQL tabular query result. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct DdsqlTabularQueryColumn { + /// Name of the column as projected by the SQL statement. + #[serde(rename = "name")] + pub name: String, + /// 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. + #[serde(rename = "type")] + pub type_: String, + /// 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. + #[serde(rename = "values")] + pub values: Vec, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl DdsqlTabularQueryColumn { + pub fn new( + name: String, + type_: String, + values: Vec, + ) -> DdsqlTabularQueryColumn { + DdsqlTabularQueryColumn { + name, + type_, + values, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl<'de> Deserialize<'de> for DdsqlTabularQueryColumn { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct DdsqlTabularQueryColumnVisitor; + impl<'a> Visitor<'a> for DdsqlTabularQueryColumnVisitor { + type Value = DdsqlTabularQueryColumn; + + fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str("a mapping") + } + + fn visit_map(self, mut map: M) -> Result + where + M: MapAccess<'a>, + { + let mut name: Option = None; + let mut type_: Option = None; + let mut values: Option> = None; + let mut additional_properties: std::collections::BTreeMap< + String, + serde_json::Value, + > = std::collections::BTreeMap::new(); + let mut _unparsed = false; + + while let Some((k, v)) = map.next_entry::()? { + match k.as_str() { + "name" => { + name = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "type" => { + type_ = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "values" => { + values = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + &_ => { + if let Ok(value) = serde_json::from_value(v.clone()) { + additional_properties.insert(k, value); + } + } + } + } + let name = name.ok_or_else(|| M::Error::missing_field("name"))?; + let type_ = type_.ok_or_else(|| M::Error::missing_field("type_"))?; + let values = values.ok_or_else(|| M::Error::missing_field("values"))?; + + let content = DdsqlTabularQueryColumn { + name, + type_, + values, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(DdsqlTabularQueryColumnVisitor) + } +} diff --git a/src/datadogV2/model/model_ddsql_tabular_query_fetch_request.rs b/src/datadogV2/model/model_ddsql_tabular_query_fetch_request.rs new file mode 100644 index 000000000..6fa730bbc --- /dev/null +++ b/src/datadogV2/model/model_ddsql_tabular_query_fetch_request.rs @@ -0,0 +1,95 @@ +// 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. +use serde::de::{Error, MapAccess, Visitor}; +use serde::{Deserialize, Deserializer, Serialize}; +use serde_with::skip_serializing_none; +use std::fmt::{self, Formatter}; + +/// Wrapper for a DDSQL tabular query fetch request. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct DdsqlTabularQueryFetchRequest { + /// JSON:API resource object for a DDSQL tabular query fetch request. + #[serde(rename = "data")] + pub data: crate::datadogV2::model::DdsqlTabularQueryFetchRequestData, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl DdsqlTabularQueryFetchRequest { + pub fn new( + data: crate::datadogV2::model::DdsqlTabularQueryFetchRequestData, + ) -> DdsqlTabularQueryFetchRequest { + DdsqlTabularQueryFetchRequest { + data, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl<'de> Deserialize<'de> for DdsqlTabularQueryFetchRequest { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct DdsqlTabularQueryFetchRequestVisitor; + impl<'a> Visitor<'a> for DdsqlTabularQueryFetchRequestVisitor { + type Value = DdsqlTabularQueryFetchRequest; + + fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str("a mapping") + } + + fn visit_map(self, mut map: M) -> Result + where + M: MapAccess<'a>, + { + let mut data: Option = + None; + let mut additional_properties: std::collections::BTreeMap< + String, + serde_json::Value, + > = std::collections::BTreeMap::new(); + let mut _unparsed = false; + + while let Some((k, v)) = map.next_entry::()? { + match k.as_str() { + "data" => { + data = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + &_ => { + if let Ok(value) = serde_json::from_value(v.clone()) { + additional_properties.insert(k, value); + } + } + } + } + let data = data.ok_or_else(|| M::Error::missing_field("data"))?; + + let content = DdsqlTabularQueryFetchRequest { + data, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(DdsqlTabularQueryFetchRequestVisitor) + } +} diff --git a/src/datadogV2/model/model_ddsql_tabular_query_fetch_request_attributes.rs b/src/datadogV2/model/model_ddsql_tabular_query_fetch_request_attributes.rs new file mode 100644 index 000000000..3e49c519a --- /dev/null +++ b/src/datadogV2/model/model_ddsql_tabular_query_fetch_request_attributes.rs @@ -0,0 +1,93 @@ +// 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. +use serde::de::{Error, MapAccess, Visitor}; +use serde::{Deserialize, Deserializer, Serialize}; +use serde_with::skip_serializing_none; +use std::fmt::{self, Formatter}; + +/// Attributes describing which previously submitted DDSQL query to fetch. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct DdsqlTabularQueryFetchRequestAttributes { + /// Opaque token returned by an earlier execute or fetch response that carried + /// `state: running`. Identifies the query to poll for results. + #[serde(rename = "query_id")] + pub query_id: String, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl DdsqlTabularQueryFetchRequestAttributes { + pub fn new(query_id: String) -> DdsqlTabularQueryFetchRequestAttributes { + DdsqlTabularQueryFetchRequestAttributes { + query_id, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl<'de> Deserialize<'de> for DdsqlTabularQueryFetchRequestAttributes { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct DdsqlTabularQueryFetchRequestAttributesVisitor; + impl<'a> Visitor<'a> for DdsqlTabularQueryFetchRequestAttributesVisitor { + type Value = DdsqlTabularQueryFetchRequestAttributes; + + fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str("a mapping") + } + + fn visit_map(self, mut map: M) -> Result + where + M: MapAccess<'a>, + { + let mut query_id: Option = None; + let mut additional_properties: std::collections::BTreeMap< + String, + serde_json::Value, + > = std::collections::BTreeMap::new(); + let mut _unparsed = false; + + while let Some((k, v)) = map.next_entry::()? { + match k.as_str() { + "query_id" => { + query_id = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + &_ => { + if let Ok(value) = serde_json::from_value(v.clone()) { + additional_properties.insert(k, value); + } + } + } + } + let query_id = query_id.ok_or_else(|| M::Error::missing_field("query_id"))?; + + let content = DdsqlTabularQueryFetchRequestAttributes { + query_id, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(DdsqlTabularQueryFetchRequestAttributesVisitor) + } +} diff --git a/src/datadogV2/model/model_ddsql_tabular_query_fetch_request_data.rs b/src/datadogV2/model/model_ddsql_tabular_query_fetch_request_data.rs new file mode 100644 index 000000000..32e887c0b --- /dev/null +++ b/src/datadogV2/model/model_ddsql_tabular_query_fetch_request_data.rs @@ -0,0 +1,116 @@ +// 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. +use serde::de::{Error, MapAccess, Visitor}; +use serde::{Deserialize, Deserializer, Serialize}; +use serde_with::skip_serializing_none; +use std::fmt::{self, Formatter}; + +/// JSON:API resource object for a DDSQL tabular query fetch request. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct DdsqlTabularQueryFetchRequestData { + /// Attributes describing which previously submitted DDSQL query to fetch. + #[serde(rename = "attributes")] + pub attributes: crate::datadogV2::model::DdsqlTabularQueryFetchRequestAttributes, + /// JSON:API resource type for a DDSQL tabular query fetch request. + #[serde(rename = "type")] + pub type_: crate::datadogV2::model::DdsqlTabularQueryFetchRequestType, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl DdsqlTabularQueryFetchRequestData { + pub fn new( + attributes: crate::datadogV2::model::DdsqlTabularQueryFetchRequestAttributes, + type_: crate::datadogV2::model::DdsqlTabularQueryFetchRequestType, + ) -> DdsqlTabularQueryFetchRequestData { + DdsqlTabularQueryFetchRequestData { + attributes, + type_, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl<'de> Deserialize<'de> for DdsqlTabularQueryFetchRequestData { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct DdsqlTabularQueryFetchRequestDataVisitor; + impl<'a> Visitor<'a> for DdsqlTabularQueryFetchRequestDataVisitor { + type Value = DdsqlTabularQueryFetchRequestData; + + fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str("a mapping") + } + + fn visit_map(self, mut map: M) -> Result + where + M: MapAccess<'a>, + { + let mut attributes: Option< + crate::datadogV2::model::DdsqlTabularQueryFetchRequestAttributes, + > = None; + let mut type_: Option = + None; + let mut additional_properties: std::collections::BTreeMap< + String, + serde_json::Value, + > = std::collections::BTreeMap::new(); + let mut _unparsed = false; + + while let Some((k, v)) = map.next_entry::()? { + match k.as_str() { + "attributes" => { + attributes = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "type" => { + type_ = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + if let Some(ref _type_) = type_ { + match _type_ { + crate::datadogV2::model::DdsqlTabularQueryFetchRequestType::UnparsedObject(_type_) => { + _unparsed = true; + }, + _ => {} + } + } + } + &_ => { + if let Ok(value) = serde_json::from_value(v.clone()) { + additional_properties.insert(k, value); + } + } + } + } + let attributes = attributes.ok_or_else(|| M::Error::missing_field("attributes"))?; + let type_ = type_.ok_or_else(|| M::Error::missing_field("type_"))?; + + let content = DdsqlTabularQueryFetchRequestData { + attributes, + type_, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(DdsqlTabularQueryFetchRequestDataVisitor) + } +} diff --git a/src/datadogV2/model/model_ddsql_tabular_query_fetch_request_type.rs b/src/datadogV2/model/model_ddsql_tabular_query_fetch_request_type.rs new file mode 100644 index 000000000..9f3222f34 --- /dev/null +++ b/src/datadogV2/model/model_ddsql_tabular_query_fetch_request_type.rs @@ -0,0 +1,48 @@ +// 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. + +use serde::{Deserialize, Deserializer, Serialize, Serializer}; + +#[non_exhaustive] +#[derive(Clone, Debug, Eq, PartialEq)] +pub enum DdsqlTabularQueryFetchRequestType { + DDSQL_QUERY_FETCH_REQUEST, + UnparsedObject(crate::datadog::UnparsedObject), +} + +impl ToString for DdsqlTabularQueryFetchRequestType { + fn to_string(&self) -> String { + match self { + Self::DDSQL_QUERY_FETCH_REQUEST => String::from("ddsql_query_fetch_request"), + Self::UnparsedObject(v) => v.value.to_string(), + } + } +} + +impl Serialize for DdsqlTabularQueryFetchRequestType { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + match self { + Self::UnparsedObject(v) => v.serialize(serializer), + _ => serializer.serialize_str(self.to_string().as_str()), + } + } +} + +impl<'de> Deserialize<'de> for DdsqlTabularQueryFetchRequestType { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + let s: String = String::deserialize(deserializer)?; + Ok(match s.as_str() { + "ddsql_query_fetch_request" => Self::DDSQL_QUERY_FETCH_REQUEST, + _ => Self::UnparsedObject(crate::datadog::UnparsedObject { + value: serde_json::Value::String(s.into()), + }), + }) + } +} diff --git a/src/datadogV2/model/model_ddsql_tabular_query_request.rs b/src/datadogV2/model/model_ddsql_tabular_query_request.rs new file mode 100644 index 000000000..34470feff --- /dev/null +++ b/src/datadogV2/model/model_ddsql_tabular_query_request.rs @@ -0,0 +1,94 @@ +// 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. +use serde::de::{Error, MapAccess, Visitor}; +use serde::{Deserialize, Deserializer, Serialize}; +use serde_with::skip_serializing_none; +use std::fmt::{self, Formatter}; + +/// Wrapper for a DDSQL tabular query execution request. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct DdsqlTabularQueryRequest { + /// JSON:API resource object for a DDSQL tabular query execution request. + #[serde(rename = "data")] + pub data: crate::datadogV2::model::DdsqlTabularQueryRequestData, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl DdsqlTabularQueryRequest { + pub fn new( + data: crate::datadogV2::model::DdsqlTabularQueryRequestData, + ) -> DdsqlTabularQueryRequest { + DdsqlTabularQueryRequest { + data, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl<'de> Deserialize<'de> for DdsqlTabularQueryRequest { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct DdsqlTabularQueryRequestVisitor; + impl<'a> Visitor<'a> for DdsqlTabularQueryRequestVisitor { + type Value = DdsqlTabularQueryRequest; + + fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str("a mapping") + } + + fn visit_map(self, mut map: M) -> Result + where + M: MapAccess<'a>, + { + let mut data: Option = None; + let mut additional_properties: std::collections::BTreeMap< + String, + serde_json::Value, + > = std::collections::BTreeMap::new(); + let mut _unparsed = false; + + while let Some((k, v)) = map.next_entry::()? { + match k.as_str() { + "data" => { + data = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + &_ => { + if let Ok(value) = serde_json::from_value(v.clone()) { + additional_properties.insert(k, value); + } + } + } + } + let data = data.ok_or_else(|| M::Error::missing_field("data"))?; + + let content = DdsqlTabularQueryRequest { + data, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(DdsqlTabularQueryRequestVisitor) + } +} diff --git a/src/datadogV2/model/model_ddsql_tabular_query_request_attributes.rs b/src/datadogV2/model/model_ddsql_tabular_query_request_attributes.rs new file mode 100644 index 000000000..81567a22f --- /dev/null +++ b/src/datadogV2/model/model_ddsql_tabular_query_request_attributes.rs @@ -0,0 +1,127 @@ +// 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. +use serde::de::{Error, MapAccess, Visitor}; +use serde::{Deserialize, Deserializer, Serialize}; +use serde_with::skip_serializing_none; +use std::fmt::{self, Formatter}; + +/// Attributes describing the DDSQL query to execute. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct DdsqlTabularQueryRequestAttributes { + /// The DDSQL statement to execute. DDSQL is Datadog's SQL dialect, which is a subset + /// of PostgreSQL, scoped to Datadog data sources. + #[serde(rename = "query")] + pub query: String, + /// 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. + #[serde(rename = "row_limit")] + pub row_limit: Option, + /// 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. + #[serde(rename = "time")] + pub time: crate::datadogV2::model::DdsqlTabularQueryTimeWindow, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl DdsqlTabularQueryRequestAttributes { + pub fn new( + query: String, + time: crate::datadogV2::model::DdsqlTabularQueryTimeWindow, + ) -> DdsqlTabularQueryRequestAttributes { + DdsqlTabularQueryRequestAttributes { + query, + row_limit: None, + time, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn row_limit(mut self, value: i64) -> Self { + self.row_limit = Some(value); + self + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl<'de> Deserialize<'de> for DdsqlTabularQueryRequestAttributes { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct DdsqlTabularQueryRequestAttributesVisitor; + impl<'a> Visitor<'a> for DdsqlTabularQueryRequestAttributesVisitor { + type Value = DdsqlTabularQueryRequestAttributes; + + fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str("a mapping") + } + + fn visit_map(self, mut map: M) -> Result + where + M: MapAccess<'a>, + { + let mut query: Option = None; + let mut row_limit: Option = None; + let mut time: Option = None; + let mut additional_properties: std::collections::BTreeMap< + String, + serde_json::Value, + > = std::collections::BTreeMap::new(); + let mut _unparsed = false; + + while let Some((k, v)) = map.next_entry::()? { + match k.as_str() { + "query" => { + query = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "row_limit" => { + if v.is_null() { + continue; + } + row_limit = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "time" => { + time = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + &_ => { + if let Ok(value) = serde_json::from_value(v.clone()) { + additional_properties.insert(k, value); + } + } + } + } + let query = query.ok_or_else(|| M::Error::missing_field("query"))?; + let time = time.ok_or_else(|| M::Error::missing_field("time"))?; + + let content = DdsqlTabularQueryRequestAttributes { + query, + row_limit, + time, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(DdsqlTabularQueryRequestAttributesVisitor) + } +} diff --git a/src/datadogV2/model/model_ddsql_tabular_query_request_data.rs b/src/datadogV2/model/model_ddsql_tabular_query_request_data.rs new file mode 100644 index 000000000..ff8d1f550 --- /dev/null +++ b/src/datadogV2/model/model_ddsql_tabular_query_request_data.rs @@ -0,0 +1,115 @@ +// 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. +use serde::de::{Error, MapAccess, Visitor}; +use serde::{Deserialize, Deserializer, Serialize}; +use serde_with::skip_serializing_none; +use std::fmt::{self, Formatter}; + +/// JSON:API resource object for a DDSQL tabular query execution request. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct DdsqlTabularQueryRequestData { + /// Attributes describing the DDSQL query to execute. + #[serde(rename = "attributes")] + pub attributes: crate::datadogV2::model::DdsqlTabularQueryRequestAttributes, + /// JSON:API resource type for a DDSQL tabular query request. + #[serde(rename = "type")] + pub type_: crate::datadogV2::model::DdsqlTabularQueryRequestType, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl DdsqlTabularQueryRequestData { + pub fn new( + attributes: crate::datadogV2::model::DdsqlTabularQueryRequestAttributes, + type_: crate::datadogV2::model::DdsqlTabularQueryRequestType, + ) -> DdsqlTabularQueryRequestData { + DdsqlTabularQueryRequestData { + attributes, + type_, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl<'de> Deserialize<'de> for DdsqlTabularQueryRequestData { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct DdsqlTabularQueryRequestDataVisitor; + impl<'a> Visitor<'a> for DdsqlTabularQueryRequestDataVisitor { + type Value = DdsqlTabularQueryRequestData; + + fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str("a mapping") + } + + fn visit_map(self, mut map: M) -> Result + where + M: MapAccess<'a>, + { + let mut attributes: Option< + crate::datadogV2::model::DdsqlTabularQueryRequestAttributes, + > = None; + let mut type_: Option = None; + let mut additional_properties: std::collections::BTreeMap< + String, + serde_json::Value, + > = std::collections::BTreeMap::new(); + let mut _unparsed = false; + + while let Some((k, v)) = map.next_entry::()? { + match k.as_str() { + "attributes" => { + attributes = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "type" => { + type_ = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + if let Some(ref _type_) = type_ { + match _type_ { + crate::datadogV2::model::DdsqlTabularQueryRequestType::UnparsedObject(_type_) => { + _unparsed = true; + }, + _ => {} + } + } + } + &_ => { + if let Ok(value) = serde_json::from_value(v.clone()) { + additional_properties.insert(k, value); + } + } + } + } + let attributes = attributes.ok_or_else(|| M::Error::missing_field("attributes"))?; + let type_ = type_.ok_or_else(|| M::Error::missing_field("type_"))?; + + let content = DdsqlTabularQueryRequestData { + attributes, + type_, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(DdsqlTabularQueryRequestDataVisitor) + } +} diff --git a/src/datadogV2/model/model_ddsql_tabular_query_request_type.rs b/src/datadogV2/model/model_ddsql_tabular_query_request_type.rs new file mode 100644 index 000000000..959bf8bfc --- /dev/null +++ b/src/datadogV2/model/model_ddsql_tabular_query_request_type.rs @@ -0,0 +1,48 @@ +// 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. + +use serde::{Deserialize, Deserializer, Serialize, Serializer}; + +#[non_exhaustive] +#[derive(Clone, Debug, Eq, PartialEq)] +pub enum DdsqlTabularQueryRequestType { + DDSQL_QUERY_REQUEST, + UnparsedObject(crate::datadog::UnparsedObject), +} + +impl ToString for DdsqlTabularQueryRequestType { + fn to_string(&self) -> String { + match self { + Self::DDSQL_QUERY_REQUEST => String::from("ddsql_query_request"), + Self::UnparsedObject(v) => v.value.to_string(), + } + } +} + +impl Serialize for DdsqlTabularQueryRequestType { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + match self { + Self::UnparsedObject(v) => v.serialize(serializer), + _ => serializer.serialize_str(self.to_string().as_str()), + } + } +} + +impl<'de> Deserialize<'de> for DdsqlTabularQueryRequestType { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + let s: String = String::deserialize(deserializer)?; + Ok(match s.as_str() { + "ddsql_query_request" => Self::DDSQL_QUERY_REQUEST, + _ => Self::UnparsedObject(crate::datadog::UnparsedObject { + value: serde_json::Value::String(s.into()), + }), + }) + } +} diff --git a/src/datadogV2/model/model_ddsql_tabular_query_response.rs b/src/datadogV2/model/model_ddsql_tabular_query_response.rs new file mode 100644 index 000000000..fa1fe145b --- /dev/null +++ b/src/datadogV2/model/model_ddsql_tabular_query_response.rs @@ -0,0 +1,108 @@ +// 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. +use serde::de::{Error, MapAccess, Visitor}; +use serde::{Deserialize, Deserializer, Serialize}; +use serde_with::skip_serializing_none; +use std::fmt::{self, Formatter}; + +/// 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. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct DdsqlTabularQueryResponse { + /// JSON:API resource object for a DDSQL tabular query response. + #[serde(rename = "data")] + pub data: crate::datadogV2::model::DdsqlTabularQueryResponseData, + /// Top-level JSON:API meta block accompanying every DDSQL tabular query response. + /// Carries standard observability handles for client-side correlation. + #[serde(rename = "meta")] + pub meta: crate::datadogV2::model::DdsqlTabularQueryResponseMeta, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl DdsqlTabularQueryResponse { + pub fn new( + data: crate::datadogV2::model::DdsqlTabularQueryResponseData, + meta: crate::datadogV2::model::DdsqlTabularQueryResponseMeta, + ) -> DdsqlTabularQueryResponse { + DdsqlTabularQueryResponse { + data, + meta, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl<'de> Deserialize<'de> for DdsqlTabularQueryResponse { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct DdsqlTabularQueryResponseVisitor; + impl<'a> Visitor<'a> for DdsqlTabularQueryResponseVisitor { + type Value = DdsqlTabularQueryResponse; + + fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str("a mapping") + } + + fn visit_map(self, mut map: M) -> Result + where + M: MapAccess<'a>, + { + let mut data: Option = None; + let mut meta: Option = None; + let mut additional_properties: std::collections::BTreeMap< + String, + serde_json::Value, + > = std::collections::BTreeMap::new(); + let mut _unparsed = false; + + while let Some((k, v)) = map.next_entry::()? { + match k.as_str() { + "data" => { + data = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "meta" => { + meta = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + &_ => { + if let Ok(value) = serde_json::from_value(v.clone()) { + additional_properties.insert(k, value); + } + } + } + } + let data = data.ok_or_else(|| M::Error::missing_field("data"))?; + let meta = meta.ok_or_else(|| M::Error::missing_field("meta"))?; + + let content = DdsqlTabularQueryResponse { + data, + meta, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(DdsqlTabularQueryResponseVisitor) + } +} diff --git a/src/datadogV2/model/model_ddsql_tabular_query_response_attributes.rs b/src/datadogV2/model/model_ddsql_tabular_query_response_attributes.rs new file mode 100644 index 000000000..3bb52ddde --- /dev/null +++ b/src/datadogV2/model/model_ddsql_tabular_query_response_attributes.rs @@ -0,0 +1,160 @@ +// 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. +use serde::de::{Error, MapAccess, Visitor}; +use serde::{Deserialize, Deserializer, Serialize}; +use serde_with::skip_serializing_none; +use std::fmt::{self, Formatter}; + +/// Attributes of a DDSQL tabular query response. `query_id` is set when +/// `state` is `running`; `columns` is set when `state` is `completed`. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct DdsqlTabularQueryResponseAttributes { + /// 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`. + #[serde(rename = "columns")] + pub columns: Option>, + /// Opaque token to pass to the fetch endpoint to poll for results. + /// Set when `state` is `running` and absent when `state` is `completed`. + #[serde(rename = "query_id")] + pub query_id: Option, + /// 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. + #[serde(rename = "state")] + pub state: crate::datadogV2::model::DdsqlTabularQueryState, + /// Non-fatal messages emitted by the query engine while serving this response. + #[serde(rename = "warnings")] + pub warnings: Option>, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl DdsqlTabularQueryResponseAttributes { + pub fn new( + state: crate::datadogV2::model::DdsqlTabularQueryState, + ) -> DdsqlTabularQueryResponseAttributes { + DdsqlTabularQueryResponseAttributes { + columns: None, + query_id: None, + state, + warnings: None, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn columns(mut self, value: Vec) -> Self { + self.columns = Some(value); + self + } + + pub fn query_id(mut self, value: String) -> Self { + self.query_id = Some(value); + self + } + + pub fn warnings(mut self, value: Vec) -> Self { + self.warnings = Some(value); + self + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl<'de> Deserialize<'de> for DdsqlTabularQueryResponseAttributes { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct DdsqlTabularQueryResponseAttributesVisitor; + impl<'a> Visitor<'a> for DdsqlTabularQueryResponseAttributesVisitor { + type Value = DdsqlTabularQueryResponseAttributes; + + fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str("a mapping") + } + + fn visit_map(self, mut map: M) -> Result + where + M: MapAccess<'a>, + { + let mut columns: Option> = + None; + let mut query_id: Option = None; + let mut state: Option = None; + let mut warnings: Option> = None; + let mut additional_properties: std::collections::BTreeMap< + String, + serde_json::Value, + > = std::collections::BTreeMap::new(); + let mut _unparsed = false; + + while let Some((k, v)) = map.next_entry::()? { + match k.as_str() { + "columns" => { + if v.is_null() { + continue; + } + columns = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "query_id" => { + if v.is_null() { + continue; + } + query_id = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "state" => { + state = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + if let Some(ref _state) = state { + match _state { + crate::datadogV2::model::DdsqlTabularQueryState::UnparsedObject(_state) => { + _unparsed = true; + }, + _ => {} + } + } + } + "warnings" => { + if v.is_null() { + continue; + } + warnings = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + &_ => { + if let Ok(value) = serde_json::from_value(v.clone()) { + additional_properties.insert(k, value); + } + } + } + } + let state = state.ok_or_else(|| M::Error::missing_field("state"))?; + + let content = DdsqlTabularQueryResponseAttributes { + columns, + query_id, + state, + warnings, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(DdsqlTabularQueryResponseAttributesVisitor) + } +} diff --git a/src/datadogV2/model/model_ddsql_tabular_query_response_data.rs b/src/datadogV2/model/model_ddsql_tabular_query_response_data.rs new file mode 100644 index 000000000..c7c39bfb0 --- /dev/null +++ b/src/datadogV2/model/model_ddsql_tabular_query_response_data.rs @@ -0,0 +1,128 @@ +// 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. +use serde::de::{Error, MapAccess, Visitor}; +use serde::{Deserialize, Deserializer, Serialize}; +use serde_with::skip_serializing_none; +use std::fmt::{self, Formatter}; + +/// JSON:API resource object for a DDSQL tabular query response. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct DdsqlTabularQueryResponseData { + /// Attributes of a DDSQL tabular query response. `query_id` is set when + /// `state` is `running`; `columns` is set when `state` is `completed`. + #[serde(rename = "attributes")] + pub attributes: crate::datadogV2::model::DdsqlTabularQueryResponseAttributes, + /// Stable identifier for the query response resource. + #[serde(rename = "id")] + pub id: String, + /// JSON:API resource type for a DDSQL tabular query response. + #[serde(rename = "type")] + pub type_: crate::datadogV2::model::DdsqlTabularQueryResponseType, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl DdsqlTabularQueryResponseData { + pub fn new( + attributes: crate::datadogV2::model::DdsqlTabularQueryResponseAttributes, + id: String, + type_: crate::datadogV2::model::DdsqlTabularQueryResponseType, + ) -> DdsqlTabularQueryResponseData { + DdsqlTabularQueryResponseData { + attributes, + id, + type_, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl<'de> Deserialize<'de> for DdsqlTabularQueryResponseData { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct DdsqlTabularQueryResponseDataVisitor; + impl<'a> Visitor<'a> for DdsqlTabularQueryResponseDataVisitor { + type Value = DdsqlTabularQueryResponseData; + + fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str("a mapping") + } + + fn visit_map(self, mut map: M) -> Result + where + M: MapAccess<'a>, + { + let mut attributes: Option< + crate::datadogV2::model::DdsqlTabularQueryResponseAttributes, + > = None; + let mut id: Option = None; + let mut type_: Option = + None; + let mut additional_properties: std::collections::BTreeMap< + String, + serde_json::Value, + > = std::collections::BTreeMap::new(); + let mut _unparsed = false; + + while let Some((k, v)) = map.next_entry::()? { + match k.as_str() { + "attributes" => { + attributes = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "id" => { + id = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "type" => { + type_ = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + if let Some(ref _type_) = type_ { + match _type_ { + crate::datadogV2::model::DdsqlTabularQueryResponseType::UnparsedObject(_type_) => { + _unparsed = true; + }, + _ => {} + } + } + } + &_ => { + if let Ok(value) = serde_json::from_value(v.clone()) { + additional_properties.insert(k, value); + } + } + } + } + let attributes = attributes.ok_or_else(|| M::Error::missing_field("attributes"))?; + let id = id.ok_or_else(|| M::Error::missing_field("id"))?; + let type_ = type_.ok_or_else(|| M::Error::missing_field("type_"))?; + + let content = DdsqlTabularQueryResponseData { + attributes, + id, + type_, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(DdsqlTabularQueryResponseDataVisitor) + } +} diff --git a/src/datadogV2/model/model_ddsql_tabular_query_response_meta.rs b/src/datadogV2/model/model_ddsql_tabular_query_response_meta.rs new file mode 100644 index 000000000..e244124e4 --- /dev/null +++ b/src/datadogV2/model/model_ddsql_tabular_query_response_meta.rs @@ -0,0 +1,104 @@ +// 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. +use serde::de::{Error, MapAccess, Visitor}; +use serde::{Deserialize, Deserializer, Serialize}; +use serde_with::skip_serializing_none; +use std::fmt::{self, Formatter}; + +/// Top-level JSON:API meta block accompanying every DDSQL tabular query response. +/// Carries standard observability handles for client-side correlation. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct DdsqlTabularQueryResponseMeta { + /// Server-side time spent serving this request, in milliseconds. + #[serde(rename = "elapsed")] + pub elapsed: i64, + /// Echo of the `DD-Request-ID` header assigned by Datadog's edge to this request, + /// for support correlation. + #[serde(rename = "request_id")] + pub request_id: String, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl DdsqlTabularQueryResponseMeta { + pub fn new(elapsed: i64, request_id: String) -> DdsqlTabularQueryResponseMeta { + DdsqlTabularQueryResponseMeta { + elapsed, + request_id, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl<'de> Deserialize<'de> for DdsqlTabularQueryResponseMeta { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct DdsqlTabularQueryResponseMetaVisitor; + impl<'a> Visitor<'a> for DdsqlTabularQueryResponseMetaVisitor { + type Value = DdsqlTabularQueryResponseMeta; + + fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str("a mapping") + } + + fn visit_map(self, mut map: M) -> Result + where + M: MapAccess<'a>, + { + let mut elapsed: Option = None; + let mut request_id: Option = None; + let mut additional_properties: std::collections::BTreeMap< + String, + serde_json::Value, + > = std::collections::BTreeMap::new(); + let mut _unparsed = false; + + while let Some((k, v)) = map.next_entry::()? { + match k.as_str() { + "elapsed" => { + elapsed = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "request_id" => { + request_id = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + &_ => { + if let Ok(value) = serde_json::from_value(v.clone()) { + additional_properties.insert(k, value); + } + } + } + } + let elapsed = elapsed.ok_or_else(|| M::Error::missing_field("elapsed"))?; + let request_id = request_id.ok_or_else(|| M::Error::missing_field("request_id"))?; + + let content = DdsqlTabularQueryResponseMeta { + elapsed, + request_id, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(DdsqlTabularQueryResponseMetaVisitor) + } +} diff --git a/src/datadogV2/model/model_ddsql_tabular_query_response_type.rs b/src/datadogV2/model/model_ddsql_tabular_query_response_type.rs new file mode 100644 index 000000000..1439f1bb6 --- /dev/null +++ b/src/datadogV2/model/model_ddsql_tabular_query_response_type.rs @@ -0,0 +1,48 @@ +// 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. + +use serde::{Deserialize, Deserializer, Serialize, Serializer}; + +#[non_exhaustive] +#[derive(Clone, Debug, Eq, PartialEq)] +pub enum DdsqlTabularQueryResponseType { + DDSQL_QUERY_RESPONSE, + UnparsedObject(crate::datadog::UnparsedObject), +} + +impl ToString for DdsqlTabularQueryResponseType { + fn to_string(&self) -> String { + match self { + Self::DDSQL_QUERY_RESPONSE => String::from("ddsql_query_response"), + Self::UnparsedObject(v) => v.value.to_string(), + } + } +} + +impl Serialize for DdsqlTabularQueryResponseType { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + match self { + Self::UnparsedObject(v) => v.serialize(serializer), + _ => serializer.serialize_str(self.to_string().as_str()), + } + } +} + +impl<'de> Deserialize<'de> for DdsqlTabularQueryResponseType { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + let s: String = String::deserialize(deserializer)?; + Ok(match s.as_str() { + "ddsql_query_response" => Self::DDSQL_QUERY_RESPONSE, + _ => Self::UnparsedObject(crate::datadog::UnparsedObject { + value: serde_json::Value::String(s.into()), + }), + }) + } +} diff --git a/src/datadogV2/model/model_ddsql_tabular_query_state.rs b/src/datadogV2/model/model_ddsql_tabular_query_state.rs new file mode 100644 index 000000000..88c21bd59 --- /dev/null +++ b/src/datadogV2/model/model_ddsql_tabular_query_state.rs @@ -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. + +use serde::{Deserialize, Deserializer, Serialize, Serializer}; + +#[non_exhaustive] +#[derive(Clone, Debug, Eq, PartialEq)] +pub enum DdsqlTabularQueryState { + RUNNING, + COMPLETED, + UnparsedObject(crate::datadog::UnparsedObject), +} + +impl ToString for DdsqlTabularQueryState { + fn to_string(&self) -> String { + match self { + Self::RUNNING => String::from("running"), + Self::COMPLETED => String::from("completed"), + Self::UnparsedObject(v) => v.value.to_string(), + } + } +} + +impl Serialize for DdsqlTabularQueryState { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + match self { + Self::UnparsedObject(v) => v.serialize(serializer), + _ => serializer.serialize_str(self.to_string().as_str()), + } + } +} + +impl<'de> Deserialize<'de> for DdsqlTabularQueryState { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + let s: String = String::deserialize(deserializer)?; + Ok(match s.as_str() { + "running" => Self::RUNNING, + "completed" => Self::COMPLETED, + _ => Self::UnparsedObject(crate::datadog::UnparsedObject { + value: serde_json::Value::String(s.into()), + }), + }) + } +} diff --git a/src/datadogV2/model/model_ddsql_tabular_query_time_window.rs b/src/datadogV2/model/model_ddsql_tabular_query_time_window.rs new file mode 100644 index 000000000..a8c1e5a50 --- /dev/null +++ b/src/datadogV2/model/model_ddsql_tabular_query_time_window.rs @@ -0,0 +1,109 @@ +// 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. +use serde::de::{Error, MapAccess, Visitor}; +use serde::{Deserialize, Deserializer, Serialize}; +use serde_with::skip_serializing_none; +use std::fmt::{self, Formatter}; + +/// 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. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct DdsqlTabularQueryTimeWindow { + /// Start of the query window (inclusive), in Unix milliseconds since the epoch. + #[serde(rename = "from_timestamp")] + pub from_timestamp: i64, + /// End of the query window (exclusive), in Unix milliseconds since the epoch. + #[serde(rename = "to_timestamp")] + pub to_timestamp: i64, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl DdsqlTabularQueryTimeWindow { + pub fn new(from_timestamp: i64, to_timestamp: i64) -> DdsqlTabularQueryTimeWindow { + DdsqlTabularQueryTimeWindow { + from_timestamp, + to_timestamp, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl<'de> Deserialize<'de> for DdsqlTabularQueryTimeWindow { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct DdsqlTabularQueryTimeWindowVisitor; + impl<'a> Visitor<'a> for DdsqlTabularQueryTimeWindowVisitor { + type Value = DdsqlTabularQueryTimeWindow; + + fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str("a mapping") + } + + fn visit_map(self, mut map: M) -> Result + where + M: MapAccess<'a>, + { + let mut from_timestamp: Option = None; + let mut to_timestamp: Option = None; + let mut additional_properties: std::collections::BTreeMap< + String, + serde_json::Value, + > = std::collections::BTreeMap::new(); + let mut _unparsed = false; + + while let Some((k, v)) = map.next_entry::()? { + match k.as_str() { + "from_timestamp" => { + from_timestamp = + Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "to_timestamp" => { + to_timestamp = + Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + &_ => { + if let Ok(value) = serde_json::from_value(v.clone()) { + additional_properties.insert(k, value); + } + } + } + } + let from_timestamp = + from_timestamp.ok_or_else(|| M::Error::missing_field("from_timestamp"))?; + let to_timestamp = + to_timestamp.ok_or_else(|| M::Error::missing_field("to_timestamp"))?; + + let content = DdsqlTabularQueryTimeWindow { + from_timestamp, + to_timestamp, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(DdsqlTabularQueryTimeWindowVisitor) + } +} diff --git a/tests/scenarios/function_mappings.rs b/tests/scenarios/function_mappings.rs index 9732c15b3..1b0593b3c 100644 --- a/tests/scenarios/function_mappings.rs +++ b/tests/scenarios/function_mappings.rs @@ -102,6 +102,7 @@ pub struct ApiInstances { pub v2_api_dashboards: Option, pub v2_api_data_observability: Option, pub v2_api_datasets: Option, + pub v2_api_ddsql: Option, pub v2_api_data_deletion: Option, pub v2_api_deployment_gates: Option, pub v2_api_domain_allowlist: Option, @@ -860,6 +861,13 @@ pub fn initialize_api_instance(world: &mut DatadogWorld, api: String) { ), ); } + "DDSQL" => { + world.api_instances.v2_api_ddsql = + Some(datadogV2::api_ddsql::DDSQLAPI::with_client_and_config( + world.config.clone(), + world.http_client.as_ref().unwrap().clone(), + )); + } "DataDeletion" => { world.api_instances.v2_api_data_deletion = Some( datadogV2::api_data_deletion::DataDeletionAPI::with_client_and_config( @@ -4589,6 +4597,14 @@ pub fn collect_function_calls(world: &mut DatadogWorld) { world .function_mappings .insert("v2.UpdateDataset".into(), test_v2_update_dataset); + world.function_mappings.insert( + "v2.ExecuteDdsqlTabularQuery".into(), + test_v2_execute_ddsql_tabular_query, + ); + world.function_mappings.insert( + "v2.FetchDdsqlTabularQuery".into(), + test_v2_fetch_ddsql_tabular_query, + ); world.function_mappings.insert( "v2.CreateDataDeletionRequest".into(), test_v2_create_data_deletion_request, @@ -34885,6 +34901,62 @@ fn test_v2_update_dataset(world: &mut DatadogWorld, _parameters: &HashMap, +) { + let api = world + .api_instances + .v2_api_ddsql + .as_ref() + .expect("api instance not found"); + let body = serde_json::from_value(_parameters.get("body").unwrap().clone()).unwrap(); + let response = match block_on(api.execute_ddsql_tabular_query_with_http_info(body)) { + Ok(response) => response, + Err(error) => { + return match error { + Error::ResponseError(e) => { + world.response.code = e.status.as_u16(); + if let Some(entity) = e.entity { + world.response.object = serde_json::to_value(entity).unwrap(); + } + } + _ => panic!("error parsing response: {error}"), + }; + } + }; + world.response.object = serde_json::to_value(response.entity).unwrap(); + world.response.code = response.status.as_u16(); +} + +fn test_v2_fetch_ddsql_tabular_query( + world: &mut DatadogWorld, + _parameters: &HashMap, +) { + let api = world + .api_instances + .v2_api_ddsql + .as_ref() + .expect("api instance not found"); + let body = serde_json::from_value(_parameters.get("body").unwrap().clone()).unwrap(); + let response = match block_on(api.fetch_ddsql_tabular_query_with_http_info(body)) { + Ok(response) => response, + Err(error) => { + return match error { + Error::ResponseError(e) => { + world.response.code = e.status.as_u16(); + if let Some(entity) = e.entity { + world.response.object = serde_json::to_value(entity).unwrap(); + } + } + _ => panic!("error parsing response: {error}"), + }; + } + }; + world.response.object = serde_json::to_value(response.entity).unwrap(); + world.response.code = response.status.as_u16(); +} + fn test_v2_create_data_deletion_request( world: &mut DatadogWorld, _parameters: &HashMap,