use of com.facebook.presto.spi.TableNotFoundException in project presto by prestodb.
the class SemiTransactionalHiveMetastore method listTablePrivileges.
public synchronized Set<HivePrivilegeInfo> listTablePrivileges(MetastoreContext metastoreContext, String databaseName, String tableName, PrestoPrincipal principal) {
checkReadable();
SchemaTableName schemaTableName = new SchemaTableName(databaseName, tableName);
Action<TableAndMore> tableAction = tableActions.get(schemaTableName);
if (tableAction == null) {
return delegate.listTablePrivileges(metastoreContext, databaseName, tableName, principal);
}
switch(tableAction.getType()) {
case ADD:
case ALTER:
{
if (principal.getType() == PrincipalType.ROLE) {
return ImmutableSet.of();
}
if (!principal.getName().equals(tableAction.getData().getTable().getOwner())) {
return ImmutableSet.of();
}
Collection<HivePrivilegeInfo> privileges = tableAction.getData().getPrincipalPrivileges().getUserPrivileges().get(principal.getName());
return ImmutableSet.<HivePrivilegeInfo>builder().addAll(privileges).add(new HivePrivilegeInfo(OWNERSHIP, true, new PrestoPrincipal(USER, principal.getName()), new PrestoPrincipal(USER, principal.getName()))).build();
}
case INSERT_EXISTING:
return delegate.listTablePrivileges(metastoreContext, databaseName, tableName, principal);
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 SemiTransactionalHiveMetastore method truncateUnpartitionedTable.
public synchronized void truncateUnpartitionedTable(ConnectorSession session, String databaseName, String tableName) {
checkReadable();
Optional<Table> table = getTable(new MetastoreContext(session.getIdentity(), session.getQueryId(), session.getClientInfo(), session.getSource(), getMetastoreHeaders(session), isUserDefinedTypeEncodingEnabled(session), columnConverterProvider), databaseName, tableName);
SchemaTableName schemaTableName = new SchemaTableName(databaseName, tableName);
if (!table.isPresent()) {
throw new TableNotFoundException(schemaTableName);
}
if (!table.get().getTableType().equals(MANAGED_TABLE) && !table.get().getTableType().equals(MATERIALIZED_VIEW)) {
throw new PrestoException(NOT_SUPPORTED, "Cannot delete from non-managed Hive table");
}
if (!table.get().getPartitionColumns().isEmpty()) {
throw new IllegalArgumentException("Table is partitioned");
}
Path path = new Path(table.get().getStorage().getLocation());
HdfsContext context = new HdfsContext(session, databaseName, tableName, table.get().getStorage().getLocation(), false);
setExclusive((delegate, hdfsEnvironment) -> {
RecursiveDeleteResult recursiveDeleteResult = recursiveDeleteFiles(hdfsEnvironment, context, path, ImmutableSet.of(""), false);
if (!recursiveDeleteResult.getNotDeletedEligibleItems().isEmpty()) {
throw new PrestoException(HIVE_FILESYSTEM_ERROR, format("Error deleting from unpartitioned table %s. These items can not be deleted: %s", schemaTableName, recursiveDeleteResult.getNotDeletedEligibleItems()));
}
});
}
use of com.facebook.presto.spi.TableNotFoundException in project presto by prestodb.
the class SemiTransactionalHiveMetastore method dropTable.
public synchronized void dropTable(HdfsContext context, String databaseName, String tableName) {
setShared();
// Dropping table with partition actions requires cleaning up staging data, which is not implemented yet.
checkNoPartitionAction(databaseName, tableName);
SchemaTableName schemaTableName = new SchemaTableName(databaseName, tableName);
Action<TableAndMore> oldTableAction = tableActions.get(schemaTableName);
if (oldTableAction == null || oldTableAction.getType() == ActionType.ALTER) {
tableActions.put(schemaTableName, new Action<>(ActionType.DROP, null, context));
return;
}
switch(oldTableAction.getType()) {
case DROP:
throw new TableNotFoundException(schemaTableName);
case ADD:
case ALTER:
case INSERT_EXISTING:
throw new UnsupportedOperationException("dropping a table added/modified in the same transaction is not supported");
default:
throw new IllegalStateException("Unknown action type");
}
}
use of com.facebook.presto.spi.TableNotFoundException in project presto by prestodb.
the class SemiTransactionalHiveMetastore method finishInsertIntoExistingTable.
public synchronized void finishInsertIntoExistingTable(ConnectorSession session, String databaseName, String tableName, Path currentLocation, List<String> fileNames, PartitionStatistics statisticsUpdate) {
// Data can only be inserted into partitions and unpartitioned tables. They can never be inserted into a partitioned table.
// Therefore, this method assumes that the table is unpartitioned.
setShared();
SchemaTableName schemaTableName = new SchemaTableName(databaseName, tableName);
Action<TableAndMore> oldTableAction = tableActions.get(schemaTableName);
MetastoreContext metastoreContext = new MetastoreContext(session.getIdentity(), session.getQueryId(), session.getClientInfo(), session.getSource(), getMetastoreHeaders(session), isUserDefinedTypeEncodingEnabled(session), columnConverterProvider);
if (oldTableAction == null || oldTableAction.getData().getTable().getTableType().equals(TEMPORARY_TABLE)) {
Table table = getTable(metastoreContext, databaseName, tableName).orElseThrow(() -> new TableNotFoundException(schemaTableName));
PartitionStatistics currentStatistics = getTableStatistics(metastoreContext, databaseName, tableName);
HdfsContext context = new HdfsContext(session, databaseName, tableName, table.getStorage().getLocation(), false);
tableActions.put(schemaTableName, new Action<>(ActionType.INSERT_EXISTING, new TableAndMore(table, Optional.empty(), Optional.of(currentLocation), Optional.of(fileNames), false, merge(currentStatistics, statisticsUpdate), statisticsUpdate), context));
return;
}
switch(oldTableAction.getType()) {
case DROP:
throw new TableNotFoundException(schemaTableName);
case ADD:
case ALTER:
case INSERT_EXISTING:
throw new UnsupportedOperationException("Inserting into an unpartitioned table that were added, altered, or inserted into in the same transaction is not supported");
default:
throw new IllegalStateException("Unknown action type");
}
}
use of com.facebook.presto.spi.TableNotFoundException in project presto by prestodb.
the class KuduClientSession method openTable.
public KuduTable openTable(SchemaTableName schemaTableName) {
reTryKerberos(kerberosAuthEnabled);
String rawName = schemaEmulation.toRawName(schemaTableName);
try {
return client.openTable(rawName);
} catch (KuduException e) {
log.debug("Error on doOpenTable: " + e, e);
if (!listSchemaNames().contains(schemaTableName.getSchemaName())) {
throw new SchemaNotFoundException(schemaTableName.getSchemaName());
}
throw new TableNotFoundException(schemaTableName);
}
}
Aggregations