Skip to content

Commit 993c707

Browse files
committed
address pr comments
- removed unnecessary wording in function documentation comments - renamed `table_ident` parameter - replaced `load_table()` with `Table::builder()` - attached source error using `.with_source(e)` - restructured error handling to follow `update_table()` pattern
1 parent fcfc8e3 commit 993c707

File tree

2 files changed

+66
-7
lines changed

2 files changed

+66
-7
lines changed

crates/catalog/glue/src/catalog.rs

Lines changed: 62 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use std::fmt::Debug;
2020

2121
use anyhow::anyhow;
2222
use async_trait::async_trait;
23+
use aws_sdk_glue::operation::create_table::CreateTableError;
2324
use aws_sdk_glue::operation::update_table::UpdateTableError;
2425
use aws_sdk_glue::types::TableInput;
2526
use iceberg::io::{
@@ -700,15 +701,70 @@ impl Catalog for GlueCatalog {
700701
}
701702
}
702703

704+
/// registers an existing table into the Glue Catalog.
705+
///
706+
/// Converts the provided table identifier and metadata location into a
707+
/// Glue-compatible table representation, and attempts to create the
708+
/// corresponding table in the Glue Catalog.
709+
///
710+
/// # Returns
711+
/// Returns `Ok(Table)` if the table is successfully registered and loaded.
712+
/// If the registration fails due to validation issues, existing table conflicts,
713+
/// metadata problems, or errors during the registration or loading process,
714+
/// an `Err(...)` is returned.
703715
async fn register_table(
704716
&self,
705-
_table_ident: &TableIdent,
706-
_metadata_location: String,
717+
table_ident: &TableIdent,
718+
metadata_location: String,
707719
) -> Result<Table> {
708-
Err(Error::new(
709-
ErrorKind::FeatureUnsupported,
710-
"Registering a table is not supported yet",
711-
))
720+
let db_name = validate_namespace(table_ident.namespace())?;
721+
let table_name = table_ident.name();
722+
let metadata = TableMetadata::read_from(&self.file_io, &metadata_location).await?;
723+
724+
let table_input = convert_to_glue_table(
725+
table_name,
726+
metadata_location.clone(),
727+
&metadata,
728+
metadata.properties(),
729+
None,
730+
)?;
731+
732+
let builder = self
733+
.client
734+
.0
735+
.create_table()
736+
.database_name(&db_name)
737+
.table_input(table_input);
738+
let builder = with_catalog_id!(builder, self.config);
739+
740+
builder.send().await.map_err(|e| {
741+
let error = e.into_service_error();
742+
match error {
743+
CreateTableError::EntityNotFoundException(_) => Error::new(
744+
ErrorKind::NamespaceNotFound,
745+
format!("Database {} does not exist", db_name),
746+
),
747+
CreateTableError::AlreadyExistsException(_) => Error::new(
748+
ErrorKind::TableAlreadyExists,
749+
format!("Table {}.{} already exists", db_name, table_name),
750+
),
751+
_ => Error::new(
752+
ErrorKind::Unexpected,
753+
format!(
754+
"Failed to register table {}.{} due to AWS SDK error",
755+
db_name, table_name
756+
),
757+
),
758+
}
759+
.with_source(anyhow!("aws sdk error: {:?}", error))
760+
})?;
761+
762+
Ok(Table::builder()
763+
.identifier(table_ident.clone())
764+
.metadata_location(metadata_location)
765+
.metadata(metadata)
766+
.file_io(self.file_io())
767+
.build()?)
712768
}
713769

714770
async fn update_table(&self, commit: TableCommit) -> Result<Table> {

crates/catalog/glue/tests/glue_catalog_test.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,10 @@ async fn test_register_table() -> Result<()> {
476476
let namespace = NamespaceIdent::new("test_register_table".into());
477477
set_test_namespace(&catalog, &namespace).await?;
478478

479-
let creation = set_table_creation(Some("s3a://warehouse/hive/test_register_table".into()), "my_table")?;
479+
let creation = set_table_creation(
480+
Some("s3a://warehouse/hive/test_register_table".into()),
481+
"my_table",
482+
)?;
480483
let table = catalog.create_table(&namespace, creation).await?;
481484
let metadata_location = table
482485
.metadata_location()

0 commit comments

Comments
 (0)