Search in sources :

Example 1 with PartitionNotFoundException

use of io.trino.plugin.hive.PartitionNotFoundException in project trino by trinodb.

the class SemiTransactionalHiveMetastore method dropPartition.

public synchronized void dropPartition(ConnectorSession session, String databaseName, String tableName, List<String> partitionValues, boolean deleteData) {
    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) {
        HdfsContext hdfsContext = new HdfsContext(session);
        if (deleteData) {
            partitionActionsOfTable.put(partitionValues, new Action<>(ActionType.DROP, null, hdfsContext, session.getQueryId()));
        } else {
            partitionActionsOfTable.put(partitionValues, new Action<>(ActionType.DROP_PRESERVE_DATA, null, hdfsContext, session.getQueryId()));
        }
        return;
    }
    switch(oldPartitionAction.getType()) {
        case DROP:
        case DROP_PRESERVE_DATA:
            throw new PartitionNotFoundException(new SchemaTableName(databaseName, tableName), partitionValues);
        case ADD:
        case ALTER:
        case INSERT_EXISTING:
        case DELETE_ROWS:
        case UPDATE:
            throw new TrinoException(NOT_SUPPORTED, format("dropping a partition added in the same transaction is not supported: %s %s %s", databaseName, tableName, partitionValues));
    }
    throw new IllegalStateException("Unknown action type");
}
Also used : PartitionNotFoundException(io.trino.plugin.hive.PartitionNotFoundException) TrinoException(io.trino.spi.TrinoException) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) ArrayList(java.util.ArrayList) ValidTxnWriteIdList(org.apache.hadoop.hive.common.ValidTxnWriteIdList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) LinkedList(java.util.LinkedList) HdfsContext(io.trino.plugin.hive.HdfsEnvironment.HdfsContext) SchemaTableName(io.trino.spi.connector.SchemaTableName)

Example 2 with PartitionNotFoundException

use of io.trino.plugin.hive.PartitionNotFoundException in project trino by trinodb.

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, boolean cleanExtraOutputFilesOnCommit) {
    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) {
        Partition partition = delegate.getPartition(databaseName, tableName, partitionValues).orElseThrow(() -> new PartitionNotFoundException(schemaTableName, partitionValues));
        String partitionName = getPartitionName(databaseName, tableName, partitionValues);
        PartitionStatistics currentStatistics = delegate.getPartitionStatistics(databaseName, tableName, ImmutableSet.of(partitionName)).get(partitionName);
        if (currentStatistics == null) {
            throw new TrinoException(HIVE_METASTORE_ERROR, "currentStatistics is null");
        }
        HdfsContext context = new HdfsContext(session);
        partitionActionsOfTable.put(partitionValues, new Action<>(ActionType.INSERT_EXISTING, new PartitionAndMore(partition, currentLocation, Optional.of(fileNames), merge(currentStatistics, statisticsUpdate), statisticsUpdate, cleanExtraOutputFilesOnCommit), context, session.getQueryId()));
        return;
    }
    switch(oldPartitionAction.getType()) {
        case DROP:
        case DROP_PRESERVE_DATA:
            throw new PartitionNotFoundException(schemaTableName, partitionValues);
        case ADD:
        case ALTER:
        case INSERT_EXISTING:
        case DELETE_ROWS:
        case UPDATE:
            throw new UnsupportedOperationException("Inserting into a partition that were added, altered, or inserted into in the same transaction is not supported");
    }
    throw new IllegalStateException("Unknown action type");
}
Also used : SchemaTableName(io.trino.spi.connector.SchemaTableName) PartitionNotFoundException(io.trino.plugin.hive.PartitionNotFoundException) PartitionStatistics(io.trino.plugin.hive.PartitionStatistics) TrinoException(io.trino.spi.TrinoException) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) ArrayList(java.util.ArrayList) ValidTxnWriteIdList(org.apache.hadoop.hive.common.ValidTxnWriteIdList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) LinkedList(java.util.LinkedList) HdfsContext(io.trino.plugin.hive.HdfsEnvironment.HdfsContext)

Example 3 with PartitionNotFoundException

use of io.trino.plugin.hive.PartitionNotFoundException in project trino by trinodb.

the class FileHiveMetastore method getPartitionStatisticsInternal.

private synchronized PartitionStatistics getPartitionStatisticsInternal(Table table, List<String> partitionValues) {
    Path partitionDirectory = getPartitionMetadataDirectory(table, ImmutableList.copyOf(partitionValues));
    PartitionMetadata partitionMetadata = readSchemaFile(PARTITION, partitionDirectory, partitionCodec).orElseThrow(() -> new PartitionNotFoundException(table.getSchemaTableName(), partitionValues));
    HiveBasicStatistics basicStatistics = getHiveBasicStatistics(partitionMetadata.getParameters());
    return new PartitionStatistics(basicStatistics, partitionMetadata.getColumnStatistics());
}
Also used : Path(org.apache.hadoop.fs.Path) PartitionNotFoundException(io.trino.plugin.hive.PartitionNotFoundException) PartitionStatistics(io.trino.plugin.hive.PartitionStatistics) ThriftMetastoreUtil.getHiveBasicStatistics(io.trino.plugin.hive.metastore.thrift.ThriftMetastoreUtil.getHiveBasicStatistics) HiveBasicStatistics(io.trino.plugin.hive.HiveBasicStatistics)

Example 4 with PartitionNotFoundException

use of io.trino.plugin.hive.PartitionNotFoundException in project trino by trinodb.

the class GlueHiveMetastore method alterPartition.

@Override
public void alterPartition(String databaseName, String tableName, PartitionWithStatistics partition) {
    try {
        PartitionInput newPartition = convertPartition(partition);
        stats.getUpdatePartition().call(() -> glueClient.updatePartition(new UpdatePartitionRequest().withCatalogId(catalogId).withDatabaseName(databaseName).withTableName(tableName).withPartitionInput(newPartition).withPartitionValueList(partition.getPartition().getValues())));
        columnStatisticsProvider.updatePartitionStatistics(partition.getPartition(), partition.getStatistics().getColumnStatistics());
    } catch (EntityNotFoundException e) {
        throw new PartitionNotFoundException(new SchemaTableName(databaseName, tableName), partition.getPartition().getValues());
    } catch (AmazonServiceException e) {
        throw new TrinoException(HIVE_METASTORE_ERROR, e);
    }
}
Also used : PartitionNotFoundException(io.trino.plugin.hive.PartitionNotFoundException) AmazonServiceException(com.amazonaws.AmazonServiceException) TrinoException(io.trino.spi.TrinoException) BatchUpdatePartitionRequest(com.amazonaws.services.glue.model.BatchUpdatePartitionRequest) UpdatePartitionRequest(com.amazonaws.services.glue.model.UpdatePartitionRequest) EntityNotFoundException(com.amazonaws.services.glue.model.EntityNotFoundException) SchemaTableName(io.trino.spi.connector.SchemaTableName) PartitionInput(com.amazonaws.services.glue.model.PartitionInput)

Example 5 with PartitionNotFoundException

use of io.trino.plugin.hive.PartitionNotFoundException in project trino by trinodb.

the class FileHiveMetastore method updatePartitionStatistics.

@Override
public synchronized void updatePartitionStatistics(Table table, Map<String, Function<PartitionStatistics, PartitionStatistics>> updates) {
    updates.forEach((partitionName, update) -> {
        PartitionStatistics originalStatistics = getPartitionStatisticsInternal(table, extractPartitionValues(partitionName));
        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(table.getDatabaseName(), table.getTableName()), partitionValues));
        PartitionMetadata updatedMetadata = partitionMetadata.withParameters(updateStatisticsParameters(partitionMetadata.getParameters(), updatedStatistics.getBasicStatistics())).withColumnStatistics(updatedStatistics.getColumnStatistics());
        writeSchemaFile(PARTITION, partitionDirectory, partitionCodec, updatedMetadata, true);
    });
}
Also used : Path(org.apache.hadoop.fs.Path) PartitionNotFoundException(io.trino.plugin.hive.PartitionNotFoundException) PartitionStatistics(io.trino.plugin.hive.PartitionStatistics) SchemaTableName(io.trino.spi.connector.SchemaTableName)

Aggregations

PartitionNotFoundException (io.trino.plugin.hive.PartitionNotFoundException)6 SchemaTableName (io.trino.spi.connector.SchemaTableName)5 TrinoException (io.trino.spi.TrinoException)4 PartitionStatistics (io.trino.plugin.hive.PartitionStatistics)3 Path (org.apache.hadoop.fs.Path)3 AmazonServiceException (com.amazonaws.AmazonServiceException)2 ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)2 HdfsContext (io.trino.plugin.hive.HdfsEnvironment.HdfsContext)2 ArrayList (java.util.ArrayList)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 ValidTxnWriteIdList (org.apache.hadoop.hive.common.ValidTxnWriteIdList)2 BatchUpdatePartitionRequest (com.amazonaws.services.glue.model.BatchUpdatePartitionRequest)1 DeletePartitionRequest (com.amazonaws.services.glue.model.DeletePartitionRequest)1 EntityNotFoundException (com.amazonaws.services.glue.model.EntityNotFoundException)1 PartitionInput (com.amazonaws.services.glue.model.PartitionInput)1 UpdatePartitionRequest (com.amazonaws.services.glue.model.UpdatePartitionRequest)1 HiveBasicStatistics (io.trino.plugin.hive.HiveBasicStatistics)1 Partition (io.trino.plugin.hive.metastore.Partition)1