@@ -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,15 +701,70 @@ impl Catalog for GlueCatalog {
700
701
}
701
702
}
702
703
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.
703
715
async fn register_table (
704
716
& self ,
705
- _table_ident : & TableIdent ,
706
- _metadata_location : String ,
717
+ table_ident : & TableIdent ,
718
+ metadata_location : String ,
707
719
) -> 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 ( ) ?)
712
768
}
713
769
714
770
async fn update_table ( & self , commit : TableCommit ) -> Result < Table > {
0 commit comments