use of com.facebook.presto.spi.TableNotFoundException in project presto by prestodb.
the class BridgingHiveMetastore method renameTable.
@Override
public void renameTable(String databaseName, String tableName, String newDatabaseName, String newTableName) {
Optional<org.apache.hadoop.hive.metastore.api.Table> source = delegate.getTable(databaseName, tableName);
if (!source.isPresent()) {
throw new TableNotFoundException(new SchemaTableName(databaseName, tableName));
}
org.apache.hadoop.hive.metastore.api.Table table = source.get();
table.setDbName(newDatabaseName);
table.setTableName(newTableName);
alterTable(databaseName, tableName, table);
}
use of com.facebook.presto.spi.TableNotFoundException in project presto by prestodb.
the class FileHiveMetastore method alterTable.
private void alterTable(String databaseName, String tableName, Function<TableMetadata, TableMetadata> alterFunction) {
requireNonNull(databaseName, "databaseName is null");
requireNonNull(tableName, "tableName is null");
Path tableMetadataDirectory = getTableMetadataDirectory(databaseName, tableName);
TableMetadata oldTableSchema = readSchemaFile("table", tableMetadataDirectory, tableCodec).orElseThrow(() -> new TableNotFoundException(new SchemaTableName(databaseName, tableName)));
TableMetadata newTableSchema = alterFunction.apply(oldTableSchema);
if (oldTableSchema == newTableSchema) {
return;
}
writeSchemaFile("table", tableMetadataDirectory, tableCodec, newTableSchema, true);
}
use of com.facebook.presto.spi.TableNotFoundException in project presto by prestodb.
the class SemiTransactionalHiveMetastore method getTableSource.
/**
* This method can only be called when the table is known to exist
*/
@GuardedBy("this")
private TableSource getTableSource(String databaseName, String tableName) {
checkHoldsLock();
checkReadable();
Action<TableAndMore> tableAction = tableActions.get(new SchemaTableName(databaseName, tableName));
if (tableAction == null) {
return TableSource.PRE_EXISTING_TABLE;
}
switch(tableAction.getType()) {
case ADD:
return TableSource.CREATED_IN_THIS_TRANSACTION;
case ALTER:
throw new IllegalStateException("Tables are never altered in the current implementation");
case DROP:
throw new TableNotFoundException(new SchemaTableName(databaseName, tableName));
case INSERT_EXISTING:
return TableSource.PRE_EXISTING_TABLE;
default:
throw new IllegalStateException("Unknown action type");
}
}
use of com.facebook.presto.spi.TableNotFoundException 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.TableNotFoundException 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);
}
Aggregations