Skip to main content

unitycatalog_client/codegen/delta_commits/
client.rs

1// @generated — do not edit by hand.
2#![allow(unused_imports)]
3use crate::Result;
4use olai_http::CloudClient;
5use unitycatalog_common::models::delta_commits::v1::*;
6use url::Url;
7/// HTTP client for service operations
8#[derive(Clone)]
9pub struct DeltaCommitClient {
10    pub(crate) client: CloudClient,
11    pub(crate) base_url: Url,
12}
13impl DeltaCommitClient {
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    /// Ratify a staged commit at the requested version (first-writer-wins), and/or
22    /// notify the catalog that commits have been backfilled to the Delta log.
23    pub async fn commit(&self, request: &CommitRequest) -> Result<()> {
24        let url = self.base_url.join("delta/preview/commits")?;
25        let response = self.client.post(url).json(request).send().await?;
26        if !response.status().is_success() {
27            return Err(crate::error::parse_error_response(response).await);
28        }
29        Ok(())
30    }
31    /// Return ratified-but-unpublished commits for a table, plus the latest
32    /// version the catalog tracks.
33    pub async fn get_commits(&self, request: &GetCommitsRequest) -> Result<GetCommitsResponse> {
34        let mut url = self.base_url.join("delta/preview/commits")?;
35        url.query_pairs_mut()
36            .append_pair("table_id", &request.table_id);
37        url.query_pairs_mut()
38            .append_pair("table_uri", &request.table_uri);
39        url.query_pairs_mut()
40            .append_pair("start_version", &request.start_version.to_string());
41        if let Some(ref value) = request.end_version {
42            url.query_pairs_mut()
43                .append_pair("end_version", &value.to_string());
44        }
45        let response = self.client.get(url).send().await?;
46        if !response.status().is_success() {
47            return Err(crate::error::parse_error_response(response).await);
48        }
49        let result = response.bytes().await?;
50        Ok(serde_json::from_slice(&result)?)
51    }
52}