Search in sources :

Example 1 with PREVIOUS_METADATA_LOCATION_PROP

use of org.apache.iceberg.BaseMetastoreTableOperations.PREVIOUS_METADATA_LOCATION_PROP in project trino by trinodb.

the class FileMetastoreTableOperations method commitToExistingTable.

@Override
protected void commitToExistingTable(TableMetadata base, TableMetadata metadata) {
    Table currentTable = getTable();
    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());
    }
    String newMetadataLocation = writeNewMetadata(metadata, version + 1);
    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);
    metastore.replaceTable(database, tableName, table, privileges);
}
Also used : CommitFailedException(org.apache.iceberg.exceptions.CommitFailedException) Table(io.trino.plugin.hive.metastore.Table) NO_PRIVILEGES(io.trino.plugin.hive.metastore.PrincipalPrivileges.NO_PRIVILEGES) ConnectorSession(io.trino.spi.connector.ConnectorSession) TableMetadata(org.apache.iceberg.TableMetadata) Preconditions.checkState(com.google.common.base.Preconditions.checkState) HiveMetastore(io.trino.plugin.hive.metastore.HiveMetastore) Optional(java.util.Optional) PREVIOUS_METADATA_LOCATION_PROP(org.apache.iceberg.BaseMetastoreTableOperations.PREVIOUS_METADATA_LOCATION_PROP) METADATA_LOCATION_PROP(org.apache.iceberg.BaseMetastoreTableOperations.METADATA_LOCATION_PROP) PrincipalPrivileges(io.trino.plugin.hive.metastore.PrincipalPrivileges) FileIO(org.apache.iceberg.io.FileIO) MetastoreUtil(io.trino.plugin.hive.metastore.MetastoreUtil) AbstractMetastoreTableOperations(io.trino.plugin.iceberg.catalog.hms.AbstractMetastoreTableOperations) NotThreadSafe(javax.annotation.concurrent.NotThreadSafe) Table(io.trino.plugin.hive.metastore.Table) PrincipalPrivileges(io.trino.plugin.hive.metastore.PrincipalPrivileges) CommitFailedException(org.apache.iceberg.exceptions.CommitFailedException)

Aggregations

Preconditions.checkState (com.google.common.base.Preconditions.checkState)1 HiveMetastore (io.trino.plugin.hive.metastore.HiveMetastore)1 MetastoreUtil (io.trino.plugin.hive.metastore.MetastoreUtil)1 PrincipalPrivileges (io.trino.plugin.hive.metastore.PrincipalPrivileges)1 NO_PRIVILEGES (io.trino.plugin.hive.metastore.PrincipalPrivileges.NO_PRIVILEGES)1 Table (io.trino.plugin.hive.metastore.Table)1 AbstractMetastoreTableOperations (io.trino.plugin.iceberg.catalog.hms.AbstractMetastoreTableOperations)1 ConnectorSession (io.trino.spi.connector.ConnectorSession)1 Optional (java.util.Optional)1 NotThreadSafe (javax.annotation.concurrent.NotThreadSafe)1 METADATA_LOCATION_PROP (org.apache.iceberg.BaseMetastoreTableOperations.METADATA_LOCATION_PROP)1 PREVIOUS_METADATA_LOCATION_PROP (org.apache.iceberg.BaseMetastoreTableOperations.PREVIOUS_METADATA_LOCATION_PROP)1 TableMetadata (org.apache.iceberg.TableMetadata)1 CommitFailedException (org.apache.iceberg.exceptions.CommitFailedException)1 FileIO (org.apache.iceberg.io.FileIO)1