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);
}
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);
}
}
}
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);
}
}
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);
}
}
}
}
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);
}
Aggregations