Search in sources :

Example 76 with TableNotFoundException

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");
    }
}
Also used : TableNotFoundException(com.facebook.presto.spi.TableNotFoundException) Collection(java.util.Collection) SchemaTableName(com.facebook.presto.spi.SchemaTableName) PrestoPrincipal(com.facebook.presto.spi.security.PrestoPrincipal)

Example 77 with TableNotFoundException

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()));
        }
    });
}
Also used : Path(org.apache.hadoop.fs.Path) TableNotFoundException(com.facebook.presto.spi.TableNotFoundException) PrestoException(com.facebook.presto.spi.PrestoException) HdfsContext(com.facebook.presto.hive.HdfsContext) SchemaTableName(com.facebook.presto.spi.SchemaTableName)

Example 78 with TableNotFoundException

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");
    }
}
Also used : TableNotFoundException(com.facebook.presto.spi.TableNotFoundException) SchemaTableName(com.facebook.presto.spi.SchemaTableName)

Example 79 with TableNotFoundException

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");
    }
}
Also used : TableNotFoundException(com.facebook.presto.spi.TableNotFoundException) HdfsContext(com.facebook.presto.hive.HdfsContext) SchemaTableName(com.facebook.presto.spi.SchemaTableName)

Example 80 with TableNotFoundException

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);
    }
}
Also used : TableNotFoundException(com.facebook.presto.spi.TableNotFoundException) SchemaNotFoundException(com.facebook.presto.spi.SchemaNotFoundException) KuduException(org.apache.kudu.client.KuduException)

Aggregations

TableNotFoundException (com.facebook.presto.spi.TableNotFoundException)95 SchemaTableName (com.facebook.presto.spi.SchemaTableName)68 PrestoException (com.facebook.presto.spi.PrestoException)38 Table (com.facebook.presto.hive.metastore.Table)36 ImmutableMap (com.google.common.collect.ImmutableMap)33 MetastoreContext (com.facebook.presto.hive.metastore.MetastoreContext)28 ImmutableList (com.google.common.collect.ImmutableList)28 List (java.util.List)24 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)23 ColumnHandle (com.facebook.presto.spi.ColumnHandle)22 ColumnMetadata (com.facebook.presto.spi.ColumnMetadata)20 Constraint (com.facebook.presto.spi.Constraint)20 Map (java.util.Map)20 Set (java.util.Set)20 Optional (java.util.Optional)19 Column (com.facebook.presto.hive.metastore.Column)18 PartitionStatistics (com.facebook.presto.hive.metastore.PartitionStatistics)18 HashSet (java.util.HashSet)18 SystemTable (com.facebook.presto.spi.SystemTable)17 ImmutableMap.toImmutableMap (com.google.common.collect.ImmutableMap.toImmutableMap)17