@@ -20,6 +20,7 @@ use std::fmt::Debug;
20
20
21
21
use anyhow:: anyhow;
22
22
use async_trait:: async_trait;
23
+ use aws_sdk_glue:: operation:: create_table:: CreateTableError ;
23
24
use aws_sdk_glue:: operation:: update_table:: UpdateTableError ;
24
25
use aws_sdk_glue:: types:: TableInput ;
25
26
use iceberg:: io:: {
@@ -700,7 +701,7 @@ impl Catalog for GlueCatalog {
700
701
}
701
702
}
702
703
703
- /// Asynchronously registers an existing table into the Glue Catalog.
704
+ /// registers an existing table into the Glue Catalog.
704
705
///
705
706
/// Converts the provided table identifier and metadata location into a
706
707
/// Glue-compatible table representation, and attempts to create the
@@ -713,12 +714,11 @@ impl Catalog for GlueCatalog {
713
714
/// an `Err(...)` is returned.
714
715
async fn register_table (
715
716
& self ,
716
- table : & TableIdent ,
717
+ table_ident : & TableIdent ,
717
718
metadata_location : String ,
718
719
) -> Result < Table > {
719
- let db_name = validate_namespace ( table. namespace ( ) ) ?;
720
- let table_name = table. name ( ) ;
721
-
720
+ let db_name = validate_namespace ( table_ident. namespace ( ) ) ?;
721
+ let table_name = table_ident. name ( ) ;
722
722
let metadata = TableMetadata :: read_from ( & self . file_io , & metadata_location) . await ?;
723
723
724
724
let table_input = convert_to_glue_table (
@@ -737,38 +737,34 @@ impl Catalog for GlueCatalog {
737
737
. table_input ( table_input) ;
738
738
let builder = with_catalog_id ! ( builder, self . config) ;
739
739
740
- let result = builder. send ( ) . await ;
741
-
742
- match result {
743
- Ok ( _) => {
744
- self . load_table ( table) . await . map_err ( |e| {
745
- Error :: new (
746
- ErrorKind :: Unexpected ,
747
- format ! (
748
- "Table {}.{} created but failed to load: {e}" ,
749
- db_name, table_name
750
- ) ,
751
- )
752
- } )
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
+ ) ,
753
758
}
754
- Err ( err ) => {
755
- let service_err = err . as_service_error ( ) ;
759
+ . with_source ( anyhow ! ( "aws sdk error: {:?}" , error ) )
760
+ } ) ? ;
756
761
757
- if service_err. map ( |e| e. is_entity_not_found_exception ( ) ) == Some ( true ) {
758
- Err ( Error :: new (
759
- ErrorKind :: NamespaceNotFound ,
760
- format ! ( "Database {} does not exist" , db_name) ,
761
- ) )
762
- } else if service_err. map ( |e| e. is_already_exists_exception ( ) ) == Some ( true ) {
763
- Err ( Error :: new (
764
- ErrorKind :: TableAlreadyExists ,
765
- format ! ( "Table {}.{} already exists" , db_name, table_name) ,
766
- ) )
767
- } else {
768
- Err ( from_aws_sdk_error ( err) )
769
- }
770
- }
771
- }
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 ( ) ?)
772
768
}
773
769
774
770
async fn update_table ( & self , commit : TableCommit ) -> Result < Table > {
0 commit comments