Search in sources :

Example 1 with PartitionNotFoundException

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");
    }
}
Also used : SchemaTableName(com.facebook.presto.spi.SchemaTableName) PartitionNotFoundException(com.facebook.presto.hive.PartitionNotFoundException) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList)

Example 2 with PartitionNotFoundException

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);
    }
}
Also used : PartitionNotFoundException(com.facebook.presto.hive.PartitionNotFoundException) SchemaTableName(com.facebook.presto.spi.SchemaTableName) File(java.io.File)

Example 3 with PartitionNotFoundException

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

Example 4 with PartitionNotFoundException

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");
    }
}
Also used : PartitionNotFoundException(com.facebook.presto.hive.PartitionNotFoundException) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) PrestoException(com.facebook.presto.spi.PrestoException) SchemaTableName(com.facebook.presto.spi.SchemaTableName)

Aggregations

PartitionNotFoundException (com.facebook.presto.hive.PartitionNotFoundException)4 SchemaTableName (com.facebook.presto.spi.SchemaTableName)4 PrestoException (com.facebook.presto.spi.PrestoException)2 ImmutableList (com.google.common.collect.ImmutableList)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 File (java.io.File)1