Search in sources :

Example 1 with PartitionNotFoundException

use of io.prestosql.plugin.hive.PartitionNotFoundException in project hetu-core by openlookeng.

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 ConcurrentHashMap<>());
    Action<PartitionAndMore> oldPartitionAction = partitionActionsOfTable.get(partitionValues);
    if (oldPartitionAction == null) {
        HdfsContext hdfsContext = new HdfsContext(session, databaseName, tableName);
        HiveIdentity identity = new HiveIdentity(session);
        partitionActionsOfTable.put(partitionValues, new Action<>(ActionType.DROP, null, hdfsContext, identity));
        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 : PrestoException(io.prestosql.spi.PrestoException) SchemaTableName(io.prestosql.spi.connector.SchemaTableName) HiveIdentity(io.prestosql.plugin.hive.authentication.HiveIdentity) PartitionNotFoundException(io.prestosql.plugin.hive.PartitionNotFoundException) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) ValidTxnWriteIdList(org.apache.hadoop.hive.common.ValidTxnWriteIdList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) HdfsContext(io.prestosql.plugin.hive.HdfsEnvironment.HdfsContext)

Example 2 with PartitionNotFoundException

use of io.prestosql.plugin.hive.PartitionNotFoundException in project hetu-core by openlookeng.

the class SemiTransactionalHiveMetastore method finishInsertIntoExistingPartition.

public synchronized void finishInsertIntoExistingPartition(ConnectorSession session, String databaseName, String tableName, List<String> partitionValues, Path currentLocation, List<String> fileNames, PartitionStatistics statisticsUpdate, HiveACIDWriteType acidWriteType) {
    setShared();
    isVacuumIncluded |= HiveACIDWriteType.isVacuum(acidWriteType);
    HiveIdentity identity = new HiveIdentity(session);
    SchemaTableName schemaTableName = new SchemaTableName(databaseName, tableName);
    Map<List<String>, Action<PartitionAndMore>> partitionActionsOfTable = partitionActions.computeIfAbsent(schemaTableName, k -> new LinkedHashMap<>());
    Action<PartitionAndMore> oldPartitionAction = partitionActionsOfTable.get(partitionValues);
    if (oldPartitionAction == null) {
        Partition partition = delegate.getPartition(identity, databaseName, tableName, partitionValues).orElseThrow(() -> new PartitionNotFoundException(schemaTableName, partitionValues));
        String partitionName = getPartitionName(identity, databaseName, tableName, partitionValues);
        PartitionStatistics mergedStatistics = statisticsUpdate;
        boolean updateStats = canUpdateStats(session, acidWriteType);
        if (updateStats) {
            PartitionStatistics currentStatistics = closure.getPartitionStatistics(identity, databaseName, tableName, ImmutableSet.of(partitionName)).get(partitionName);
            if (currentStatistics == null) {
                throw new PrestoException(HiveErrorCode.HIVE_METASTORE_ERROR, "currentStatistics is null");
            }
            mergedStatistics = merge(currentStatistics, statisticsUpdate);
        }
        HdfsContext context = new HdfsContext(session, databaseName, tableName);
        partitionActionsOfTable.put(partitionValues, new Action<>(ActionType.INSERT_EXISTING, new PartitionAndMore(identity, partition, currentLocation, Optional.of(fileNames), mergedStatistics, statisticsUpdate, updateStats), context, identity));
        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 : PrestoException(io.prestosql.spi.PrestoException) SchemaTableName(io.prestosql.spi.connector.SchemaTableName) HiveIdentity(io.prestosql.plugin.hive.authentication.HiveIdentity) PartitionNotFoundException(io.prestosql.plugin.hive.PartitionNotFoundException) PartitionStatistics(io.prestosql.plugin.hive.PartitionStatistics) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) ValidTxnWriteIdList(org.apache.hadoop.hive.common.ValidTxnWriteIdList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) HdfsContext(io.prestosql.plugin.hive.HdfsEnvironment.HdfsContext)

Example 3 with PartitionNotFoundException

use of io.prestosql.plugin.hive.PartitionNotFoundException in project hetu-core by openlookeng.

the class GlueHiveMetastore method updatePartitionStatistics.

@Override
public void updatePartitionStatistics(HiveIdentity identity, String databaseName, String tableName, String partitionName, Function<PartitionStatistics, PartitionStatistics> update) {
    List<String> partitionValues = toPartitionValues(partitionName);
    Partition partition = getPartition(identity, databaseName, tableName, partitionValues).orElseThrow(() -> new PrestoException(HIVE_PARTITION_DROPPED_DURING_QUERY, "Statistics result does not contain entry for partition: " + partitionName));
    PartitionStatistics currentStatistics = getPartitionStatistics(partition);
    PartitionStatistics updatedStatistics = update.apply(currentStatistics);
    if (!updatedStatistics.getColumnStatistics().isEmpty()) {
        throw new PrestoException(NOT_SUPPORTED, "Glue metastore does not support column level statistics");
    }
    try {
        PartitionInput partitionInput = GlueInputConverter.convertPartition(partition);
        partitionInput.setParameters(ThriftMetastoreUtil.updateStatisticsParameters(partition.getParameters(), updatedStatistics.getBasicStatistics()));
        glueClient.updatePartition(new UpdatePartitionRequest().withCatalogId(catalogId).withDatabaseName(databaseName).withTableName(tableName).withPartitionValueList(partition.getValues()).withPartitionInput(partitionInput));
    } catch (EntityNotFoundException e) {
        throw new PartitionNotFoundException(new SchemaTableName(databaseName, tableName), partitionValues);
    } catch (AmazonServiceException e) {
        throw new PrestoException(HiveErrorCode.HIVE_METASTORE_ERROR, e);
    }
}
Also used : Partition(io.prestosql.plugin.hive.metastore.Partition) PartitionNotFoundException(io.prestosql.plugin.hive.PartitionNotFoundException) PartitionStatistics(io.prestosql.plugin.hive.PartitionStatistics) AmazonServiceException(com.amazonaws.AmazonServiceException) PrestoException(io.prestosql.spi.PrestoException) UpdatePartitionRequest(com.amazonaws.services.glue.model.UpdatePartitionRequest) EntityNotFoundException(com.amazonaws.services.glue.model.EntityNotFoundException) SchemaTableName(io.prestosql.spi.connector.SchemaTableName) PartitionInput(com.amazonaws.services.glue.model.PartitionInput)

Example 4 with PartitionNotFoundException

use of io.prestosql.plugin.hive.PartitionNotFoundException in project hetu-core by openlookeng.

the class FileHiveMetastore method updatePartitionStatistics.

@Override
public synchronized void updatePartitionStatistics(HiveIdentity identity, String databaseName, String tableName, String partitionName, Function<PartitionStatistics, PartitionStatistics> update) {
    Table table = getRequiredTable(databaseName, tableName);
    PartitionStatistics originalStatistics = getPartitionStatistics(identity, extractPartitionValues(partitionName), table);
    PartitionStatistics updatedStatistics = update.apply(originalStatistics);
    List<String> partitionValues = extractPartitionValues(partitionName);
    Path partitionDirectory = getPartitionMetadataDirectory(table, partitionValues);
    PartitionMetadata partitionMetadata = readSchemaFile("partition", partitionDirectory, partitionCodec).orElseThrow(() -> new PartitionNotFoundException(new SchemaTableName(databaseName, tableName), partitionValues));
    PartitionMetadata updatedMetadata = partitionMetadata.withParameters(ThriftMetastoreUtil.updateStatisticsParameters(partitionMetadata.getParameters(), updatedStatistics.getBasicStatistics())).withColumnStatistics(updatedStatistics.getColumnStatistics());
    writeSchemaFile("partition", partitionDirectory, partitionCodec, updatedMetadata, true);
}
Also used : Path(org.apache.hadoop.fs.Path) PartitionNotFoundException(io.prestosql.plugin.hive.PartitionNotFoundException) Table(io.prestosql.plugin.hive.metastore.Table) PartitionStatistics(io.prestosql.plugin.hive.PartitionStatistics) SchemaTableName(io.prestosql.spi.connector.SchemaTableName)

Example 5 with PartitionNotFoundException

use of io.prestosql.plugin.hive.PartitionNotFoundException in project boostkit-bigdata by kunpengcompute.

the class GlueHiveMetastore method dropPartition.

@Override
public void dropPartition(HiveIdentity identity, String databaseName, String tableName, List<String> parts, boolean deleteData) {
    Table table = getTableOrElseThrow(identity, databaseName, tableName);
    Partition partition = getPartition(identity, databaseName, tableName, parts).orElseThrow(() -> new PartitionNotFoundException(new SchemaTableName(databaseName, tableName), parts));
    try {
        glueClient.deletePartition(new DeletePartitionRequest().withCatalogId(catalogId).withDatabaseName(databaseName).withTableName(tableName).withPartitionValues(parts));
    } catch (AmazonServiceException e) {
        throw new PrestoException(HiveErrorCode.HIVE_METASTORE_ERROR, e);
    }
    String partLocation = partition.getStorage().getLocation();
    if (deleteData && isManagedTable(table) && !isNullOrEmpty(partLocation)) {
        deleteDir(hdfsContext, hdfsEnvironment, new Path(partLocation), true);
    }
}
Also used : Path(org.apache.hadoop.fs.Path) Partition(io.prestosql.plugin.hive.metastore.Partition) PartitionNotFoundException(io.prestosql.plugin.hive.PartitionNotFoundException) Table(io.prestosql.plugin.hive.metastore.Table) AmazonServiceException(com.amazonaws.AmazonServiceException) DeletePartitionRequest(com.amazonaws.services.glue.model.DeletePartitionRequest) PrestoException(io.prestosql.spi.PrestoException) SchemaTableName(io.prestosql.spi.connector.SchemaTableName)

Aggregations

PartitionNotFoundException (io.prestosql.plugin.hive.PartitionNotFoundException)14 SchemaTableName (io.prestosql.spi.connector.SchemaTableName)12 PrestoException (io.prestosql.spi.PrestoException)10 PartitionStatistics (io.prestosql.plugin.hive.PartitionStatistics)8 AmazonServiceException (com.amazonaws.AmazonServiceException)6 Path (org.apache.hadoop.fs.Path)6 EntityNotFoundException (com.amazonaws.services.glue.model.EntityNotFoundException)4 PartitionInput (com.amazonaws.services.glue.model.PartitionInput)4 UpdatePartitionRequest (com.amazonaws.services.glue.model.UpdatePartitionRequest)4 ImmutableList (com.google.common.collect.ImmutableList)4 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)4 HdfsContext (io.prestosql.plugin.hive.HdfsEnvironment.HdfsContext)4 HiveIdentity (io.prestosql.plugin.hive.authentication.HiveIdentity)4 Partition (io.prestosql.plugin.hive.metastore.Partition)4 Table (io.prestosql.plugin.hive.metastore.Table)4 ArrayList (java.util.ArrayList)4 List (java.util.List)4 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)4 ValidTxnWriteIdList (org.apache.hadoop.hive.common.ValidTxnWriteIdList)4 DeletePartitionRequest (com.amazonaws.services.glue.model.DeletePartitionRequest)2