code: private void dropExtraColumnStatisticsAfterAlterPartition(
              String databaseName,
              String tableName,
              PartitionWithStatistics partitionWithStatistics)
      {
          List<String> dataColumns = partitionWithStatistics.getPartition().getColumns().stream()
                  .map(Column::getName)
                  .collect(toImmutableList());
  
          Set<String> columnsWithMissingStatistics = new HashSet<>(dataColumns);
          columnsWithMissingStatistics.removeAll(partitionWithStatistics.getStatistics().getColumnStatistics().keySet());
  
          // In case new partition had the statistics computed for all the columns, the storePartitionColumnStatistics
          // call in the alterPartition will just overwrite the old statistics. There is no need to explicitly remove anything.
          if (columnsWithMissingStatistics.isEmpty()) {
              return;
          }
  
          // check if statistics for the columnsWithMissingStatistics are actually stored in the metastore
          // when trying to remove any missing statistics the metastore throws NoSuchObjectException
          String partitionName = partitionWithStatistics.getPartitionName();
          List<ColumnStatisticsObj> statisticsToBeRemoved = getMetastorePartitionColumnStatistics(
                  databaseName,
                  tableName,
                  ImmutableSet.of(partitionName),
                  ImmutableList.copyOf(columnsWithMissingStatistics))
                  .getOrDefault(partitionName, ImmutableList.of());
  
          for (ColumnStatisticsObj statistics : statisticsToBeRemoved) {
              deletePartitionColumnStatistics(databaseName, tableName, partitionName, statistics.getColName());
          }
      }
docs: /*
  After altering a partition metastore preserves all column statistics for that partition.
  
  The old statistics are supposed to be replaced by storing the new partition statistics.
  
  In case when the new statistics are not present for some columns, or if the table schema has changed
  if is needed to explicitly remove the statistics from the metastore for that columns.