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());
}
}
Aggregations