diff --git a/plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/catalog/hms/HiveMetastoreTableOperations.java b/plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/catalog/hms/HiveMetastoreTableOperations.java index 3950a4c54277..7dfa6b523beb 100644 --- a/plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/catalog/hms/HiveMetastoreTableOperations.java +++ b/plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/catalog/hms/HiveMetastoreTableOperations.java @@ -70,27 +70,26 @@ protected void commitToExistingTable(TableMetadata base, TableMetadata metadata) database, tableName); try { - Table table; - try { - Table currentTable = fromMetastoreApiTable(thriftMetastore.getTable(identity, database, tableName) - .orElseThrow(() -> new TableNotFoundException(getSchemaTableName()))); + Table currentTable = fromMetastoreApiTable(thriftMetastore.getTable(identity, database, tableName) + .orElseThrow(() -> new TableNotFoundException(getSchemaTableName()))); - checkState(currentMetadataLocation != null, "No current metadata location for existing table"); - String metadataLocation = currentTable.getParameters().get(METADATA_LOCATION_PROP); - if (!currentMetadataLocation.equals(metadataLocation)) { - throw new CommitFailedException("Metadata location [%s] is not same as table metadata location [%s] for %s", - currentMetadataLocation, metadataLocation, getSchemaTableName()); - } + checkState(currentMetadataLocation != null, "No current metadata location for existing table"); + String metadataLocation = currentTable.getParameters().get(METADATA_LOCATION_PROP); + if (!currentMetadataLocation.equals(metadataLocation)) { + throw new CommitFailedException("Metadata location [%s] is not same as table metadata location [%s] for %s", + currentMetadataLocation, metadataLocation, getSchemaTableName()); + } - table = Table.builder(currentTable) - .setDataColumns(toHiveColumns(metadata.schema().columns())) - .withStorage(storage -> storage.setLocation(metadata.location())) - .setParameter(METADATA_LOCATION_PROP, newMetadataLocation) - .setParameter(PREVIOUS_METADATA_LOCATION_PROP, currentMetadataLocation) - .build(); + Table table = Table.builder(currentTable) + .setDataColumns(toHiveColumns(metadata.schema().columns())) + .withStorage(storage -> storage.setLocation(metadata.location())) + .setParameter(METADATA_LOCATION_PROP, newMetadataLocation) + .setParameter(PREVIOUS_METADATA_LOCATION_PROP, currentMetadataLocation) + .build(); - // todo privileges should not be replaced for an alter - PrincipalPrivileges privileges = table.getOwner().map(MetastoreUtil::buildInitialPrivilegeSet).orElse(NO_PRIVILEGES); + // todo privileges should not be replaced for an alter + PrincipalPrivileges privileges = table.getOwner().map(MetastoreUtil::buildInitialPrivilegeSet).orElse(NO_PRIVILEGES); + try { metastore.replaceTable(database, tableName, table, privileges); } catch (RuntimeException e) {