#![cfg(not(target_family = "wasm"))]
use crate::catalog::rest::IcebergRestCatalog;
use crate::catalog::{map_catalog_error, Catalog, CatalogOptions};
use crate::error::Result;
use crate::spec::{NamespaceIdent, TableCreation, TableIdent};
use crate::table::Table;
use async_trait::async_trait;
use std::collections::HashMap;
#[derive(Debug)]
pub struct S3TablesCatalog {
inner: IcebergRestCatalog,
}
impl S3TablesCatalog {
pub async fn from_arn(name: impl Into<String>, arn: impl AsRef<str>) -> Result<Self> {
let name = name.into();
let arn = arn.as_ref();
let inner = IcebergRestCatalog::from_s3_tables_arn(name, arn)
.await
.map_err(map_catalog_error)?;
Ok(Self { inner })
}
pub async fn from_arn_with_options(
name: impl Into<String>,
arn: impl AsRef<str>,
options: CatalogOptions,
) -> Result<Self> {
let name = name.into();
let arn = arn.as_ref();
let inner = IcebergRestCatalog::from_s3_tables_arn_with_options(name, arn, options)
.await
.map_err(map_catalog_error)?;
Ok(Self { inner })
}
}
#[cfg(not(target_family = "wasm"))]
#[async_trait]
impl Catalog for S3TablesCatalog {
fn file_io(&self) -> &crate::io::FileIO {
self.inner.file_io()
}
async fn create_namespace(
&self,
namespace: &NamespaceIdent,
properties: HashMap<String, String>,
) -> Result<()> {
self.inner.create_namespace(namespace, properties).await
}
async fn namespace_exists(&self, namespace: &NamespaceIdent) -> Result<bool> {
self.inner.namespace_exists(namespace).await
}
async fn list_namespaces(&self) -> Result<Vec<NamespaceIdent>> {
self.inner.list_namespaces().await
}
async fn list_tables(&self, namespace: &NamespaceIdent) -> Result<Vec<TableIdent>> {
self.inner.list_tables(namespace).await
}
async fn table_exists(&self, identifier: &TableIdent) -> Result<bool> {
self.inner.table_exists(identifier).await
}
async fn create_table(
&self,
namespace: &NamespaceIdent,
creation: TableCreation,
) -> Result<Table> {
self.inner.create_table(namespace, creation).await
}
async fn load_table(&self, identifier: &TableIdent) -> Result<Table> {
self.inner.load_table(identifier).await
}
async fn drop_table(&self, identifier: &TableIdent) -> Result<()> {
self.inner.drop_table(identifier).await
}
async fn update_table_metadata(
&self,
identifier: &TableIdent,
old_metadata_location: &str,
new_metadata_location: &str,
) -> Result<()> {
self.inner
.update_table_metadata(identifier, old_metadata_location, new_metadata_location)
.await
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_s3_tables_catalog_debug() {
let _type_check: fn(S3TablesCatalog) = |c| {
let _ = format!("{:?}", c);
};
}
}