@@ -276,6 +276,26 @@ impl Catalog for MemoryCatalog {
276276 Ok ( ( ) )
277277 }
278278
279+ async fn register_table (
280+ & self ,
281+ table_ident : & TableIdent ,
282+ metadata_location : String ,
283+ ) -> Result < Table > {
284+ let mut root_namespace_state = self . root_namespace_state . lock ( ) . await ;
285+ root_namespace_state. insert_new_table ( & table_ident. clone ( ) , metadata_location. clone ( ) ) ?;
286+
287+ let input_file = self . file_io . new_input ( metadata_location. clone ( ) ) ?;
288+ let metadata_content = input_file. read ( ) . await ?;
289+ let metadata = serde_json:: from_slice :: < TableMetadata > ( & metadata_content) ?;
290+
291+ Table :: builder ( )
292+ . file_io ( self . file_io . clone ( ) )
293+ . metadata_location ( metadata_location)
294+ . metadata ( metadata)
295+ . identifier ( table_ident. clone ( ) )
296+ . build ( )
297+ }
298+
279299 /// Update a table to the catalog.
280300 async fn update_table ( & self , _commit : TableCommit ) -> Result < Table > {
281301 Err ( Error :: new (
@@ -1697,4 +1717,48 @@ mod tests {
16971717 ) ,
16981718 ) ;
16991719 }
1720+
1721+ #[ tokio:: test]
1722+ async fn test_register_table ( ) {
1723+ // Create a catalog and namespace
1724+ let catalog = new_memory_catalog ( ) ;
1725+ let namespace_ident = NamespaceIdent :: new ( "test_namespace" . into ( ) ) ;
1726+ create_namespace ( & catalog, & namespace_ident) . await ;
1727+
1728+ // Create a table to get a valid metadata file
1729+ let source_table_ident = TableIdent :: new ( namespace_ident. clone ( ) , "source_table" . into ( ) ) ;
1730+ create_table ( & catalog, & source_table_ident) . await ;
1731+
1732+ // Get the metadata location from the source table
1733+ let source_table = catalog. load_table ( & source_table_ident) . await . unwrap ( ) ;
1734+ let metadata_location = source_table. metadata_location ( ) . unwrap ( ) . to_string ( ) ;
1735+
1736+ // Register a new table using the same metadata location
1737+ let register_table_ident =
1738+ TableIdent :: new ( namespace_ident. clone ( ) , "register_table" . into ( ) ) ;
1739+ let registered_table = catalog
1740+ . register_table ( & register_table_ident, metadata_location. clone ( ) )
1741+ . await
1742+ . unwrap ( ) ;
1743+
1744+ // Verify the registered table has the correct identifier
1745+ assert_eq ! ( registered_table. identifier( ) , & register_table_ident) ;
1746+
1747+ // Verify the registered table has the correct metadata location
1748+ assert_eq ! (
1749+ registered_table. metadata_location( ) . unwrap( ) . to_string( ) ,
1750+ metadata_location
1751+ ) ;
1752+
1753+ // Verify the table exists in the catalog
1754+ assert ! ( catalog. table_exists( & register_table_ident) . await . unwrap( ) ) ;
1755+
1756+ // Verify we can load the registered table
1757+ let loaded_table = catalog. load_table ( & register_table_ident) . await . unwrap ( ) ;
1758+ assert_eq ! ( loaded_table. identifier( ) , & register_table_ident) ;
1759+ assert_eq ! (
1760+ loaded_table. metadata_location( ) . unwrap( ) . to_string( ) ,
1761+ metadata_location
1762+ ) ;
1763+ }
17001764}
0 commit comments