use of com.facebook.presto.hive.PartitionNotFoundException in project presto by prestodb.
the class SemiTransactionalHiveMetastore method finishInsertIntoExistingPartition.
public synchronized void finishInsertIntoExistingPartition(ConnectorSession session, String databaseName, String tableName, List<String> partitionValues, Path currentLocation, List<String> fileNames) {
setShared();
SchemaTableName schemaTableName = new SchemaTableName(databaseName, tableName);
Map<List<String>, Action<PartitionAndMore>> partitionActionsOfTable = partitionActions.computeIfAbsent(schemaTableName, k -> new HashMap<>());
Action<PartitionAndMore> oldPartitionAction = partitionActionsOfTable.get(partitionValues);
if (oldPartitionAction == null) {
Optional<Partition> partition = delegate.getPartition(databaseName, tableName, partitionValues);
if (!partition.isPresent()) {
throw new PartitionNotFoundException(schemaTableName, partitionValues);
}
partitionActionsOfTable.put(partitionValues, new Action<>(ActionType.INSERT_EXISTING, new PartitionAndMore(partition.get(), currentLocation, Optional.of(fileNames)), session.getUser(), session.getQueryId()));
return;
}
switch(oldPartitionAction.getType()) {
case DROP:
throw new PartitionNotFoundException(schemaTableName, partitionValues);
case ADD:
case ALTER:
case INSERT_EXISTING:
throw new UnsupportedOperationException("Inserting into a partition 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.hive.PartitionNotFoundException in project presto by prestodb.
the class TestingHiveMetastore method dropPartition.
@Override
public synchronized void dropPartition(String databaseName, String tableName, List<String> parts, boolean deleteData) {
Table table = getRequiredTable(new SchemaTableName(databaseName, tableName));
Partition partition = partitions.remove(new PartitionName(databaseName, tableName, parts));
if (partition == null) {
throw new PartitionNotFoundException(new SchemaTableName(databaseName, tableName), parts);
}
if (deleteData && table.getTableType().equals(MANAGED_TABLE.name())) {
File directory = new File(URI.create(partition.getStorage().getLocation()));
checkArgument(isParentDir(directory, baseDirectory), "Partition directory must be inside of the metastore base directory");
deleteRecursively(directory);
}
}
use of com.facebook.presto.hive.PartitionNotFoundException in project presto by prestodb.
the class TestingHiveMetastore method alterPartition.
@Override
public synchronized void alterPartition(String databaseName, String tableName, Partition partition) {
PartitionName partitionName = new PartitionName(databaseName, tableName, partition.getValues());
Partition oldPartition = partitions.get(partitionName);
if (oldPartition == null) {
throw new PartitionNotFoundException(new SchemaTableName(databaseName, tableName), partition.getValues());
}
if (!oldPartition.getStorage().getLocation().equals(partition.getStorage().getLocation())) {
throw new PrestoException(HIVE_METASTORE_ERROR, "alterPartition can not change storage location");
}
dropPartition(databaseName, tableName, partition.getValues(), false);
addPartitions(databaseName, tableName, ImmutableList.of(partition));
}
use of com.facebook.presto.hive.PartitionNotFoundException in project presto by prestodb.
the class SemiTransactionalHiveMetastore method dropPartition.
public synchronized void dropPartition(ConnectorSession session, String databaseName, String tableName, List<String> partitionValues) {
setShared();
Map<List<String>, Action<PartitionAndMore>> partitionActionsOfTable = partitionActions.computeIfAbsent(new SchemaTableName(databaseName, tableName), k -> new HashMap<>());
Action<PartitionAndMore> oldPartitionAction = partitionActionsOfTable.get(partitionValues);
if (oldPartitionAction == null) {
partitionActionsOfTable.put(partitionValues, new Action<>(ActionType.DROP, null, session.getUser(), session.getQueryId()));
return;
}
switch(oldPartitionAction.getType()) {
case DROP:
throw new PartitionNotFoundException(new SchemaTableName(databaseName, tableName), partitionValues);
case ADD:
case ALTER:
case INSERT_EXISTING:
throw new PrestoException(NOT_SUPPORTED, format("dropping a partition added in the same transaction is not supported: %s %s %s", databaseName, tableName, partitionValues));
default:
throw new IllegalStateException("Unknown action type");
}
}
Aggregations