Search in sources :

Example 1 with ROLE

use of com.facebook.presto.hive.metastore.PrincipalType.ROLE in project presto by prestodb.

the class TestingHiveMetastore method replaceTable.

@Override
public synchronized void replaceTable(String databaseName, String tableName, Table newTable, PrincipalPrivileges principalPrivileges) {
    SchemaTableName schemaTableName = new SchemaTableName(databaseName, tableName);
    Table table = getRequiredTable(schemaTableName);
    checkArgument(newTable.getDatabaseName().equals(databaseName) && newTable.getTableName().equals(tableName), "Replacement table must have same name");
    checkArgument(newTable.getTableType().equals(table.getTableType()), "Replacement table must have same type");
    checkArgument(newTable.getStorage().getLocation().equals(table.getStorage().getLocation()), "Replacement table must have same location");
    // replace table
    relations.put(schemaTableName, newTable);
    // remove old permissions
    ImmutableList.copyOf(tablePrivileges.keySet()).stream().filter(key -> key.matches(databaseName, tableName)).forEach(tablePrivileges::remove);
    // add new permissions
    for (Entry<String, Collection<HivePrivilegeInfo>> entry : principalPrivileges.getUserPrivileges().asMap().entrySet()) {
        setTablePrivileges(entry.getKey(), USER, newTable.getDatabaseName(), newTable.getTableName(), entry.getValue());
    }
    for (Entry<String, Collection<HivePrivilegeInfo>> entry : principalPrivileges.getRolePrivileges().asMap().entrySet()) {
        setTablePrivileges(entry.getKey(), ROLE, newTable.getDatabaseName(), newTable.getTableName(), entry.getValue());
    }
}
Also used : MetastoreUtil.makePartName(com.facebook.presto.hive.metastore.MetastoreUtil.makePartName) Collections.unmodifiableList(java.util.Collections.unmodifiableList) HiveType(com.facebook.presto.hive.HiveType) PartitionNotFoundException(com.facebook.presto.hive.PartitionNotFoundException) EXTERNAL_TABLE(org.apache.hadoop.hive.metastore.TableType.EXTERNAL_TABLE) US(java.util.Locale.US) HashMap(java.util.HashMap) PrestoException(com.facebook.presto.spi.PrestoException) ArrayList(java.util.ArrayList) OWNERSHIP(com.facebook.presto.hive.metastore.HivePrivilegeInfo.HivePrivilege.OWNERSHIP) HashSet(java.util.HashSet) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) SchemaTableName(com.facebook.presto.spi.SchemaTableName) HIVE_METASTORE_ERROR(com.facebook.presto.hive.HiveErrorCode.HIVE_METASTORE_ERROR) ColumnNotFoundException(com.facebook.presto.spi.ColumnNotFoundException) ImmutableList(com.google.common.collect.ImmutableList) ALREADY_EXISTS(com.facebook.presto.spi.StandardErrorCode.ALREADY_EXISTS) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) HiveUtil.toPartitionValues(com.facebook.presto.hive.HiveUtil.toPartitionValues) TableAlreadyExistsException(com.facebook.presto.hive.TableAlreadyExistsException) URI(java.net.URI) ImmutableCollectors.toImmutableList(com.facebook.presto.util.ImmutableCollectors.toImmutableList) VIRTUAL_VIEW(org.apache.hadoop.hive.metastore.TableType.VIRTUAL_VIEW) EnumSet(java.util.EnumSet) FileUtils.deleteRecursively(io.airlift.testing.FileUtils.deleteRecursively) ImmutableSet(com.google.common.collect.ImmutableSet) ROLE(com.facebook.presto.hive.metastore.PrincipalType.ROLE) ImmutableMap(com.google.common.collect.ImmutableMap) Collection(java.util.Collection) Set(java.util.Set) ThreadSafe(javax.annotation.concurrent.ThreadSafe) DEFAULT_DATABASE_NAME(com.facebook.presto.hive.metastore.Database.DEFAULT_DATABASE_NAME) GuardedBy(javax.annotation.concurrent.GuardedBy) MANAGED_TABLE(org.apache.hadoop.hive.metastore.TableType.MANAGED_TABLE) File(java.io.File) Objects(java.util.Objects) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) TableNotFoundException(com.facebook.presto.spi.TableNotFoundException) NOT_SUPPORTED(com.facebook.presto.spi.StandardErrorCode.NOT_SUPPORTED) TableType(org.apache.hadoop.hive.metastore.TableType) Entry(java.util.Map.Entry) USER(com.facebook.presto.hive.metastore.PrincipalType.USER) Optional(java.util.Optional) MoreObjects.toStringHelper(com.google.common.base.MoreObjects.toStringHelper) Collection(java.util.Collection) SchemaTableName(com.facebook.presto.spi.SchemaTableName)

Aggregations

HIVE_METASTORE_ERROR (com.facebook.presto.hive.HiveErrorCode.HIVE_METASTORE_ERROR)1 HiveType (com.facebook.presto.hive.HiveType)1 HiveUtil.toPartitionValues (com.facebook.presto.hive.HiveUtil.toPartitionValues)1 PartitionNotFoundException (com.facebook.presto.hive.PartitionNotFoundException)1 TableAlreadyExistsException (com.facebook.presto.hive.TableAlreadyExistsException)1 DEFAULT_DATABASE_NAME (com.facebook.presto.hive.metastore.Database.DEFAULT_DATABASE_NAME)1 OWNERSHIP (com.facebook.presto.hive.metastore.HivePrivilegeInfo.HivePrivilege.OWNERSHIP)1 MetastoreUtil.makePartName (com.facebook.presto.hive.metastore.MetastoreUtil.makePartName)1 ROLE (com.facebook.presto.hive.metastore.PrincipalType.ROLE)1 USER (com.facebook.presto.hive.metastore.PrincipalType.USER)1 ColumnNotFoundException (com.facebook.presto.spi.ColumnNotFoundException)1 PrestoException (com.facebook.presto.spi.PrestoException)1 SchemaTableName (com.facebook.presto.spi.SchemaTableName)1 ALREADY_EXISTS (com.facebook.presto.spi.StandardErrorCode.ALREADY_EXISTS)1 NOT_SUPPORTED (com.facebook.presto.spi.StandardErrorCode.NOT_SUPPORTED)1 TableNotFoundException (com.facebook.presto.spi.TableNotFoundException)1 ImmutableCollectors.toImmutableList (com.facebook.presto.util.ImmutableCollectors.toImmutableList)1 MoreObjects.toStringHelper (com.google.common.base.MoreObjects.toStringHelper)1 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 ImmutableList (com.google.common.collect.ImmutableList)1