Skip to main content

unitycatalog_client/codegen/tables/
builders.rs

1// @generated — do not edit by hand.
2#![allow(unused_mut)]
3#![allow(unused_imports)]
4#[cfg(not(target_arch = "wasm32"))]
5type BoxFut<'a, T> = ::futures::future::BoxFuture<'a, T>;
6#[cfg(target_arch = "wasm32")]
7type BoxFut<'a, T> = ::futures::future::LocalBoxFuture<'a, T>;
8#[cfg(not(target_arch = "wasm32"))]
9type BoxStr<'a, T> = ::futures::stream::BoxStream<'a, T>;
10#[cfg(target_arch = "wasm32")]
11type BoxStr<'a, T> = ::futures::stream::LocalBoxStream<'a, T>;
12use super::super::stream_paginated;
13use super::client::*;
14use crate::Result;
15use futures::{StreamExt, TryStreamExt};
16use std::future::IntoFuture;
17use unitycatalog_common::models::tables::v1::*;
18/// Builder for table summaries
19pub struct ListTableSummariesBuilder {
20    client: TableServiceClient,
21    request: ListTableSummariesRequest,
22}
23impl ListTableSummariesBuilder {
24    /// Create a new builder instance.
25    /// Obtain via the corresponding method on `TableServiceClient`.
26    pub(crate) fn new(client: TableServiceClient, catalog_name: impl Into<String>) -> Self {
27        let request = ListTableSummariesRequest {
28            catalog_name: catalog_name.into(),
29            ..Default::default()
30        };
31        Self { client, request }
32    }
33    /// A sql LIKE pattern (% and _) for schema names. All schemas will be returned if not set or empty.
34    pub fn with_schema_name_pattern(
35        mut self,
36        schema_name_pattern: impl Into<Option<String>>,
37    ) -> Self {
38        self.request.schema_name_pattern = schema_name_pattern.into();
39        self
40    }
41    /// A sql LIKE pattern (% and _) for table names. All tables will be returned if not set or empty.
42    pub fn with_table_name_pattern(
43        mut self,
44        table_name_pattern: impl Into<Option<String>>,
45    ) -> Self {
46        self.request.table_name_pattern = table_name_pattern.into();
47        self
48    }
49    /// The maximum number of results per page that should be returned.
50    pub fn with_max_results(mut self, max_results: impl Into<Option<i32>>) -> Self {
51        self.request.max_results = max_results.into();
52        self
53    }
54    /// Opaque pagination token to go to next page based on previous query.
55    pub fn with_page_token(mut self, page_token: impl Into<Option<String>>) -> Self {
56        self.request.page_token = page_token.into();
57        self
58    }
59    /// Whether to include a manifest containing capabilities the table has.
60    pub fn with_include_manifest_capabilities(
61        mut self,
62        include_manifest_capabilities: impl Into<Option<bool>>,
63    ) -> Self {
64        self.request.include_manifest_capabilities = include_manifest_capabilities.into();
65        self
66    }
67}
68impl IntoFuture for ListTableSummariesBuilder {
69    type Output = Result<ListTableSummariesResponse>;
70    type IntoFuture = BoxFut<'static, Self::Output>;
71    fn into_future(self) -> Self::IntoFuture {
72        let client = self.client;
73        let request = self.request;
74        Box::pin(async move { client.list_table_summaries(&request).await })
75    }
76}
77/// Builder for listing tables
78pub struct ListTablesBuilder {
79    client: TableServiceClient,
80    request: ListTablesRequest,
81}
82impl ListTablesBuilder {
83    /// Create a new builder instance.
84    /// Obtain via the corresponding method on `TableServiceClient`.
85    pub(crate) fn new(
86        client: TableServiceClient,
87        catalog_name: impl Into<String>,
88        schema_name: impl Into<String>,
89    ) -> Self {
90        let request = ListTablesRequest {
91            catalog_name: catalog_name.into(),
92            schema_name: schema_name.into(),
93            ..Default::default()
94        };
95        Self { client, request }
96    }
97    /// The maximum number of results per page that should be returned.
98    pub fn with_max_results(mut self, max_results: impl Into<Option<i32>>) -> Self {
99        self.request.max_results = max_results.into();
100        self
101    }
102    /// Opaque pagination token to go to next page based on previous query.
103    pub fn with_page_token(mut self, page_token: impl Into<Option<String>>) -> Self {
104        self.request.page_token = page_token.into();
105        self
106    }
107    /// Whether delta metadata should be included in the response.
108    pub fn with_include_delta_metadata(
109        mut self,
110        include_delta_metadata: impl Into<Option<bool>>,
111    ) -> Self {
112        self.request.include_delta_metadata = include_delta_metadata.into();
113        self
114    }
115    /// Whether to omit the columns of the table from the response or not.
116    pub fn with_omit_columns(mut self, omit_columns: impl Into<Option<bool>>) -> Self {
117        self.request.omit_columns = omit_columns.into();
118        self
119    }
120    /// Whether to omit the properties of the table from the response or not.
121    pub fn with_omit_properties(mut self, omit_properties: impl Into<Option<bool>>) -> Self {
122        self.request.omit_properties = omit_properties.into();
123        self
124    }
125    /// Whether to omit the username of the table (e.g. owner, updated_by, created_by) from the response or not.
126    pub fn with_omit_username(mut self, omit_username: impl Into<Option<bool>>) -> Self {
127        self.request.omit_username = omit_username.into();
128        self
129    }
130    /// Whether to include tables in the response for which the principal can only access selective metadata for
131    pub fn with_include_browse(mut self, include_browse: impl Into<Option<bool>>) -> Self {
132        self.request.include_browse = include_browse.into();
133        self
134    }
135    /// Whether to include a manifest containing capabilities the table has.
136    pub fn with_include_manifest_capabilities(
137        mut self,
138        include_manifest_capabilities: impl Into<Option<bool>>,
139    ) -> Self {
140        self.request.include_manifest_capabilities = include_manifest_capabilities.into();
141        self
142    }
143    /// Convert paginated request into stream of results
144    pub fn into_stream(self) -> BoxStr<'static, Result<Table>> {
145        let remaining = self.request.max_results;
146        let stream = stream_paginated(
147            (self, remaining),
148            move |(mut builder, mut remaining), page_token| async move {
149                builder.request.page_token = page_token;
150                let res = builder.client.list_tables(&builder.request).await?;
151                if let Some(ref mut rem) = remaining {
152                    *rem -= res.tables.len() as i32;
153                }
154                let next_page_token = if remaining.is_some_and(|r| r <= 0) {
155                    None
156                } else {
157                    res.next_page_token.clone()
158                };
159                Ok((res, (builder, remaining), next_page_token))
160            },
161        )
162        .map_ok(|resp| futures::stream::iter(resp.tables.into_iter().map(Ok)))
163        .try_flatten();
164        #[cfg(not(target_arch = "wasm32"))]
165        let stream = stream.boxed();
166        #[cfg(target_arch = "wasm32")]
167        let stream = stream.boxed_local();
168        stream
169    }
170}
171impl IntoFuture for ListTablesBuilder {
172    type Output = Result<ListTablesResponse>;
173    type IntoFuture = BoxFut<'static, Self::Output>;
174    fn into_future(self) -> Self::IntoFuture {
175        let client = self.client;
176        let request = self.request;
177        Box::pin(async move { client.list_tables(&request).await })
178    }
179}
180/// Builder for creating a table
181pub struct CreateTableBuilder {
182    client: TableServiceClient,
183    request: CreateTableRequest,
184}
185impl CreateTableBuilder {
186    /// Create a new builder instance.
187    /// Obtain via the corresponding method on `TableServiceClient`.
188    pub(crate) fn new(
189        client: TableServiceClient,
190        name: impl Into<String>,
191        schema_name: impl Into<String>,
192        catalog_name: impl Into<String>,
193        table_type: TableType,
194        data_source_format: DataSourceFormat,
195    ) -> Self {
196        let request = CreateTableRequest {
197            name: name.into(),
198            schema_name: schema_name.into(),
199            catalog_name: catalog_name.into(),
200            table_type: buffa::EnumValue::Known(table_type),
201            data_source_format: buffa::EnumValue::Known(data_source_format),
202            ..Default::default()
203        };
204        Self { client, request }
205    }
206    /// The array of Column definitions of the table's columns.
207    pub fn with_columns<I>(mut self, columns: I) -> Self
208    where
209        I: IntoIterator<Item = Column>,
210    {
211        self.request.columns = columns.into_iter().collect();
212        self
213    }
214    /// Storage root URL for external table.
215    pub fn with_storage_location(mut self, storage_location: impl Into<Option<String>>) -> Self {
216        self.request.storage_location = storage_location.into();
217        self
218    }
219    /// User-provided free-form text description.
220    pub fn with_comment(mut self, comment: impl Into<Option<String>>) -> Self {
221        self.request.comment = comment.into();
222        self
223    }
224    /// A map of key-value properties attached to the securable.
225    pub fn with_properties<I, K, V>(mut self, properties: I) -> Self
226    where
227        I: IntoIterator<Item = (K, V)>,
228        K: Into<String>,
229        V: Into<String>,
230    {
231        self.request.properties = properties
232            .into_iter()
233            .map(|(k, v)| (k.into(), v.into()))
234            .collect();
235        self
236    }
237    /** Definition text for view-like table types (VIEW, MATERIALIZED_VIEW,
238    STREAMING_TABLE, METRIC_VIEW). The format depends on the table type:
239    SQL for views, YAML for metric views. Required for METRIC_VIEW.*/
240    pub fn with_view_definition(mut self, view_definition: impl Into<Option<String>>) -> Self {
241        self.request.view_definition = view_definition.into();
242        self
243    }
244    /** Tables and functions the view-like table reads. For metric views the server
245    derives this from view_definition and rejects a supplied list that diverges
246    from the derived set (the definition is the single source of truth).*/
247    pub fn with_view_dependencies(
248        mut self,
249        view_dependencies: impl Into<Option<DependencyList>>,
250    ) -> Self {
251        self.request.view_dependencies = {
252            let view_dependencies: ::core::option::Option<_> = view_dependencies.into();
253            buffa::MessageField::from(view_dependencies)
254        };
255        self
256    }
257}
258impl IntoFuture for CreateTableBuilder {
259    type Output = Result<Table>;
260    type IntoFuture = BoxFut<'static, Self::Output>;
261    fn into_future(self) -> Self::IntoFuture {
262        let client = self.client;
263        let request = self.request;
264        Box::pin(async move { client.create_table(&request).await })
265    }
266}
267/// Builder for getting a table
268pub struct GetTableBuilder {
269    client: TableServiceClient,
270    request: GetTableRequest,
271}
272impl GetTableBuilder {
273    /// Create a new builder instance.
274    /// Obtain via the corresponding method on `TableServiceClient`.
275    pub(crate) fn new(client: TableServiceClient, full_name: impl Into<String>) -> Self {
276        let request = GetTableRequest {
277            full_name: full_name.into(),
278            ..Default::default()
279        };
280        Self { client, request }
281    }
282    /// Whether delta metadata should be included in the response.
283    pub fn with_include_delta_metadata(
284        mut self,
285        include_delta_metadata: impl Into<Option<bool>>,
286    ) -> Self {
287        self.request.include_delta_metadata = include_delta_metadata.into();
288        self
289    }
290    /// Whether to include tables in the response for which the principal can only access selective metadata for
291    pub fn with_include_browse(mut self, include_browse: impl Into<Option<bool>>) -> Self {
292        self.request.include_browse = include_browse.into();
293        self
294    }
295    /// Whether to include a manifest containing capabilities the table has.
296    pub fn with_include_manifest_capabilities(
297        mut self,
298        include_manifest_capabilities: impl Into<Option<bool>>,
299    ) -> Self {
300        self.request.include_manifest_capabilities = include_manifest_capabilities.into();
301        self
302    }
303}
304impl IntoFuture for GetTableBuilder {
305    type Output = Result<Table>;
306    type IntoFuture = BoxFut<'static, Self::Output>;
307    fn into_future(self) -> Self::IntoFuture {
308        let client = self.client;
309        let request = self.request;
310        Box::pin(async move { client.get_table(&request).await })
311    }
312}
313/// Builder for table exists
314pub struct GetTableExistsBuilder {
315    client: TableServiceClient,
316    request: GetTableExistsRequest,
317}
318impl GetTableExistsBuilder {
319    /// Create a new builder instance.
320    /// Obtain via the corresponding method on `TableServiceClient`.
321    pub(crate) fn new(client: TableServiceClient, full_name: impl Into<String>) -> Self {
322        let request = GetTableExistsRequest {
323            full_name: full_name.into(),
324            ..Default::default()
325        };
326        Self { client, request }
327    }
328}
329impl IntoFuture for GetTableExistsBuilder {
330    type Output = Result<GetTableExistsResponse>;
331    type IntoFuture = BoxFut<'static, Self::Output>;
332    fn into_future(self) -> Self::IntoFuture {
333        let client = self.client;
334        let request = self.request;
335        Box::pin(async move { client.get_table_exists(&request).await })
336    }
337}
338/// Builder for deleting a table
339pub struct DeleteTableBuilder {
340    client: TableServiceClient,
341    request: DeleteTableRequest,
342}
343impl DeleteTableBuilder {
344    /// Create a new builder instance.
345    /// Obtain via the corresponding method on `TableServiceClient`.
346    pub(crate) fn new(client: TableServiceClient, full_name: impl Into<String>) -> Self {
347        let request = DeleteTableRequest {
348            full_name: full_name.into(),
349            ..Default::default()
350        };
351        Self { client, request }
352    }
353}
354impl IntoFuture for DeleteTableBuilder {
355    type Output = Result<()>;
356    type IntoFuture = BoxFut<'static, Self::Output>;
357    fn into_future(self) -> Self::IntoFuture {
358        let client = self.client;
359        let request = self.request;
360        Box::pin(async move { client.delete_table(&request).await })
361    }
362}