@@ -87,11 +87,15 @@ impl Catalog for InMemoryCatalog {
87
87
let root_namespace_state = self . root_namespace_state . lock ( ) . await ;
88
88
89
89
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
+ }
95
99
Some ( parent_namespace_ident) => {
96
100
let namespaces = root_namespace_state
97
101
. list_namespaces_under ( parent_namespace_ident) ?
@@ -184,55 +188,44 @@ impl Catalog for InMemoryCatalog {
184
188
185
189
let table_name = table_creation. name . clone ( ) ;
186
190
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)
236
229
}
237
230
238
231
/// Load table from the catalog.
@@ -282,6 +275,7 @@ impl Catalog for InMemoryCatalog {
282
275
new_root_namespace_state. remove_existing_table ( src_table_ident) ?;
283
276
new_root_namespace_state. insert_new_table ( dst_table_ident, metadata_location) ?;
284
277
* root_namespace_state = new_root_namespace_state;
278
+
285
279
Ok ( ( ) )
286
280
}
287
281
@@ -604,7 +598,7 @@ mod tests {
604
598
. unwrap_err( )
605
599
. to_string( ) ,
606
600
format!(
607
- "Unexpected => Cannot create namespace {:?}. Namespace already exists" ,
601
+ "Unexpected => Cannot create namespace {:?}. Namespace already exists. " ,
608
602
& namespace_ident
609
603
)
610
604
) ;
@@ -1092,7 +1086,7 @@ mod tests {
1092
1086
. unwrap_err( )
1093
1087
. to_string( ) ,
1094
1088
format!(
1095
- "Unexpected => Cannot create table {:?}. Table already exists" ,
1089
+ "Unexpected => Cannot create table {:?}. Table already exists. " ,
1096
1090
& table_ident
1097
1091
)
1098
1092
) ;
@@ -1513,7 +1507,7 @@ mod tests {
1513
1507
. unwrap_err( )
1514
1508
. to_string( ) ,
1515
1509
format!(
1516
- "Unexpected => Cannot insert table {:? }. Table already exists." ,
1510
+ "Unexpected => Cannot create table {:? }. Table already exists." ,
1517
1511
& dst_table_ident
1518
1512
) ,
1519
1513
) ;
0 commit comments