@@ -195,30 +195,49 @@ impl Catalog for S3TablesCatalog {
195195 ) -> Result < Table > {
196196 let table_ident = TableIdent :: new ( namespace. clone ( ) , creation. name . clone ( ) ) ;
197197
198+ // create table
199+ let create_resp: CreateTableOutput = self
200+ . s3tables_client
201+ . create_table ( )
202+ . table_bucket_arn ( self . config . table_bucket_arn . clone ( ) )
203+ . namespace ( namespace. to_url_string ( ) )
204+ . name ( table_ident. name ( ) )
205+ . send ( )
206+ . await
207+ . map_err ( from_aws_sdk_error) ?;
208+
209+ // get warehouse location
210+ let get_resp: GetTableOutput = self
211+ . s3tables_client
212+ . get_table ( )
213+ . table_bucket_arn ( self . config . table_bucket_arn . clone ( ) )
214+ . namespace ( namespace. to_url_string ( ) )
215+ . name ( table_ident. name ( ) )
216+ . send ( )
217+ . await
218+ . map_err ( from_aws_sdk_error) ?;
219+
220+ // write metadata to file
198221 let metadata = TableMetadataBuilder :: from_table_creation ( creation) ?
199222 . build ( ) ?
200223 . metadata ;
201- let metadata_location =
202- create_metadata_location ( namespace. to_url_string ( ) , table_ident. name ( ) , 0 ) ?;
224+ let metadata_location = create_metadata_location (
225+ get_resp. warehouse_location ( ) ,
226+ get_resp. version_token ( ) . parse :: < i32 > ( ) . unwrap ( ) ,
227+ ) ?;
203228 self . file_io
204229 . new_output ( & metadata_location) ?
205230 . write ( serde_json:: to_vec ( & metadata) ?. into ( ) )
206231 . await ?;
207232
208- self . s3tables_client
209- . create_table ( )
210- . table_bucket_arn ( self . config . table_bucket_arn . clone ( ) )
211- . namespace ( namespace. to_url_string ( ) )
212- . name ( table_ident. name ( ) )
213- . send ( )
214- . await
215- . map_err ( from_aws_sdk_error) ?;
233+ // update metadata location
216234 self . s3tables_client
217235 . update_table_metadata_location ( )
218236 . table_bucket_arn ( self . config . table_bucket_arn . clone ( ) )
219237 . namespace ( namespace. to_url_string ( ) )
220238 . name ( table_ident. name ( ) )
221239 . metadata_location ( metadata_location. clone ( ) )
240+ . version_token ( create_resp. version_token ( ) )
222241 . send ( )
223242 . await
224243 . map_err ( from_aws_sdk_error) ?;
0 commit comments