Source:
<code>public synchronized void updatePartitionStatistics(String databaseName, String tableName, String partitionName, Function<PartitionStatistics, PartitionStatistics> update) { PartitionStatistics currentStatistics = requireNonNull(getPartitionStatistics(databaseName, tableName, ImmutableSet.of(partitionName)).get(partitionName), "currentStatistics is null"); PartitionStatistics updatedStatistics = update.apply(currentStatistics); List<Partition> partitions = getPartitionsByNames(databaseName, tableName, ImmutableList.of(partitionName)); <START> verify(partitions.size() == 1, "exactly one partition is expected to be returned: %s", partitions.size()); <END> Partition partition = getOnlyElement(partitions); partition.setParameters(updateStatisticParameters(partition.getParameters(), updatedStatistics.getBasicStatistics())); alterPartition(databaseName, tableName, partition); com.facebook.presto.hive.metastore.Table table = getTable(databaseName, tableName) .map(ThriftMetastoreUtil::fromMetastoreApiTable) .orElseThrow(() -> new TableNotFoundException(new SchemaTableName(databaseName, tableName))); List<ColumnStatisticsObj> metastoreColumnStatistics = updatedStatistics.getColumnStatistics().entrySet() .stream() .map(entry -> createMetastoreColumnStatistics(entry.getKey(), table.getColumn(entry.getKey()).get().getType(), entry.getValue())) .collect(toImmutableList()); if (!metastoreColumnStatistics.isEmpty()) { setPartitionColumnStatistics(databaseName, tableName, partitionName, metastoreColumnStatistics); } Set<String> removedStatistics = difference(currentStatistics.getColumnStatistics().keySet(), updatedStatistics.getColumnStatistics().keySet()); removedStatistics.forEach(column -> deletePartitionColumnStatistics(databaseName, tableName, partitionName, column)); }</code><technical_language>Throw HIVE_METASTORE_ERROR</technical_language>

Target:
public synchronized void updatePartitionStatistics(String databaseName, String tableName, String partitionName, Function<PartitionStatistics, PartitionStatistics> update) { PartitionStatistics currentStatistics = requireNonNull( getPartitionStatistics(databaseName, tableName, ImmutableSet.of(partitionName)).get(partitionName), "getPartitionStatistics() returned null"); PartitionStatistics updatedStatistics = update.apply(currentStatistics); List<Partition> partitions = getPartitionsByNames(databaseName, tableName, ImmutableList.of(partitionName)); if (partitions.size() != 1) { throw new PrestoException(HIVE_METASTORE_ERROR, "exactly one partition is expected to be returned: " + partitions.size()); } Partition originalPartition = getOnlyElement(partitions); Partition modifiedPartition = originalPartition.deepCopy(); modifiedPartition.setParameters(updateStatisticParameters(modifiedPartition.getParameters(), updatedStatistics.getBasicStatistics())); alterPartition(databaseName, tableName, modifiedPartition); com.facebook.presto.hive.metastore.Table table = getTable(databaseName, tableName) .map(ThriftMetastoreUtil::fromMetastoreApiTable) .orElseThrow(() -> new TableNotFoundException(new SchemaTableName(databaseName, tableName))); List<ColumnStatisticsObj> metastoreColumnStatistics = updatedStatistics.getColumnStatistics().entrySet() .stream() .map(entry -> createMetastoreColumnStatistics(entry.getKey(), table.getColumn(entry.getKey()).get().getType(), entry.getValue())) .collect(toImmutableList()); if (!metastoreColumnStatistics.isEmpty()) { setPartitionColumnStatistics(databaseName, tableName, partitionName, metastoreColumnStatistics); } Set<String> removedStatistics = difference(currentStatistics.getColumnStatistics().keySet(), updatedStatistics.getColumnStatistics().keySet()); removedStatistics.forEach(column -> deletePartitionColumnStatistics(databaseName, tableName, partitionName, column)); }