use of com.facebook.presto.hive.TableAlreadyExistsException in project presto by prestodb.
the class InMemoryHiveMetastore method alterTable.
@Override
public synchronized void alterTable(String databaseName, String tableName, Table newTable) {
SchemaTableName oldName = new SchemaTableName(databaseName, tableName);
SchemaTableName newName = new SchemaTableName(newTable.getDbName(), newTable.getTableName());
// if the name did not change, this is a simple schema change
if (oldName.equals(newName)) {
if (relations.replace(oldName, newTable) == null) {
throw new TableNotFoundException(oldName);
}
return;
}
// remove old table definition and add the new one
Table table = relations.get(oldName);
if (table == null) {
throw new TableNotFoundException(oldName);
}
if (relations.putIfAbsent(newName, newTable) != null) {
throw new TableAlreadyExistsException(newName);
}
relations.remove(oldName);
}
use of com.facebook.presto.hive.TableAlreadyExistsException in project presto by prestodb.
the class InMemoryHiveMetastore method createTable.
@Override
public synchronized void createTable(Table table) {
TableType tableType = TableType.valueOf(table.getTableType());
checkArgument(EnumSet.of(MANAGED_TABLE, EXTERNAL_TABLE, VIRTUAL_VIEW).contains(tableType), "Invalid table type: %s", tableType);
if (tableType == VIRTUAL_VIEW) {
checkArgument(table.getSd().getLocation() == null, "Storage location for view must be null");
} else {
File directory = new File(new Path(table.getSd().getLocation()).toUri());
checkArgument(directory.exists(), "Table directory does not exist");
if (tableType == MANAGED_TABLE) {
checkArgument(isParentDir(directory, baseDirectory), "Table directory must be inside of the metastore base directory");
}
}
SchemaTableName schemaTableName = new SchemaTableName(table.getDbName(), table.getTableName());
Table tableCopy = table.deepCopy();
if (relations.putIfAbsent(schemaTableName, tableCopy) != null) {
throw new TableAlreadyExistsException(schemaTableName);
}
if (tableType == VIRTUAL_VIEW) {
views.put(schemaTableName, tableCopy);
}
PrincipalPrivilegeSet privileges = table.getPrivileges();
if (privileges != null) {
for (Entry<String, List<PrivilegeGrantInfo>> entry : privileges.getUserPrivileges().entrySet()) {
String user = entry.getKey();
Set<HivePrivilegeInfo> userPrivileges = entry.getValue().stream().map(HivePrivilegeInfo::parsePrivilege).flatMap(Collection::stream).collect(toImmutableSet());
setTablePrivileges(user, USER, table.getDbName(), table.getTableName(), userPrivileges);
}
for (Entry<String, List<PrivilegeGrantInfo>> entry : privileges.getRolePrivileges().entrySet()) {
String role = entry.getKey();
Set<HivePrivilegeInfo> rolePrivileges = entry.getValue().stream().map(HivePrivilegeInfo::parsePrivilege).flatMap(Collection::stream).collect(toImmutableSet());
setTablePrivileges(role, ROLE, table.getDbName(), table.getTableName(), rolePrivileges);
}
}
}
use of com.facebook.presto.hive.TableAlreadyExistsException in project presto by prestodb.
the class TestingHiveMetastore method createTable.
@Override
public synchronized void createTable(Table table, PrincipalPrivileges principalPrivileges) {
TableType tableType = TableType.valueOf(table.getTableType());
checkArgument(EnumSet.of(MANAGED_TABLE, EXTERNAL_TABLE, VIRTUAL_VIEW).contains(tableType), "Invalid table type: %s", tableType);
SchemaTableName schemaTableName = new SchemaTableName(table.getDatabaseName(), table.getTableName());
if (tableType == VIRTUAL_VIEW) {
checkArgument(table.getStorage().getLocation().isEmpty(), "Storage location for view must be empty");
} else {
File directory = new File(URI.create(table.getStorage().getLocation()));
if (!directory.exists()) {
throw new PrestoException(HIVE_METASTORE_ERROR, "Table directory does not exist");
}
if (tableType == MANAGED_TABLE && !isParentDir(directory, baseDirectory)) {
throw new PrestoException(HIVE_METASTORE_ERROR, "Table directory must be inside of the metastore base directory");
}
}
if (relations.putIfAbsent(schemaTableName, table) != null) {
throw new TableAlreadyExistsException(schemaTableName);
}
for (Entry<String, Collection<HivePrivilegeInfo>> entry : principalPrivileges.getUserPrivileges().asMap().entrySet()) {
setTablePrivileges(entry.getKey(), USER, table.getDatabaseName(), table.getTableName(), entry.getValue());
}
for (Entry<String, Collection<HivePrivilegeInfo>> entry : principalPrivileges.getRolePrivileges().asMap().entrySet()) {
setTablePrivileges(entry.getKey(), ROLE, table.getDatabaseName(), table.getTableName(), entry.getValue());
}
}
use of com.facebook.presto.hive.TableAlreadyExistsException in project presto by prestodb.
the class GlueHiveMetastore method createTable.
@Override
public void createTable(MetastoreContext metastoreContext, Table table, PrincipalPrivileges principalPrivileges) {
try {
TableInput input = GlueInputConverter.convertTable(table);
stats.getCreateTable().record(() -> glueClient.createTable(new CreateTableRequest().withCatalogId(catalogId).withDatabaseName(table.getDatabaseName()).withTableInput(input)));
} catch (AlreadyExistsException e) {
throw new TableAlreadyExistsException(new SchemaTableName(table.getDatabaseName(), table.getTableName()));
} catch (EntityNotFoundException e) {
throw new SchemaNotFoundException(table.getDatabaseName());
} catch (AmazonServiceException e) {
throw new PrestoException(HIVE_METASTORE_ERROR, e);
}
}
use of com.facebook.presto.hive.TableAlreadyExistsException in project presto by prestodb.
the class InMemoryHiveMetastore method createTable.
@Override
public synchronized void createTable(MetastoreContext metastoreContext, Table table) {
TableType tableType = TableType.valueOf(table.getTableType());
checkArgument(EnumSet.of(MANAGED_TABLE, EXTERNAL_TABLE, VIRTUAL_VIEW).contains(tableType), "Invalid table type: %s", tableType);
if (tableType == VIRTUAL_VIEW) {
checkArgument(table.getSd().getLocation() == null, "Storage location for view must be null");
} else {
File directory = new File(new Path(table.getSd().getLocation()).toUri());
checkArgument(directory.exists(), "Table directory does not exist: %s", directory);
if (tableType == MANAGED_TABLE) {
checkArgument(isParentDir(directory, baseDirectory), "Table directory must be inside of the metastore base directory");
}
}
SchemaTableName schemaTableName = new SchemaTableName(table.getDbName(), table.getTableName());
Table tableCopy = table.deepCopy();
if (relations.putIfAbsent(schemaTableName, tableCopy) != null) {
throw new TableAlreadyExistsException(schemaTableName);
}
if (tableType == VIRTUAL_VIEW) {
views.put(schemaTableName, tableCopy);
}
PrincipalPrivilegeSet privileges = table.getPrivileges();
if (privileges != null) {
throw new UnsupportedOperationException();
}
}
Aggregations