Skip to content

Commit e459edc

Browse files
blackmwkliurenjie1024
authored andcommitted
Add catalog test suite to unify catalog's behavior. (apache#2131)
## Which issue does this PR close? - Closes apache#2086 . ## What changes are included in this PR? In this pr we introduced catalog test suite in catalog-loader, which could unify the behavior of catalogs. ## Are these changes tested? Yes. --------- Co-authored-by: Ray Liu <liurenjie2008@gmail.com> (cherry picked from commit 335961a)
1 parent 2c7aa95 commit e459edc

20 files changed

Lines changed: 1496 additions & 1757 deletions

File tree

Cargo.lock

Lines changed: 45 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ rand = "0.8.5"
110110
regex = "1.11.3"
111111
reqwest = { version = "0.12.12", default-features = false, features = ["json"] }
112112
roaring = { version = "0.11" }
113+
rstest = "0.26"
113114
fastnum = { version = "0.7", default-features = false, features = ["std", "serde"] }
114115
serde = { version = "1.0.219", features = ["rc"] }
115116
serde_bytes = "0.11.17"

crates/catalog/glue/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ iceberg = { workspace = true }
3737
iceberg-storage-opendal = { workspace = true, features = ["opendal-s3"] }
3838
serde_json = { workspace = true }
3939
tokio = { workspace = true }
40-
tracing = { workspace = true }
4140

4241
[dev-dependencies]
4342
iceberg_test_utils = { path = "../../test_utils", features = ["tests"] }

crates/catalog/glue/src/catalog.rs

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,13 @@ impl Catalog for GlueCatalog {
339339
namespace: &NamespaceIdent,
340340
properties: HashMap<String, String>,
341341
) -> Result<Namespace> {
342+
if self.namespace_exists(namespace).await? {
343+
return Err(Error::new(
344+
ErrorKind::NamespaceAlreadyExists,
345+
format!("Namespace {namespace:?} already exists"),
346+
));
347+
}
348+
342349
let db_input = convert_to_database(namespace, &properties)?;
343350

344351
let builder = self.client.0.create_database().database_input(db_input);
@@ -365,15 +372,27 @@ impl Catalog for GlueCatalog {
365372
let builder = self.client.0.get_database().name(&db_name);
366373
let builder = with_catalog_id!(builder, self.config);
367374

368-
let resp = builder.send().await.map_err(from_aws_sdk_error)?;
375+
let resp = builder.send().await.map_err(|err| {
376+
if err
377+
.as_service_error()
378+
.map(|e| e.is_entity_not_found_exception())
379+
== Some(true)
380+
{
381+
return Error::new(
382+
ErrorKind::NamespaceNotFound,
383+
format!("Namespace {namespace:?} does not exist"),
384+
);
385+
}
386+
from_aws_sdk_error(err)
387+
})?;
369388

370389
match resp.database() {
371390
Some(db) => {
372391
let namespace = convert_to_namespace(db);
373392
Ok(namespace)
374393
}
375394
None => Err(Error::new(
376-
ErrorKind::DataInvalid,
395+
ErrorKind::NamespaceNotFound,
377396
format!("Database with name: {db_name} does not exist"),
378397
)),
379398
}
@@ -429,6 +448,13 @@ impl Catalog for GlueCatalog {
429448
namespace: &NamespaceIdent,
430449
properties: HashMap<String, String>,
431450
) -> Result<()> {
451+
if !self.namespace_exists(namespace).await? {
452+
return Err(Error::new(
453+
ErrorKind::NamespaceNotFound,
454+
format!("Namespace {namespace:?} does not exist"),
455+
));
456+
}
457+
432458
let db_name = validate_namespace(namespace)?;
433459
let db_input = convert_to_database(namespace, &properties)?;
434460

@@ -456,6 +482,13 @@ impl Catalog for GlueCatalog {
456482
/// - `Err(...)` signifies failure to drop the namespace due to validation
457483
/// errors, connectivity issues, or Glue Catalog constraints.
458484
async fn drop_namespace(&self, namespace: &NamespaceIdent) -> Result<()> {
485+
if !self.namespace_exists(namespace).await? {
486+
return Err(Error::new(
487+
ErrorKind::NamespaceNotFound,
488+
format!("Namespace {namespace:?} does not exist"),
489+
));
490+
}
491+
459492
let db_name = validate_namespace(namespace)?;
460493
let table_list = self.list_tables(namespace).await?;
461494

0 commit comments

Comments
 (0)