Skip to main content

unitycatalog_client/codegen/tables/
client.rs

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