Search in sources :

Example 46 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 47 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 48 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 49 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)

Example 50 with TableNotFoundException

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

the class NativeCassandraSession method getTableMetadata.

private TableMetadata getTableMetadata(SchemaTableName schemaTableName) {
    String schemaName = schemaTableName.getSchemaName();
    String tableName = schemaTableName.getTableName();
    KeyspaceMetadata keyspaceMetadata = getCheckedKeyspaceMetadata(schemaName);
    TableMetadata tableMetadata = keyspaceMetadata.getTable(tableName);
    if (tableMetadata != null) {
        return tableMetadata;
    }
    for (TableMetadata table : keyspaceMetadata.getTables()) {
        if (table.getName().equalsIgnoreCase(tableName)) {
            return table;
        }
    }
    throw new TableNotFoundException(schemaTableName);
}
Also used : TableMetadata(com.datastax.driver.core.TableMetadata) TableNotFoundException(com.facebook.presto.spi.TableNotFoundException) KeyspaceMetadata(com.datastax.driver.core.KeyspaceMetadata)

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