public List<Partition> alterPartitions(MTable table, List<String> partNames,
                                         List<Partition> newParts, String queryWriteIdList) throws MetaException {
    List<Object[]> rows = Batchable.runBatched(batchSize, partNames, new Batchable<String, Object[]>() {
      @Override
      public List<Object[]> run(List<String> input) throws Exception {
        String filter = "" + PARTITIONS + ".\"PART_NAME\" in (" + makeParams(input.size()) + ")";
        List<String> columns = Arrays.asList("\"PART_ID\"", "\"PART_NAME\"", "\"SD_ID\"", "\"WRITE_ID\"");
        return getPartitionFieldsViaSqlFilter(table.getDatabase().getCatalogName(), table.getDatabase().getName(),
                table.getTableName(), columns, filter, input, Collections.emptyList(), null);
      }
    });
    Map<List<String>, Long> partValuesToId = new HashMap<>();
    Map<Long, Long> partIdToSdId = new HashMap<>();
    Map<Long, Long> partIdToWriteId = new HashMap<>();
    for (Object[] row : rows) {
      Long partId = MetastoreDirectSqlUtils.extractSqlLong(row[0]);
      Long sdId = MetastoreDirectSqlUtils.extractSqlLong(row[2]);
      Long writeId = MetastoreDirectSqlUtils.extractSqlLong(row[3]);
      partIdToSdId.put(partId, sdId);
      partIdToWriteId.put(partId, writeId);
      List<String> partValues = Warehouse.getPartValuesFromPartName((String) row[1]);
      partValuesToId.put(partValues, partId);
    }

    boolean isTxn = TxnUtils.isTransactionalTable(table.getParameters());
    for (Partition newPart : newParts) {
      Long partId = partValuesToId.get(newPart.getValues());
      boolean useOldWriteId = true;
      // If transactional, add/update the MUPdaterTransaction
      // for the current updater query.
      if (isTxn) {
        if (!isTxnStatsEnabled) {
          StatsSetupConst.setBasicStatsState(newPart.getParameters(), StatsSetupConst.FALSE);
        } else if (queryWriteIdList != null && newPart.getWriteId() > 0) {
          // Check concurrent INSERT case and set false to the flag.
          if (!ObjectStore.isCurrentStatsValidForTheQuery(newPart.getParameters(),
              partIdToWriteId.get(partId), queryWriteIdList, true)) {
            StatsSetupConst.setBasicStatsState(newPart.getParameters(), StatsSetupConst.FALSE);
            LOG.info("Removed COLUMN_STATS_ACCURATE from the parameters of the partition " +
                Warehouse.getQualifiedName(newPart) + " will be made persistent.");
          }
          useOldWriteId = false;
        }
      }
      // writeId default in the DB is 0 but in the application logic it is set to -1.
      // HIVE-28803 is changing the writeId from -1 to 0 during alter query which is undesirable
      if (useOldWriteId && partIdToWriteId.get(partId) != 0) {
        newPart.setWriteId(partIdToWriteId.get(partId));
      }
    }

    directSqlUpdatePart.alterPartitions(partValuesToId, partIdToSdId, newParts);
    return newParts;
  }
Alter partitions in batch using direct SQL
@param table the target table
@param partNames list of partition names
@param newParts list of new partitions
@param queryWriteIdList valid write id list
@return
@throws MetaException
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/MetaStoreDirectSql.java