Search in sources :

Example 36 with TableNotFoundException

use of com.facebook.presto.spi.TableNotFoundException in project presto by prestodb.

the class InMemoryHiveMetastore method alterPartition.

@Override
public synchronized void alterPartition(String databaseName, String tableName, Partition partition) {
    Optional<Table> table = getTable(databaseName, tableName);
    if (!table.isPresent()) {
        throw new TableNotFoundException(new SchemaTableName(databaseName, tableName));
    }
    String partitionName = createPartitionName(partition, table.get());
    this.partitions.put(PartitionName.partition(databaseName, tableName, partitionName), partition);
}
Also used : TableNotFoundException(com.facebook.presto.spi.TableNotFoundException) Table(org.apache.hadoop.hive.metastore.api.Table) SchemaTableName(com.facebook.presto.spi.SchemaTableName)

Example 37 with TableNotFoundException

use of com.facebook.presto.spi.TableNotFoundException in project presto by prestodb.

the class TestingHiveMetastore method dropTable.

@Override
public synchronized void dropTable(String databaseName, String tableName, boolean deleteData) {
    SchemaTableName schemaTableName = new SchemaTableName(databaseName, tableName);
    Table table = relations.remove(schemaTableName);
    if (table == null) {
        throw new TableNotFoundException(schemaTableName);
    }
    List<String> locations = listAllDataPaths(table);
    // remove partitions
    ImmutableList.copyOf(partitions.keySet()).stream().filter(partitionName -> partitionName.matches(databaseName, tableName)).forEach(partitions::remove);
    // remove permissions
    ImmutableList.copyOf(tablePrivileges.keySet()).stream().filter(key -> key.matches(databaseName, tableName)).forEach(tablePrivileges::remove);
    // remove data
    if (deleteData && table.getTableType().equals(MANAGED_TABLE.name())) {
        for (String location : locations) {
            File directory = new File(URI.create(location));
            checkArgument(isParentDir(directory, baseDirectory), "Table directory must be inside of the metastore base directory");
            deleteRecursively(directory);
        }
    }
}
Also used : MetastoreUtil.makePartName(com.facebook.presto.hive.metastore.MetastoreUtil.makePartName) Collections.unmodifiableList(java.util.Collections.unmodifiableList) HiveType(com.facebook.presto.hive.HiveType) PartitionNotFoundException(com.facebook.presto.hive.PartitionNotFoundException) EXTERNAL_TABLE(org.apache.hadoop.hive.metastore.TableType.EXTERNAL_TABLE) US(java.util.Locale.US) HashMap(java.util.HashMap) PrestoException(com.facebook.presto.spi.PrestoException) ArrayList(java.util.ArrayList) OWNERSHIP(com.facebook.presto.hive.metastore.HivePrivilegeInfo.HivePrivilege.OWNERSHIP) HashSet(java.util.HashSet) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) SchemaTableName(com.facebook.presto.spi.SchemaTableName) HIVE_METASTORE_ERROR(com.facebook.presto.hive.HiveErrorCode.HIVE_METASTORE_ERROR) ColumnNotFoundException(com.facebook.presto.spi.ColumnNotFoundException) ImmutableList(com.google.common.collect.ImmutableList) ALREADY_EXISTS(com.facebook.presto.spi.StandardErrorCode.ALREADY_EXISTS) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) HiveUtil.toPartitionValues(com.facebook.presto.hive.HiveUtil.toPartitionValues) TableAlreadyExistsException(com.facebook.presto.hive.TableAlreadyExistsException) URI(java.net.URI) ImmutableCollectors.toImmutableList(com.facebook.presto.util.ImmutableCollectors.toImmutableList) VIRTUAL_VIEW(org.apache.hadoop.hive.metastore.TableType.VIRTUAL_VIEW) EnumSet(java.util.EnumSet) FileUtils.deleteRecursively(io.airlift.testing.FileUtils.deleteRecursively) ImmutableSet(com.google.common.collect.ImmutableSet) ROLE(com.facebook.presto.hive.metastore.PrincipalType.ROLE) ImmutableMap(com.google.common.collect.ImmutableMap) Collection(java.util.Collection) Set(java.util.Set) ThreadSafe(javax.annotation.concurrent.ThreadSafe) DEFAULT_DATABASE_NAME(com.facebook.presto.hive.metastore.Database.DEFAULT_DATABASE_NAME) GuardedBy(javax.annotation.concurrent.GuardedBy) MANAGED_TABLE(org.apache.hadoop.hive.metastore.TableType.MANAGED_TABLE) File(java.io.File) Objects(java.util.Objects) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) TableNotFoundException(com.facebook.presto.spi.TableNotFoundException) NOT_SUPPORTED(com.facebook.presto.spi.StandardErrorCode.NOT_SUPPORTED) TableType(org.apache.hadoop.hive.metastore.TableType) Entry(java.util.Map.Entry) USER(com.facebook.presto.hive.metastore.PrincipalType.USER) Optional(java.util.Optional) MoreObjects.toStringHelper(com.google.common.base.MoreObjects.toStringHelper) TableNotFoundException(com.facebook.presto.spi.TableNotFoundException) SchemaTableName(com.facebook.presto.spi.SchemaTableName) File(java.io.File)

Example 38 with TableNotFoundException

use of com.facebook.presto.spi.TableNotFoundException in project presto by prestodb.

the class InMemoryHiveMetastore method addPartitions.

@Override
public synchronized void addPartitions(String databaseName, String tableName, List<Partition> partitions) {
    Optional<Table> table = getTable(databaseName, tableName);
    if (!table.isPresent()) {
        throw new TableNotFoundException(new SchemaTableName(databaseName, tableName));
    }
    for (Partition partition : partitions) {
        String partitionName = createPartitionName(partition, table.get());
        partition = partition.deepCopy();
        if (partition.getParameters() == null) {
            partition.setParameters(ImmutableMap.of());
        }
        this.partitions.put(PartitionName.partition(databaseName, tableName, partitionName), partition);
    }
}
Also used : TableNotFoundException(com.facebook.presto.spi.TableNotFoundException) Partition(org.apache.hadoop.hive.metastore.api.Partition) Table(org.apache.hadoop.hive.metastore.api.Table) SchemaTableName(com.facebook.presto.spi.SchemaTableName)

Example 39 with TableNotFoundException

use of com.facebook.presto.spi.TableNotFoundException in project presto by prestodb.

the class InMemoryHiveMetastore method dropTable.

@Override
public synchronized void dropTable(String databaseName, String tableName, boolean deleteData) {
    List<String> locations = listAllDataPaths(this, databaseName, tableName);
    SchemaTableName schemaTableName = new SchemaTableName(databaseName, tableName);
    Table table = relations.remove(schemaTableName);
    if (table == null) {
        throw new TableNotFoundException(schemaTableName);
    }
    views.remove(schemaTableName);
    partitions.keySet().removeIf(partitionName -> partitionName.matches(databaseName, tableName));
    // remove data
    if (deleteData && table.getTableType().equals(MANAGED_TABLE.name())) {
        for (String location : locations) {
            if (location != null) {
                File directory = new File(new Path(location).toUri());
                checkArgument(isParentDir(directory, baseDirectory), "Table directory must be inside of the metastore base directory");
                deleteRecursively(directory);
            }
        }
    }
}
Also used : Path(org.apache.hadoop.fs.Path) TableNotFoundException(com.facebook.presto.spi.TableNotFoundException) Table(org.apache.hadoop.hive.metastore.api.Table) SchemaTableName(com.facebook.presto.spi.SchemaTableName) File(java.io.File)

Aggregations

TableNotFoundException (com.facebook.presto.spi.TableNotFoundException)39 SchemaTableName (com.facebook.presto.spi.SchemaTableName)26 PrestoException (com.facebook.presto.spi.PrestoException)11 ImmutableMap (com.google.common.collect.ImmutableMap)11 ColumnHandle (com.facebook.presto.spi.ColumnHandle)8 Table (com.facebook.presto.hive.metastore.Table)7 ImmutableList (com.google.common.collect.ImmutableList)6 ArrayList (java.util.ArrayList)6 List (java.util.List)5 AccumuloTable (com.facebook.presto.accumulo.metadata.AccumuloTable)4 ColumnMetadata (com.facebook.presto.spi.ColumnMetadata)4 ConnectorTableMetadata (com.facebook.presto.spi.ConnectorTableMetadata)4 Constraint (com.facebook.presto.spi.Constraint)4 Slice (io.airlift.slice.Slice)4 Collectors.toList (java.util.stream.Collectors.toList)4 Path (org.apache.hadoop.fs.Path)4 AccumuloTableHandle (com.facebook.presto.accumulo.model.AccumuloTableHandle)3 HiveTableProperties.getHiveStorageFormat (com.facebook.presto.hive.HiveTableProperties.getHiveStorageFormat)3 Table (org.apache.hadoop.hive.metastore.api.Table)3 AccumuloColumnHandle (com.facebook.presto.accumulo.model.AccumuloColumnHandle)2