Skip to main content

unitycatalog_client/codegen/tables/
client.rs

1// @generated — do not edit by hand.
2#![allow(unused_imports)]
3use crate::Result;
4use olai_http::CloudClient;
5use unitycatalog_common::models::tables::v1::*;
6use url::Url;
7/// HTTP client for service operations
8#[derive(Clone)]
9pub struct TableServiceClient {
10    pub(crate) client: CloudClient,
11    pub(crate) base_url: Url,
12}
13impl TableServiceClient {
14    /// Create a new client instance
15    pub fn new(client: CloudClient, mut base_url: Url) -> Self {
16        if !base_url.path().ends_with('/') {
17            base_url.set_path(&format!("{}/", base_url.path()));
18        }
19        Self { client, base_url }
20    }
21    /// Gets an array of summaries for tables for a schema and catalog within the metastore. The table summaries returned are either:
22    /// - summaries for tables (within the current metastore and parent catalog and schema), when the user is a metastore admin, or:
23    /// - summaries for tables and schemas (within the current metastore and parent catalog) for which the user has ownership or the
24    /// SELECT privilege on the table and ownership or USE_SCHEMA privilege on the schema, provided that the user also has ownership
25    /// or the USE_CATALOG privilege on the parent catalog.
26    ///
27    /// There is no guarantee of a specific ordering of the elements in the array.
28    pub async fn list_table_summaries(
29        &self,
30        request: &ListTableSummariesRequest,
31    ) -> Result<ListTableSummariesResponse> {
32        let mut url = self.base_url.join("table-summaries")?;
33        url.query_pairs_mut()
34            .append_pair("catalog_name", &request.catalog_name);
35        if let Some(ref value) = request.schema_name_pattern {
36            url.query_pairs_mut()
37                .append_pair("schema_name_pattern", &value.to_string());
38        }
39        if let Some(ref value) = request.table_name_pattern {
40            url.query_pairs_mut()
41                .append_pair("table_name_pattern", &value.to_string());
42        }
43        if let Some(ref value) = request.max_results {
44            url.query_pairs_mut()
45                .append_pair("max_results", &value.to_string());
46        }
47        if let Some(ref value) = request.page_token {
48            url.query_pairs_mut()
49                .append_pair("page_token", &value.to_string());
50        }
51        if let Some(ref value) = request.include_manifest_capabilities {
52            url.query_pairs_mut()
53                .append_pair("include_manifest_capabilities", &value.to_string());
54        }
55        let response = self.client.get(url).send().await?;
56        if !response.status().is_success() {
57            return Err(crate::error::parse_error_response(response).await);
58        }
59        let result = response.bytes().await?;
60        Ok(serde_json::from_slice(&result)?)
61    }
62    /// Gets an array of all tables for the current metastore under the parent catalog and schema.
63    ///
64    /// The caller must be a metastore admin or an owner of (or have the SELECT privilege on) the table.
65    /// For the latter case, the caller must also be the owner or have the USE_CATALOG privilege on the
66    /// parent catalog and the USE_SCHEMA privilege on the parent schema. There is no guarantee of a
67    /// specific ordering of the elements in the array.
68    pub async fn list_tables(&self, request: &ListTablesRequest) -> Result<ListTablesResponse> {
69        let mut url = self.base_url.join("tables")?;
70        url.query_pairs_mut()
71            .append_pair("catalog_name", &request.catalog_name);
72        url.query_pairs_mut()
73            .append_pair("schema_name", &request.schema_name);
74        if let Some(ref value) = request.max_results {
75            url.query_pairs_mut()
76                .append_pair("max_results", &value.to_string());
77        }
78        if let Some(ref value) = request.page_token {
79            url.query_pairs_mut()
80                .append_pair("page_token", &value.to_string());
81        }
82        if let Some(ref value) = request.include_delta_metadata {
83            url.query_pairs_mut()
84                .append_pair("include_delta_metadata", &value.to_string());
85        }
86        if let Some(ref value) = request.omit_columns {
87            url.query_pairs_mut()
88                .append_pair("omit_columns", &value.to_string());
89        }
90        if let Some(ref value) = request.omit_properties {
91            url.query_pairs_mut()
92                .append_pair("omit_properties", &value.to_string());
93        }
94        if let Some(ref value) = request.omit_username {
95            url.query_pairs_mut()
96                .append_pair("omit_username", &value.to_string());
97        }
98        if let Some(ref value) = request.include_browse {
99            url.query_pairs_mut()
100                .append_pair("include_browse", &value.to_string());
101        }
102        if let Some(ref value) = request.include_manifest_capabilities {
103            url.query_pairs_mut()
104                .append_pair("include_manifest_capabilities", &value.to_string());
105        }
106        let response = self.client.get(url).send().await?;
107        if !response.status().is_success() {
108            return Err(crate::error::parse_error_response(response).await);
109        }
110        let result = response.bytes().await?;
111        Ok(serde_json::from_slice(&result)?)
112    }
113    /// Create a table
114    pub async fn create_table(&self, request: &CreateTableRequest) -> Result<Table> {
115        let url = self.base_url.join("tables")?;
116        let response = self.client.post(url).json(request).send().await?;
117        if !response.status().is_success() {
118            return Err(crate::error::parse_error_response(response).await);
119        }
120        let result = response.bytes().await?;
121        Ok(serde_json::from_slice(&result)?)
122    }
123    /// Get a table
124    pub async fn get_table(&self, request: &GetTableRequest) -> Result<Table> {
125        let formatted_path = format!("tables/{}", request.full_name);
126        let mut url = self.base_url.join(&formatted_path)?;
127        if let Some(ref value) = request.include_delta_metadata {
128            url.query_pairs_mut()
129                .append_pair("include_delta_metadata", &value.to_string());
130        }
131        if let Some(ref value) = request.include_browse {
132            url.query_pairs_mut()
133                .append_pair("include_browse", &value.to_string());
134        }
135        if let Some(ref value) = request.include_manifest_capabilities {
136            url.query_pairs_mut()
137                .append_pair("include_manifest_capabilities", &value.to_string());
138        }
139        let response = self.client.get(url).send().await?;
140        if !response.status().is_success() {
141            return Err(crate::error::parse_error_response(response).await);
142        }
143        let result = response.bytes().await?;
144        Ok(serde_json::from_slice(&result)?)
145    }
146    /// Get boolean reflecting if table exists
147    pub async fn get_table_exists(
148        &self,
149        request: &GetTableExistsRequest,
150    ) -> Result<GetTableExistsResponse> {
151        let formatted_path = format!("tables/{}/exists", request.full_name);
152        let url = self.base_url.join(&formatted_path)?;
153        let response = self.client.get(url).send().await?;
154        if !response.status().is_success() {
155            return Err(crate::error::parse_error_response(response).await);
156        }
157        let result = response.bytes().await?;
158        Ok(serde_json::from_slice(&result)?)
159    }
160    /// Delete a table
161    pub async fn delete_table(&self, request: &DeleteTableRequest) -> Result<()> {
162        let formatted_path = format!("tables/{}", request.full_name);
163        let url = self.base_url.join(&formatted_path)?;
164        let response = self.client.delete(url).send().await?;
165        if !response.status().is_success() {
166            return Err(crate::error::parse_error_response(response).await);
167        }
168        Ok(())
169    }
170}