@@ -372,8 +372,7 @@ func (c *Catalog) createS3TablesTable(ctx context.Context, database, tableName s
372372 return nil , fmt .Errorf ("failed to allocate S3 Tables storage for %s.%s: %w" , database , tableName , err )
373373 }
374374
375- tbl , err := c .commitS3TablesTable (ctx , database , tableName , identifier , schema , opts ... )
376- if err != nil {
375+ if err := c .commitS3TablesTable (ctx , database , tableName , identifier , schema , opts ... ); err != nil {
377376 if _ , delErr := c .glueSvc .DeleteTable (ctx , & glue.DeleteTableInput {
378377 CatalogId : c .catalogId ,
379378 DatabaseName : aws .String (database ),
@@ -385,29 +384,33 @@ func (c *Catalog) createS3TablesTable(ctx context.Context, database, tableName s
385384 return nil , err
386385 }
387386
388- return tbl , nil
387+ // The table is committed; load it outside the rollback scope so a transient
388+ // read failure does not delete an already-created table.
389+ return c .LoadTable (ctx , identifier )
389390}
390391
391392// commitS3TablesTable reads the service-assigned location, writes the Iceberg
392- // metadata to it, and points the Glue entry at that metadata.
393- func (c * Catalog ) commitS3TablesTable (ctx context.Context , database , tableName string , identifier table.Identifier , schema * iceberg.Schema , opts ... catalog.CreateTableOpt ) (* table.Table , error ) {
393+ // metadata to it, and points the Glue entry at that metadata. It does not reload
394+ // the table: the caller does that only after a successful commit, so a read
395+ // failure never triggers a rollback of an already-created table.
396+ func (c * Catalog ) commitS3TablesTable (ctx context.Context , database , tableName string , identifier table.Identifier , schema * iceberg.Schema , opts ... catalog.CreateTableOpt ) error {
394397 allocated , err := c .glueSvc .GetTable (ctx , & glue.GetTableInput {
395398 CatalogId : c .catalogId ,
396399 DatabaseName : aws .String (database ),
397400 Name : aws .String (tableName ),
398401 })
399402 if err != nil {
400- return nil , fmt .Errorf ("failed to load allocated S3 Tables table %s.%s: %w" , database , tableName , err )
403+ return fmt .Errorf ("failed to load allocated S3 Tables table %s.%s: %w" , database , tableName , err )
401404 }
402405 if allocated == nil || allocated .Table == nil || allocated .Table .StorageDescriptor == nil {
403- return nil , fmt .Errorf ("S3 Tables did not return a storage descriptor for %s.%s" , database , tableName )
406+ return fmt .Errorf ("S3 Tables did not return a storage descriptor for %s.%s" , database , tableName )
404407 }
405408 managedLocation := aws .ToString (allocated .Table .StorageDescriptor .Location )
406409 if managedLocation == "" {
407- return nil , fmt .Errorf ("S3 Tables did not assign a storage location for %s.%s" , database , tableName )
410+ return fmt .Errorf ("S3 Tables did not assign a storage location for %s.%s" , database , tableName )
408411 }
409412 if allocated .Table .VersionId == nil {
410- return nil , fmt .Errorf ("cannot commit table %s.%s: because Glue table version id is missing" , database , tableName )
413+ return fmt .Errorf ("cannot commit table %s.%s: because Glue table version id is missing" , database , tableName )
411414 }
412415
413416 // Copy rather than append onto the caller's opts, whose backing array may
@@ -418,13 +421,15 @@ func (c *Catalog) commitS3TablesTable(ctx context.Context, database, tableName s
418421
419422 staged , err := internal .CreateStagedTable (ctx , c .props , c .LoadNamespaceProperties , identifier , schema , stagedOpts ... )
420423 if err != nil {
421- return nil , err
424+ return err
422425 }
423426
424427 if err := internal .WriteMetadata (ctx , staged .Table ); err != nil {
425- return nil , err
428+ return err
426429 }
427430
431+ // constructTableInput sends TableType=EXTERNAL_TABLE; S3 Tables keeps its own
432+ // service type (e.g. "customer") on read, which getRawTable accepts.
428433 _ , err = c .glueSvc .UpdateTable (ctx , & glue.UpdateTableInput {
429434 CatalogId : c .catalogId ,
430435 DatabaseName : aws .String (database ),
@@ -433,10 +438,10 @@ func (c *Catalog) commitS3TablesTable(ctx context.Context, database, tableName s
433438 SkipArchive : aws .Bool (c .props .GetBool (SkipArchive , SkipArchiveDefault )),
434439 })
435440 if err != nil {
436- return nil , fmt .Errorf ("failed to commit S3 Tables table %s.%s: %w" , database , tableName , err )
441+ return fmt .Errorf ("failed to commit S3 Tables table %s.%s: %w" , database , tableName , err )
437442 }
438443
439- return c . LoadTable ( ctx , identifier )
444+ return nil
440445}
441446
442447// RegisterTable registers a new table using existing metadata.
0 commit comments