/*
* Hotdata API
*
* Powerful data platform API for instant databases, queries, and analytics.
*
* The version of the OpenAPI document: 1.0.0
* Contact: developers@hotdata.dev
* Generated by: https://openapi-generator.tech
*/
use super::{configuration, ContentType, Error};
use crate::{apis::ResponseContent, models};
use reqwest;
use serde::{de::Error as _, Deserialize, Serialize};
/// struct for typed errors of method [`add_managed_schema`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum AddManagedSchemaError {
Status400(models::ApiErrorResponse),
Status404(models::ApiErrorResponse),
Status409(models::ApiErrorResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`add_managed_table`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum AddManagedTableError {
Status400(models::ApiErrorResponse),
Status404(models::ApiErrorResponse),
Status409(models::ApiErrorResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`create_connection`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum CreateConnectionError {
Status400(models::ApiErrorResponse),
Status409(models::ApiErrorResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`delete_connection`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum DeleteConnectionError {
Status404(models::ApiErrorResponse),
Status409(models::ApiErrorResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`delete_managed_table`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum DeleteManagedTableError {
Status400(models::ApiErrorResponse),
Status404(models::ApiErrorResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_connection`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetConnectionError {
Status404(models::ApiErrorResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_table_profile`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetTableProfileError {
Status404(models::ApiErrorResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`list_connections`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ListConnectionsError {
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`load_managed_table`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum LoadManagedTableError {
Status400(models::ApiErrorResponse),
Status404(models::ApiErrorResponse),
Status409(models::ApiErrorResponse),
Status413(models::ApiErrorResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`set_managed_table_constant_per_key`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum SetManagedTableConstantPerKeyError {
Status400(models::ApiErrorResponse),
Status404(models::ApiErrorResponse),
Status409(models::ApiErrorResponse),
UnknownValue(serde_json::Value),
}
/// Declare a new schema (and optionally its tables) on an existing managed catalog after creation. The schema is added to the connection's declaration; declared tables can then be populated via the managed-table load endpoint. Only valid against connections whose source type is `managed`. Identifiers are normalized to lowercase.
pub async fn add_managed_schema(
configuration: &configuration::Configuration,
connection_id: &str,
add_managed_schema_request: models::AddManagedSchemaRequest,
) -> Result<models::ManagedSchemaResponse, Error<AddManagedSchemaError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_path_connection_id = connection_id;
let p_body_add_managed_schema_request = add_managed_schema_request;
let uri_str = format!(
"{}/v1/connections/{connection_id}/schemas",
configuration.base_path,
connection_id = crate::apis::urlencode(p_path_connection_id)
);
let mut req_builder = configuration
.client
.request(reqwest::Method::POST, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(apikey) = configuration.api_keys.get("X-Workspace-Id") {
let key = apikey.key.clone();
let value = match apikey.prefix {
Some(ref prefix) => format!("{} {}", prefix, key),
None => key,
};
req_builder = req_builder.header("X-Workspace-Id", value);
};
if let Some(token) = configuration.resolve_bearer_token().await {
req_builder = req_builder.bearer_auth(token);
};
req_builder = req_builder.json(&p_body_add_managed_schema_request);
let req = req_builder.build()?;
crate::http_log::log_request(&req);
// Route through the shared retry helper so HTTP 429 (OVERLOADED admission
// shedding) is retried per `configuration.retry` on every generated op, not
// just the hand-written query path. See crate::http::execute_retrying.
let resp = crate::http::execute_retrying(configuration, req).await?;
let status = resp.status();
crate::http_log::log_response_status(status);
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
crate::http_log::log_response_body(&content);
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ManagedSchemaResponse`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::ManagedSchemaResponse`")))),
}
} else {
let content = resp.text().await?;
crate::http_log::log_response_body(&content);
let entity: Option<AddManagedSchemaError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
/// Declare a new table on an existing schema of a managed catalog after creation. The table is added empty (declared-but-unloaded) and can be populated via the managed-table load endpoint. Only valid against connections whose source type is `managed`. Identifiers are normalized to lowercase.
pub async fn add_managed_table(
configuration: &configuration::Configuration,
connection_id: &str,
schema: &str,
add_managed_table_request: models::AddManagedTableRequest,
) -> Result<models::ManagedTableResponse, Error<AddManagedTableError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_path_connection_id = connection_id;
let p_path_schema = schema;
let p_body_add_managed_table_request = add_managed_table_request;
let uri_str = format!(
"{}/v1/connections/{connection_id}/schemas/{schema}/tables",
configuration.base_path,
connection_id = crate::apis::urlencode(p_path_connection_id),
schema = crate::apis::urlencode(p_path_schema)
);
let mut req_builder = configuration
.client
.request(reqwest::Method::POST, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(apikey) = configuration.api_keys.get("X-Workspace-Id") {
let key = apikey.key.clone();
let value = match apikey.prefix {
Some(ref prefix) => format!("{} {}", prefix, key),
None => key,
};
req_builder = req_builder.header("X-Workspace-Id", value);
};
if let Some(token) = configuration.resolve_bearer_token().await {
req_builder = req_builder.bearer_auth(token);
};
req_builder = req_builder.json(&p_body_add_managed_table_request);
let req = req_builder.build()?;
crate::http_log::log_request(&req);
// Route through the shared retry helper so HTTP 429 (OVERLOADED admission
// shedding) is retried per `configuration.retry` on every generated op, not
// just the hand-written query path. See crate::http::execute_retrying.
let resp = crate::http::execute_retrying(configuration, req).await?;
let status = resp.status();
crate::http_log::log_response_status(status);
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
crate::http_log::log_response_body(&content);
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ManagedTableResponse`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::ManagedTableResponse`")))),
}
} else {
let content = resp.text().await?;
crate::http_log::log_response_body(&content);
let entity: Option<AddManagedTableError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
/// Register a new database connection. Provide the source type and connection config (host, port, database, etc.). Credentials can be supplied inline (password/token fields are auto-converted to secrets) or by referencing an existing secret by name or ID. Schema discovery runs automatically after registration.
pub async fn create_connection(
configuration: &configuration::Configuration,
create_connection_request: models::CreateConnectionRequest,
) -> Result<models::CreateConnectionResponse, Error<CreateConnectionError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_body_create_connection_request = create_connection_request;
let uri_str = format!("{}/v1/connections", configuration.base_path);
let mut req_builder = configuration
.client
.request(reqwest::Method::POST, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(apikey) = configuration.api_keys.get("X-Workspace-Id") {
let key = apikey.key.clone();
let value = match apikey.prefix {
Some(ref prefix) => format!("{} {}", prefix, key),
None => key,
};
req_builder = req_builder.header("X-Workspace-Id", value);
};
if let Some(token) = configuration.resolve_bearer_token().await {
req_builder = req_builder.bearer_auth(token);
};
req_builder = req_builder.json(&p_body_create_connection_request);
let req = req_builder.build()?;
crate::http_log::log_request(&req);
// Route through the shared retry helper so HTTP 429 (OVERLOADED admission
// shedding) is retried per `configuration.retry` on every generated op, not
// just the hand-written query path. See crate::http::execute_retrying.
let resp = crate::http::execute_retrying(configuration, req).await?;
let status = resp.status();
crate::http_log::log_response_status(status);
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
crate::http_log::log_response_body(&content);
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::CreateConnectionResponse`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::CreateConnectionResponse`")))),
}
} else {
let content = resp.text().await?;
crate::http_log::log_response_body(&content);
let entity: Option<CreateConnectionError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
/// Delete a connection and its cached data.
pub async fn delete_connection(
configuration: &configuration::Configuration,
connection_id: &str,
) -> Result<(), Error<DeleteConnectionError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_path_connection_id = connection_id;
let uri_str = format!(
"{}/v1/connections/{connection_id}",
configuration.base_path,
connection_id = crate::apis::urlencode(p_path_connection_id)
);
let mut req_builder = configuration
.client
.request(reqwest::Method::DELETE, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(apikey) = configuration.api_keys.get("X-Workspace-Id") {
let key = apikey.key.clone();
let value = match apikey.prefix {
Some(ref prefix) => format!("{} {}", prefix, key),
None => key,
};
req_builder = req_builder.header("X-Workspace-Id", value);
};
if let Some(token) = configuration.resolve_bearer_token().await {
req_builder = req_builder.bearer_auth(token);
};
let req = req_builder.build()?;
crate::http_log::log_request(&req);
// Route through the shared retry helper so HTTP 429 (OVERLOADED admission
// shedding) is retried per `configuration.retry` on every generated op, not
// just the hand-written query path. See crate::http::execute_retrying.
let resp = crate::http::execute_retrying(configuration, req).await?;
let status = resp.status();
crate::http_log::log_response_status(status);
if !status.is_client_error() && !status.is_server_error() {
Ok(())
} else {
let content = resp.text().await?;
crate::http_log::log_response_body(&content);
let entity: Option<DeleteConnectionError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
/// Delete a single managed-catalog table. The table and its data are removed. Only valid against connections whose source type is `managed`.
pub async fn delete_managed_table(
configuration: &configuration::Configuration,
connection_id: &str,
schema: &str,
table: &str,
) -> Result<(), Error<DeleteManagedTableError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_path_connection_id = connection_id;
let p_path_schema = schema;
let p_path_table = table;
let uri_str = format!(
"{}/v1/connections/{connection_id}/schemas/{schema}/tables/{table}",
configuration.base_path,
connection_id = crate::apis::urlencode(p_path_connection_id),
schema = crate::apis::urlencode(p_path_schema),
table = crate::apis::urlencode(p_path_table)
);
let mut req_builder = configuration
.client
.request(reqwest::Method::DELETE, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(apikey) = configuration.api_keys.get("X-Workspace-Id") {
let key = apikey.key.clone();
let value = match apikey.prefix {
Some(ref prefix) => format!("{} {}", prefix, key),
None => key,
};
req_builder = req_builder.header("X-Workspace-Id", value);
};
if let Some(token) = configuration.resolve_bearer_token().await {
req_builder = req_builder.bearer_auth(token);
};
let req = req_builder.build()?;
crate::http_log::log_request(&req);
// Route through the shared retry helper so HTTP 429 (OVERLOADED admission
// shedding) is retried per `configuration.retry` on every generated op, not
// just the hand-written query path. See crate::http::execute_retrying.
let resp = crate::http::execute_retrying(configuration, req).await?;
let status = resp.status();
crate::http_log::log_response_status(status);
if !status.is_client_error() && !status.is_server_error() {
Ok(())
} else {
let content = resp.text().await?;
crate::http_log::log_response_body(&content);
let entity: Option<DeleteManagedTableError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
/// Get details for a specific connection, including table and sync counts.
pub async fn get_connection(
configuration: &configuration::Configuration,
connection_id: &str,
) -> Result<models::GetConnectionResponse, Error<GetConnectionError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_path_connection_id = connection_id;
let uri_str = format!(
"{}/v1/connections/{connection_id}",
configuration.base_path,
connection_id = crate::apis::urlencode(p_path_connection_id)
);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(apikey) = configuration.api_keys.get("X-Workspace-Id") {
let key = apikey.key.clone();
let value = match apikey.prefix {
Some(ref prefix) => format!("{} {}", prefix, key),
None => key,
};
req_builder = req_builder.header("X-Workspace-Id", value);
};
if let Some(token) = configuration.resolve_bearer_token().await {
req_builder = req_builder.bearer_auth(token);
};
let req = req_builder.build()?;
crate::http_log::log_request(&req);
// Route through the shared retry helper so HTTP 429 (OVERLOADED admission
// shedding) is retried per `configuration.retry` on every generated op, not
// just the hand-written query path. See crate::http::execute_retrying.
let resp = crate::http::execute_retrying(configuration, req).await?;
let status = resp.status();
crate::http_log::log_response_status(status);
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
crate::http_log::log_response_body(&content);
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetConnectionResponse`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::GetConnectionResponse`")))),
}
} else {
let content = resp.text().await?;
crate::http_log::log_response_body(&content);
let entity: Option<GetConnectionError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
/// Get column-level statistics for a synced table. Returns per-column profiles including cardinality, null counts, and type-specific details (distinct values for categorical columns, min/max for temporal/numeric, length stats for text). Profiles are computed at sync time.
pub async fn get_table_profile(
configuration: &configuration::Configuration,
connection_id: &str,
schema: &str,
table: &str,
) -> Result<models::TableProfileResponse, Error<GetTableProfileError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_path_connection_id = connection_id;
let p_path_schema = schema;
let p_path_table = table;
let uri_str = format!(
"{}/v1/connections/{connection_id}/tables/{schema}/{table}/profile",
configuration.base_path,
connection_id = crate::apis::urlencode(p_path_connection_id),
schema = crate::apis::urlencode(p_path_schema),
table = crate::apis::urlencode(p_path_table)
);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(apikey) = configuration.api_keys.get("X-Workspace-Id") {
let key = apikey.key.clone();
let value = match apikey.prefix {
Some(ref prefix) => format!("{} {}", prefix, key),
None => key,
};
req_builder = req_builder.header("X-Workspace-Id", value);
};
if let Some(token) = configuration.resolve_bearer_token().await {
req_builder = req_builder.bearer_auth(token);
};
let req = req_builder.build()?;
crate::http_log::log_request(&req);
// Route through the shared retry helper so HTTP 429 (OVERLOADED admission
// shedding) is retried per `configuration.retry` on every generated op, not
// just the hand-written query path. See crate::http::execute_retrying.
let resp = crate::http::execute_retrying(configuration, req).await?;
let status = resp.status();
crate::http_log::log_response_status(status);
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
crate::http_log::log_response_body(&content);
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::TableProfileResponse`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::TableProfileResponse`")))),
}
} else {
let content = resp.text().await?;
crate::http_log::log_response_body(&content);
let entity: Option<GetTableProfileError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
/// List all registered database connections.
pub async fn list_connections(
configuration: &configuration::Configuration,
) -> Result<models::ListConnectionsResponse, Error<ListConnectionsError>> {
let uri_str = format!("{}/v1/connections", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(apikey) = configuration.api_keys.get("X-Workspace-Id") {
let key = apikey.key.clone();
let value = match apikey.prefix {
Some(ref prefix) => format!("{} {}", prefix, key),
None => key,
};
req_builder = req_builder.header("X-Workspace-Id", value);
};
if let Some(token) = configuration.resolve_bearer_token().await {
req_builder = req_builder.bearer_auth(token);
};
let req = req_builder.build()?;
crate::http_log::log_request(&req);
// Route through the shared retry helper so HTTP 429 (OVERLOADED admission
// shedding) is retried per `configuration.retry` on every generated op, not
// just the hand-written query path. See crate::http::execute_retrying.
let resp = crate::http::execute_retrying(configuration, req).await?;
let status = resp.status();
crate::http_log::log_response_status(status);
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
crate::http_log::log_response_body(&content);
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ListConnectionsResponse`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::ListConnectionsResponse`")))),
}
} else {
let content = resp.text().await?;
crate::http_log::log_response_body(&content);
let entity: Option<ListConnectionsError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
/// Publish data as the new contents of a managed table from one of three sources — provide exactly one. With `data`, CSV text is sent inline in this request, up to 2 MiB; column types are detected from the data unless `columns` declares them, and a larger payload is rejected with 413 and the error code `INLINE_DATA_TOO_LARGE`, at which point the data should be uploaded and loaded by `upload_id` instead. With `upload_id`, a previously-uploaded file is published: CSV, JSON, and Parquet are supported; the format is auto-detected from the upload's `Content-Type` and file contents, or set explicitly via the `format` field. With `result_id`, a persisted query result is copied into the table, so the table keeps its data even after the result expires; a result can be loaded into any number of tables. If the target table (or its schema) has not been declared yet, it is created automatically as part of the load — declaring tables up front is optional. `mode` selects how the data is applied and accepts five values: `replace` makes the uploaded rows the table's entire contents, `append` inserts them on top of the existing data, and `delete`, `update`, and `upsert` match rows by key — removing, replacing, or inserting-or-replacing the matched rows respectively. The three key-matching modes need a key: the one the table was created with, or one given in `key` on the request. Concurrent loads against the same upload return 409. For an upload or inline data, set `async` to run the load in the background and get back a job ID to poll; add `async_after_ms` to wait briefly for it to finish before falling back to a job ID. A `result_id` load runs synchronously.
pub async fn load_managed_table(
configuration: &configuration::Configuration,
connection_id: &str,
schema: &str,
table: &str,
load_managed_table_request: models::LoadManagedTableRequest,
) -> Result<models::LoadManagedTableResponse, Error<LoadManagedTableError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_path_connection_id = connection_id;
let p_path_schema = schema;
let p_path_table = table;
let p_body_load_managed_table_request = load_managed_table_request;
let uri_str = format!(
"{}/v1/connections/{connection_id}/schemas/{schema}/tables/{table}/loads",
configuration.base_path,
connection_id = crate::apis::urlencode(p_path_connection_id),
schema = crate::apis::urlencode(p_path_schema),
table = crate::apis::urlencode(p_path_table)
);
let mut req_builder = configuration
.client
.request(reqwest::Method::POST, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(apikey) = configuration.api_keys.get("X-Workspace-Id") {
let key = apikey.key.clone();
let value = match apikey.prefix {
Some(ref prefix) => format!("{} {}", prefix, key),
None => key,
};
req_builder = req_builder.header("X-Workspace-Id", value);
};
if let Some(token) = configuration.resolve_bearer_token().await {
req_builder = req_builder.bearer_auth(token);
};
req_builder = req_builder.json(&p_body_load_managed_table_request);
let req = req_builder.build()?;
crate::http_log::log_request(&req);
// Route through the shared retry helper so HTTP 429 (OVERLOADED admission
// shedding) is retried per `configuration.retry` on every generated op, not
// just the hand-written query path. See crate::http::execute_retrying.
let resp = crate::http::execute_retrying(configuration, req).await?;
let status = resp.status();
crate::http_log::log_response_status(status);
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
crate::http_log::log_response_body(&content);
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::LoadManagedTableResponse`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::LoadManagedTableResponse`")))),
}
} else {
let content = resp.text().await?;
crate::http_log::log_response_body(&content);
let entity: Option<LoadManagedTableError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
/// Replace the columns a table declares constant for a given key: for every row, any other row sharing its key holds the same value of these columns. Declaring this lets a keyed mutation (`delete`, `update`, `upsert`) narrow its search for prior versions to the values the upload carries, which prunes far harder than the key alone when the key's own file statistics do not discriminate. Unlike `partition_by` and `sorted_by`, this is NOT fixed when the table is created. It changes only which files a mutation opens, never how rows are written, so nothing stored becomes wrong when it changes and a populated table can adopt it with no rewrite. It takes effect on the next load. Send an empty array to revoke it, restoring the unrestricted search — this is the way to undo a declaration that turns out to be false. **This is correctness-affecting, not a hint.** If the assertion is false, a keyed mutation supersedes one version of a key and appends beside another, silently duplicating it, and the pruning conceals its own evidence because the file holding the missed row is never opened. Declare it only where the invariant is established.
pub async fn set_managed_table_constant_per_key(
configuration: &configuration::Configuration,
connection_id: &str,
schema: &str,
table: &str,
update_managed_table_request: models::UpdateManagedTableRequest,
) -> Result<models::ManagedTableConstantPerKeyResponse, Error<SetManagedTableConstantPerKeyError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_path_connection_id = connection_id;
let p_path_schema = schema;
let p_path_table = table;
let p_body_update_managed_table_request = update_managed_table_request;
let uri_str = format!(
"{}/v1/connections/{connection_id}/schemas/{schema}/tables/{table}/constant-per-key",
configuration.base_path,
connection_id = crate::apis::urlencode(p_path_connection_id),
schema = crate::apis::urlencode(p_path_schema),
table = crate::apis::urlencode(p_path_table)
);
let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(apikey) = configuration.api_keys.get("X-Workspace-Id") {
let key = apikey.key.clone();
let value = match apikey.prefix {
Some(ref prefix) => format!("{} {}", prefix, key),
None => key,
};
req_builder = req_builder.header("X-Workspace-Id", value);
};
if let Some(token) = configuration.resolve_bearer_token().await {
req_builder = req_builder.bearer_auth(token);
};
req_builder = req_builder.json(&p_body_update_managed_table_request);
let req = req_builder.build()?;
crate::http_log::log_request(&req);
// Route through the shared retry helper so HTTP 429 (OVERLOADED admission
// shedding) is retried per `configuration.retry` on every generated op, not
// just the hand-written query path. See crate::http::execute_retrying.
let resp = crate::http::execute_retrying(configuration, req).await?;
let status = resp.status();
crate::http_log::log_response_status(status);
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
crate::http_log::log_response_body(&content);
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ManagedTableConstantPerKeyResponse`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::ManagedTableConstantPerKeyResponse`")))),
}
} else {
let content = resp.text().await?;
crate::http_log::log_response_body(&content);
let entity: Option<SetManagedTableConstantPerKeyError> =
serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}