Skip to content

feat: Glue Catalog - namespace operations (2/3) #304

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Mar 27, 2024
Prev Previous commit
Next Next commit
impl namespace_exists
  • Loading branch information
marvinlanhenke committed Mar 25, 2024
commit 73158291b17f89747824841638d6c7fc6895835a
23 changes: 21 additions & 2 deletions crates/catalog/glue/src/catalog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,27 @@ impl Catalog for GlueCatalog {
}
}

async fn namespace_exists(&self, _namespace: &NamespaceIdent) -> Result<bool> {
todo!()
async fn namespace_exists(&self, namespace: &NamespaceIdent) -> Result<bool> {
let db_name = validate_namespace(namespace)?;

let builder = self.client.0.get_database().name(&db_name);
let builder = with_catalog_id!(builder, self.config);

let resp = builder.send().await;

match resp {
Ok(_) => Ok(true),
Err(err) => {
if err
.as_service_error()
.map(|e| e.is_entity_not_found_exception())
== Some(true)
{
return Ok(false);
}
Err(from_sdk_error(err))
}
}
}

async fn update_namespace(
Expand Down
21 changes: 21 additions & 0 deletions crates/catalog/glue/tests/glue_catalog_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,27 @@ async fn set_test_fixture(func: &str) -> TestFixture {
}
}

#[tokio::test]
async fn test_namespace_exists() -> Result<()> {
let fixture = set_test_fixture("test_namespace_exists").await;

let properties = HashMap::new();
let namespace = NamespaceIdent::new("my_database".into());

let exists = fixture.glue_catalog.namespace_exists(&namespace).await?;
assert!(!exists);

fixture
.glue_catalog
.create_namespace(&namespace, properties)
.await?;

let exists = fixture.glue_catalog.namespace_exists(&namespace).await?;
assert!(exists);

Ok(())
}

#[tokio::test]
async fn test_get_namespace() -> Result<()> {
let fixture = set_test_fixture("test_get_namespace").await;
Expand Down