Skip to main content

unitycatalog_client/codegen/functions/
client.rs

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