use of com.facebook.presto.spi.PrestoException in project presto by prestodb.
the class MetastoreUtil method fromMetastoreApiTable.
public static Table fromMetastoreApiTable(org.apache.hadoop.hive.metastore.api.Table table) {
StorageDescriptor storageDescriptor = table.getSd();
if (storageDescriptor == null) {
throw new PrestoException(HIVE_INVALID_METADATA, "Table is missing storage descriptor");
}
Table.Builder tableBuilder = Table.builder().setDatabaseName(table.getDbName()).setTableName(table.getTableName()).setOwner(nullToEmpty(table.getOwner())).setTableType(table.getTableType()).setDataColumns(storageDescriptor.getCols().stream().map(MetastoreUtil::fromMetastoreApiFieldSchema).collect(toList())).setPartitionColumns(table.getPartitionKeys().stream().map(MetastoreUtil::fromMetastoreApiFieldSchema).collect(toList())).setParameters(table.getParameters() == null ? ImmutableMap.of() : table.getParameters()).setViewOriginalText(Optional.ofNullable(emptyToNull(table.getViewOriginalText()))).setViewExpandedText(Optional.ofNullable(emptyToNull(table.getViewExpandedText())));
fromMetastoreApiStorageDescriptor(storageDescriptor, tableBuilder.getStorageBuilder(), table.getTableName());
return tableBuilder.build();
}
use of com.facebook.presto.spi.PrestoException in project presto by prestodb.
the class FileHiveMetastore method renameTable.
@Override
public synchronized void renameTable(String databaseName, String tableName, String newDatabaseName, String newTableName) {
requireNonNull(databaseName, "databaseName is null");
requireNonNull(tableName, "tableName is null");
requireNonNull(newDatabaseName, "newDatabaseName is null");
requireNonNull(newTableName, "newTableName is null");
getRequiredTable(databaseName, tableName);
getRequiredDatabase(newDatabaseName);
// verify new table does not exist
verifyTableNotExists(newDatabaseName, newTableName);
try {
if (!metadataFileSystem.rename(getTableMetadataDirectory(databaseName, tableName), getTableMetadataDirectory(newDatabaseName, newTableName))) {
throw new PrestoException(HIVE_METASTORE_ERROR, "Could not rename table directory");
}
} catch (IOException e) {
throw new PrestoException(HIVE_METASTORE_ERROR, e);
}
}
use of com.facebook.presto.spi.PrestoException in project presto by prestodb.
the class SemiTransactionalHiveMetastore method getTablePrivileges.
public synchronized Set<HivePrivilegeInfo> getTablePrivileges(String user, String databaseName, String tableName) {
checkReadable();
SchemaTableName schemaTableName = new SchemaTableName(databaseName, tableName);
Action<TableAndMore> tableAction = tableActions.get(schemaTableName);
if (tableAction == null) {
return delegate.getTablePrivileges(user, databaseName, tableName);
}
switch(tableAction.getType()) {
case ADD:
case ALTER:
{
if (!user.equals(tableAction.getData().getTable().getOwner())) {
throw new PrestoException(NOT_SUPPORTED, "Cannot access a table newly created in the transaction with a different user");
}
Collection<HivePrivilegeInfo> privileges = tableAction.getData().getPrincipalPrivileges().getUserPrivileges().get(user);
return ImmutableSet.<HivePrivilegeInfo>builder().addAll(privileges).add(new HivePrivilegeInfo(OWNERSHIP, true)).build();
}
case INSERT_EXISTING:
return delegate.getTablePrivileges(user, databaseName, tableName);
case DROP:
throw new TableNotFoundException(schemaTableName);
default:
throw new IllegalStateException("Unknown action type");
}
}
use of com.facebook.presto.spi.PrestoException in project presto by prestodb.
the class FileHiveMetastore method renameDatabase.
@Override
public synchronized void renameDatabase(String databaseName, String newDatabaseName) {
requireNonNull(databaseName, "databaseName is null");
requireNonNull(newDatabaseName, "newDatabaseName is null");
getRequiredDatabase(databaseName);
verifyDatabaseNotExists(newDatabaseName);
try {
if (!metadataFileSystem.rename(getDatabaseMetadataDirectory(databaseName), getDatabaseMetadataDirectory(newDatabaseName))) {
throw new PrestoException(HIVE_METASTORE_ERROR, "Could not rename database metadata directory");
}
} catch (IOException e) {
throw new PrestoException(HIVE_METASTORE_ERROR, e);
}
}
use of com.facebook.presto.spi.PrestoException in project presto by prestodb.
the class TestingHiveMetastore method createDatabase.
@Override
public synchronized void createDatabase(Database database) {
requireNonNull(database, "database is null");
if (!database.getLocation().isPresent()) {
File location = new File(baseDirectory, database.getDatabaseName() + ".db");
database = Database.builder(database).setLocation(Optional.of(location.getAbsoluteFile().toURI().toString())).build();
}
File directory = new File(URI.create(database.getLocation().get()));
if (directory.exists()) {
throw new PrestoException(HIVE_METASTORE_ERROR, "Database directory already exists");
}
if (!isParentDir(directory, baseDirectory)) {
throw new PrestoException(HIVE_METASTORE_ERROR, "Database directory must be inside of the metastore base directory");
}
if (!directory.mkdirs()) {
throw new PrestoException(HIVE_METASTORE_ERROR, "Could not create database directory");
}
if (databases.putIfAbsent(database.getDatabaseName(), database) != null) {
throw new PrestoException(ALREADY_EXISTS, "Database " + database.getDatabaseName() + " already exists");
}
}
Aggregations