|
1 | 1 | /* |
2 | 2 | * Hotdata API |
3 | 3 | * |
4 | | - * Powerful data platform API for datasets, queries, and analytics. |
| 4 | + * Powerful data platform API for managed databases, queries, and analytics. |
5 | 5 | * |
6 | 6 | * The version of the OpenAPI document: 1.0.0 |
7 | 7 | * Contact: developers@hotdata.dev |
@@ -84,6 +84,16 @@ pub enum ListDatabasesError { |
84 | 84 | UnknownValue(serde_json::Value), |
85 | 85 | } |
86 | 86 |
|
| 87 | +/// struct for typed errors of method [`load_database_table`] |
| 88 | +#[derive(Debug, Clone, Serialize, Deserialize)] |
| 89 | +#[serde(untagged)] |
| 90 | +pub enum LoadDatabaseTableError { |
| 91 | + Status400(models::ApiErrorResponse), |
| 92 | + Status404(models::ApiErrorResponse), |
| 93 | + Status409(models::ApiErrorResponse), |
| 94 | + UnknownValue(serde_json::Value), |
| 95 | +} |
| 96 | + |
87 | 97 | /// Declare a new schema (and optionally its tables) on the database's auto-created default catalog after creation. The schema becomes reachable inside the database scope (e.g. `default.<schema>.<table>` and `information_schema.schemata`) without the caller addressing the internal default connection directly. Identifiers are normalized to lowercase. |
88 | 98 | pub async fn add_database_schema( |
89 | 99 | configuration: &configuration::Configuration, |
@@ -597,3 +607,81 @@ pub async fn list_databases( |
597 | 607 | })) |
598 | 608 | } |
599 | 609 | } |
| 610 | + |
| 611 | +/// Publish a previously-uploaded file as the new contents of a table on the database's default catalog. The database-scoped equivalent of the connection-scoped managed-table load — addressed by `database_id`, so no `default_connection_id` is needed. CSV, JSON, and Parquet uploads are supported; the format is auto-detected or set via `format`. Only `mode = \"replace\"` is supported. Concurrent loads against the same upload return 409. |
| 612 | +pub async fn load_database_table( |
| 613 | + configuration: &configuration::Configuration, |
| 614 | + database_id: &str, |
| 615 | + schema: &str, |
| 616 | + table: &str, |
| 617 | + load_managed_table_request: models::LoadManagedTableRequest, |
| 618 | +) -> Result<models::LoadManagedTableResponse, Error<LoadDatabaseTableError>> { |
| 619 | + // add a prefix to parameters to efficiently prevent name collisions |
| 620 | + let p_path_database_id = database_id; |
| 621 | + let p_path_schema = schema; |
| 622 | + let p_path_table = table; |
| 623 | + let p_body_load_managed_table_request = load_managed_table_request; |
| 624 | + |
| 625 | + let uri_str = format!( |
| 626 | + "{}/v1/databases/{database_id}/schemas/{schema}/tables/{table}/loads", |
| 627 | + configuration.base_path, |
| 628 | + database_id = crate::apis::urlencode(p_path_database_id), |
| 629 | + schema = crate::apis::urlencode(p_path_schema), |
| 630 | + table = crate::apis::urlencode(p_path_table) |
| 631 | + ); |
| 632 | + let mut req_builder = configuration |
| 633 | + .client |
| 634 | + .request(reqwest::Method::POST, &uri_str); |
| 635 | + |
| 636 | + if let Some(ref user_agent) = configuration.user_agent { |
| 637 | + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); |
| 638 | + } |
| 639 | + if let Some(apikey) = configuration.api_keys.get("X-Workspace-Id") { |
| 640 | + let key = apikey.key.clone(); |
| 641 | + let value = match apikey.prefix { |
| 642 | + Some(ref prefix) => format!("{} {}", prefix, key), |
| 643 | + None => key, |
| 644 | + }; |
| 645 | + req_builder = req_builder.header("X-Workspace-Id", value); |
| 646 | + }; |
| 647 | + if let Some(token) = configuration.resolve_bearer_token().await { |
| 648 | + req_builder = req_builder.bearer_auth(token); |
| 649 | + }; |
| 650 | + req_builder = req_builder.json(&p_body_load_managed_table_request); |
| 651 | + |
| 652 | + let req = req_builder.build()?; |
| 653 | + crate::http_log::log_request(&req); |
| 654 | + // Route through the shared retry helper so HTTP 429 (OVERLOADED admission |
| 655 | + // shedding) is retried per `configuration.retry` on every generated op, not |
| 656 | + // just the hand-written query path. See crate::http::execute_retrying. |
| 657 | + let resp = |
| 658 | + crate::http::execute_retrying(&configuration.client, req, &configuration.retry).await?; |
| 659 | + |
| 660 | + let status = resp.status(); |
| 661 | + crate::http_log::log_response_status(status); |
| 662 | + let content_type = resp |
| 663 | + .headers() |
| 664 | + .get("content-type") |
| 665 | + .and_then(|v| v.to_str().ok()) |
| 666 | + .unwrap_or("application/octet-stream"); |
| 667 | + let content_type = super::ContentType::from(content_type); |
| 668 | + |
| 669 | + if !status.is_client_error() && !status.is_server_error() { |
| 670 | + let content = resp.text().await?; |
| 671 | + crate::http_log::log_response_body(&content); |
| 672 | + match content_type { |
| 673 | + ContentType::Json => serde_json::from_str(&content).map_err(Error::from), |
| 674 | + ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::LoadManagedTableResponse`"))), |
| 675 | + 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`")))), |
| 676 | + } |
| 677 | + } else { |
| 678 | + let content = resp.text().await?; |
| 679 | + crate::http_log::log_response_body(&content); |
| 680 | + let entity: Option<LoadDatabaseTableError> = serde_json::from_str(&content).ok(); |
| 681 | + Err(Error::ResponseError(ResponseContent { |
| 682 | + status, |
| 683 | + content, |
| 684 | + entity, |
| 685 | + })) |
| 686 | + } |
| 687 | +} |
0 commit comments