Skip to main content

unitycatalog_client/codegen/functions/
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::functions::v1::*;
9use url::Url;
10/// HTTP client for service operations
11#[derive(Clone)]
12pub struct FunctionServiceClient {
13    pub(crate) client: Transport,
14    pub(crate) base_url: Url,
15}
16impl FunctionServiceClient {
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    /// List functions
25    ///
26    /// List functions within the specified parent catalog and schema. If the caller is the metastore
27    /// admin, all functions are returned in the response. Otherwise, the caller must have USE_CATALOG
28    /// on the parent catalog and USE_SCHEMA on the parent schema, and the function must either be
29    /// owned by the caller or have SELECT on the function.
30    pub async fn list_functions(
31        &self,
32        request: &ListFunctionsRequest,
33    ) -> Result<ListFunctionsResponse> {
34        let mut url = self.base_url.join("functions")?;
35        url.query_pairs_mut()
36            .append_pair("catalog_name", &request.catalog_name);
37        url.query_pairs_mut()
38            .append_pair("schema_name", &request.schema_name);
39        if let Some(ref value) = request.max_results {
40            url.query_pairs_mut()
41                .append_pair("max_results", &value.to_string());
42        }
43        if let Some(ref value) = request.page_token {
44            url.query_pairs_mut()
45                .append_pair("page_token", &value.to_string());
46        }
47        if let Some(ref value) = request.include_browse {
48            url.query_pairs_mut()
49                .append_pair("include_browse", &value.to_string());
50        }
51        let response = self.client.get(url).send().await?;
52        if !response.status().is_success() {
53            return Err(crate::error::parse_error_response(response).await);
54        }
55        let result = response.bytes().await?;
56        Ok(serde_json::from_slice(&result)?)
57    }
58    /// Create a function
59    ///
60    /// Creates a new function. The caller must be a metastore admin or have the CREATE_FUNCTION
61    /// privilege on the parent catalog and schema.
62    pub async fn create_function(&self, request: &CreateFunctionRequest) -> Result<Function> {
63        let url = self.base_url.join("functions")?;
64        let response = self.client.post(url).json(request).send().await?;
65        if !response.status().is_success() {
66            return Err(crate::error::parse_error_response(response).await);
67        }
68        let result = response.bytes().await?;
69        Ok(serde_json::from_slice(&result)?)
70    }
71    /// Get a function
72    ///
73    /// Gets a function from within a parent catalog and schema. For the fetch to succeed,
74    /// the caller must be a metastore admin, the owner of the function, or have SELECT on
75    /// the function.
76    pub async fn get_function(&self, request: &GetFunctionRequest) -> Result<Function> {
77        let formatted_path = format!("functions/{}", request.name);
78        let url = self.base_url.join(&formatted_path)?;
79        let response = self.client.get(url).send().await?;
80        if !response.status().is_success() {
81            return Err(crate::error::parse_error_response(response).await);
82        }
83        let result = response.bytes().await?;
84        Ok(serde_json::from_slice(&result)?)
85    }
86    /// Update a function
87    ///
88    /// Updates the function that matches the supplied name. Only the owner of the function
89    /// can be updated.
90    pub async fn update_function(&self, request: &UpdateFunctionRequest) -> Result<Function> {
91        let formatted_path = format!("functions/{}", request.name);
92        let url = self.base_url.join(&formatted_path)?;
93        let response = self.client.patch(url).json(request).send().await?;
94        if !response.status().is_success() {
95            return Err(crate::error::parse_error_response(response).await);
96        }
97        let result = response.bytes().await?;
98        Ok(serde_json::from_slice(&result)?)
99    }
100    /// Delete a function
101    ///
102    /// Deletes the function that matches the supplied name. For the deletion to succeed,
103    /// the caller must be the owner of the function.
104    pub async fn delete_function(&self, request: &DeleteFunctionRequest) -> Result<()> {
105        let formatted_path = format!("functions/{}", request.name);
106        let mut url = self.base_url.join(&formatted_path)?;
107        if let Some(ref value) = request.force {
108            url.query_pairs_mut()
109                .append_pair("force", &value.to_string());
110        }
111        let response = self.client.delete(url).send().await?;
112        if !response.status().is_success() {
113            return Err(crate::error::parse_error_response(response).await);
114        }
115        Ok(())
116    }
117}