@Override
  public Table alterTable(String catName, String dbname, String name, Table newTable,
      String queryValidWriteIds) throws InvalidObjectException, MetaException {
    boolean success = false;
    try {
      openTransaction();
      name = normalizeIdentifier(name);
      dbname = normalizeIdentifier(dbname);
      catName = normalizeIdentifier(catName);
      MTable newt = convertToMTable(newTable);
      if (newt == null) {
        throw new InvalidObjectException("new table is invalid");
      }

      MTable oldt = getMTable(catName, dbname, name);
      if (oldt == null) {
        throw new MetaException("table " + dbname + "." + name + " doesn't exist");
      }

      // For now only alter name, owner, parameters, cols, bucketcols are allowed
      oldt.setDatabase(newt.getDatabase());
      oldt.setTableName(normalizeIdentifier(newt.getTableName()));
      boolean isTxn = TxnUtils.isTransactionalTable(newTable);
      boolean isToTxn = isTxn && !TxnUtils.isTransactionalTable(oldt.getParameters());
      if (!isToTxn && isTxn && areTxnStatsSupported) {
        // Transactional table is altered without a txn. Make sure there are no changes to the flag.
        String errorMsg = verifyStatsChangeCtx(TableName.getDbTable(name, dbname), oldt.getParameters(),
                newTable.getParameters(), newTable.getWriteId(), queryValidWriteIds, false);
        if (errorMsg != null) {
          throw new MetaException(errorMsg);
        }
      }
      oldt.setParameters(newt.getParameters());
      oldt.setOwner(newt.getOwner());
      oldt.setOwnerType(newt.getOwnerType());
      // Fully copy over the contents of the new SD into the old SD,
      // so we don't create an extra SD in the metastore db that has no references.
      MColumnDescriptor oldCD = null;
      MStorageDescriptor oldSD = oldt.getSd();
      if (oldSD != null) {
        oldCD = oldSD.getCD();
      }
      copyMSD(newt.getSd(), oldt.getSd());
      removeUnusedColumnDescriptor(oldCD);
      oldt.setRetention(newt.getRetention());
      oldt.setPartitionKeys(newt.getPartitionKeys());
      oldt.setTableType(newt.getTableType());
      oldt.setLastAccessTime(newt.getLastAccessTime());
      oldt.setViewOriginalText(newt.getViewOriginalText());
      oldt.setViewExpandedText(newt.getViewExpandedText());
      oldt.setRewriteEnabled(newt.isRewriteEnabled());

      // If transactional, update the stats state for the current Stats updater query.
      // Set stats invalid for ACID conversion; it doesn't pass in the write ID.
      if (isTxn) {
        if (!areTxnStatsSupported || isToTxn) {
          StatsSetupConst.setBasicStatsState(oldt.getParameters(), StatsSetupConst.FALSE);
        } else if (queryValidWriteIds != null && newTable.getWriteId() > 0) {
          // Check concurrent INSERT case and set false to the flag.
          if (!isCurrentStatsValidForTheQuery(oldt, queryValidWriteIds, true)) {
            StatsSetupConst.setBasicStatsState(oldt.getParameters(), StatsSetupConst.FALSE);
            LOG.info("Removed COLUMN_STATS_ACCURATE from the parameters of the table " +
                    dbname + "." + name + ". will be made persistent.");
          }
          assert newTable.getWriteId() > 0;
          oldt.setWriteId(newTable.getWriteId());
        }
      }
      newTable = convertToTable(oldt);

      // commit the changes
      success = commitTransaction();
    } finally {
      rollbackAndCleanup(success, null);
    }
    return newTable;
  }
Makes a JDO query filter string for tables or partitions.
@param dbName Database name.
@param table Table. If null, the query returned is over tables in a database.
  If not null, the query returned is over partitions in a table.
@param tree The expression tree from which JDOQL filter will be made.
@param params Parameters for the filter. Some parameters may be added here.
@param isValidatedFilter Whether the filter was pre-validated for JDOQL pushdown
  by the client; if it was and we fail to create a filter, we will throw.
@return Resulting filter. Can be null if isValidatedFilter is false, and there was error.
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/ObjectStore.java