@@ -87,11 +87,15 @@ impl Catalog for InMemoryCatalog {
8787 let root_namespace_state = self . root_namespace_state . lock ( ) . await ;
8888
8989 match maybe_parent {
90- None => Ok ( root_namespace_state
91- . list_top_level_namespaces ( )
92- . into_iter ( )
93- . map ( |str| NamespaceIdent :: new ( str. to_string ( ) ) )
94- . collect_vec ( ) ) ,
90+ None => {
91+ let namespaces = root_namespace_state
92+ . list_top_level_namespaces ( )
93+ . into_iter ( )
94+ . map ( |str| NamespaceIdent :: new ( str. to_string ( ) ) )
95+ . collect_vec ( ) ;
96+
97+ Ok ( namespaces)
98+ }
9599 Some ( parent_namespace_ident) => {
96100 let namespaces = root_namespace_state
97101 . list_namespaces_under ( parent_namespace_ident) ?
@@ -184,55 +188,44 @@ impl Catalog for InMemoryCatalog {
184188
185189 let table_name = table_creation. name . clone ( ) ;
186190 let table_ident = TableIdent :: new ( namespace_ident. clone ( ) , table_name) ;
187- let table_exists = root_namespace_state. table_exists ( & table_ident) ?;
188-
189- if table_exists {
190- Err ( Error :: new (
191- ErrorKind :: Unexpected ,
192- format ! (
193- "Cannot create table {:?}. Table already exists" ,
194- & table_ident
195- ) ,
196- ) )
197- } else {
198- let ( table_creation, location) = match table_creation. location . clone ( ) {
199- Some ( location) => ( table_creation, location) ,
200- None => {
201- let location = format ! (
202- "{}/{}/{}" ,
203- self . default_table_root_location,
204- table_ident. namespace( ) . join( "/" ) ,
205- table_ident. name( )
206- ) ;
207-
208- let new_table_creation = TableCreation {
209- location : Some ( location. clone ( ) ) ,
210- ..table_creation
211- } ;
212-
213- ( new_table_creation, location)
214- }
215- } ;
216-
217- let metadata = TableMetadataBuilder :: from_table_creation ( table_creation) ?. build ( ) ?;
218- let metadata_location = create_metadata_location ( & location, 0 ) ?;
219-
220- self . file_io
221- . new_output ( & metadata_location) ?
222- . write ( serde_json:: to_vec ( & metadata) ?. into ( ) )
223- . await ?;
224-
225- root_namespace_state. insert_new_table ( & table_ident, metadata_location. clone ( ) ) ?;
226-
227- let table = Table :: builder ( )
228- . file_io ( self . file_io . clone ( ) )
229- . metadata_location ( metadata_location)
230- . metadata ( metadata)
231- . identifier ( table_ident)
232- . build ( ) ;
233-
234- Ok ( table)
235- }
191+
192+ let ( table_creation, location) = match table_creation. location . clone ( ) {
193+ Some ( location) => ( table_creation, location) ,
194+ None => {
195+ let location = format ! (
196+ "{}/{}/{}" ,
197+ self . default_table_root_location,
198+ table_ident. namespace( ) . join( "/" ) ,
199+ table_ident. name( )
200+ ) ;
201+
202+ let new_table_creation = TableCreation {
203+ location : Some ( location. clone ( ) ) ,
204+ ..table_creation
205+ } ;
206+
207+ ( new_table_creation, location)
208+ }
209+ } ;
210+
211+ let metadata = TableMetadataBuilder :: from_table_creation ( table_creation) ?. build ( ) ?;
212+ let metadata_location = create_metadata_location ( & location, 0 ) ?;
213+
214+ self . file_io
215+ . new_output ( & metadata_location) ?
216+ . write ( serde_json:: to_vec ( & metadata) ?. into ( ) )
217+ . await ?;
218+
219+ root_namespace_state. insert_new_table ( & table_ident, metadata_location. clone ( ) ) ?;
220+
221+ let table = Table :: builder ( )
222+ . file_io ( self . file_io . clone ( ) )
223+ . metadata_location ( metadata_location)
224+ . metadata ( metadata)
225+ . identifier ( table_ident)
226+ . build ( ) ;
227+
228+ Ok ( table)
236229 }
237230
238231 /// Load table from the catalog.
@@ -282,6 +275,7 @@ impl Catalog for InMemoryCatalog {
282275 new_root_namespace_state. remove_existing_table ( src_table_ident) ?;
283276 new_root_namespace_state. insert_new_table ( dst_table_ident, metadata_location) ?;
284277 * root_namespace_state = new_root_namespace_state;
278+
285279 Ok ( ( ) )
286280 }
287281
@@ -604,7 +598,7 @@ mod tests {
604598 . unwrap_err( )
605599 . to_string( ) ,
606600 format!(
607- "Unexpected => Cannot create namespace {:?}. Namespace already exists" ,
601+ "Unexpected => Cannot create namespace {:?}. Namespace already exists. " ,
608602 & namespace_ident
609603 )
610604 ) ;
@@ -1092,7 +1086,7 @@ mod tests {
10921086 . unwrap_err( )
10931087 . to_string( ) ,
10941088 format!(
1095- "Unexpected => Cannot create table {:?}. Table already exists" ,
1089+ "Unexpected => Cannot create table {:?}. Table already exists. " ,
10961090 & table_ident
10971091 )
10981092 ) ;
@@ -1513,7 +1507,7 @@ mod tests {
15131507 . unwrap_err( )
15141508 . to_string( ) ,
15151509 format!(
1516- "Unexpected => Cannot insert table {:? }. Table already exists." ,
1510+ "Unexpected => Cannot create table {:? }. Table already exists." ,
15171511 & dst_table_ident
15181512 ) ,
15191513 ) ;
0 commit comments