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