@Test
  public void testTransformerAlterTable() throws Exception {
    try {
      resetHMSClient();

      final String dbName = "dbalter";
      String tblName = "test_alter_mgd_table";
      TableType type = TableType.MANAGED_TABLE;
      StringBuilder table_params = new StringBuilder();
      table_params.append("key1=val1");
      Map<String, Object> tProps = new HashMap<>();
      tProps.put("DBNAME", dbName);
      tProps.put("TBLNAME", tblName);
      tProps.put("TBLTYPE", type);
      tProps.put("PROPERTIES", table_params.toString());

      Table table = createTableWithCapabilities(tProps); // should be converted to external table

      // retrieve the table
      Table tbl2 = client.getTable(dbName, tblName);
      assertEquals("Table type expected to be EXTERNAL", "EXTERNAL_TABLE", tbl2.getTableType());
      String tableLocation = tbl2.getSd().getLocation();
      int idx = (tableLocation.indexOf(":") > 0) ? tableLocation.indexOf(":") : 0;
      tableLocation = tableLocation.substring(idx+1);
      String expectedPath = ext_wh.getAbsolutePath().concat(File.separator).concat(dbName).concat(DATABASE_WAREHOUSE_SUFFIX)
          .concat(File.separator).concat(tblName);
      assertEquals("Table location", expectedPath, tableLocation);

      String newLocation = wh.getAbsolutePath().concat(File.separator).concat(dbName).concat(File.separator)
          .concat(tblName);
      tbl2.getSd().setLocation(newLocation);
      try {
        client.alter_table(dbName, tblName, tbl2);
        fail("alter_table expected to fail due to location:" + newLocation);
      } catch (Exception e) {
        e.printStackTrace();
        LOG.info("alter_table failed with exception, as expected");
      }

      // retrieve the table and check that the location was not altered
      tbl2 = client.getTable(dbName, tblName);
      idx = (tbl2.getSd().getLocation().indexOf(":") > 0) ? tbl2.getSd().getLocation().indexOf(":") : 0;
      assertEquals("Table location expected to be in external warehouse", tableLocation, tbl2.getSd().getLocation().substring(idx+1));

      newLocation = tableLocation.concat("_new");
      table.getSd().setLocation((new File(newLocation)).getCanonicalPath());
      try {
        client.alter_table(dbName, tblName, table);
        LOG.info("alter_table with new location succeeded as expected");
      } catch (Exception e) {
        fail("alter_table expected to succeed with new location:" + newLocation);
      }

      // retrieve the table and check that the location was altered
      tbl2 = client.getTable(dbName, tblName);
      idx = (tbl2.getSd().getLocation().indexOf(":") > 0) ? tbl2.getSd().getLocation().indexOf(":") : 0;
      assertEquals("Table location expected to be in external warehouse", newLocation, tbl2.getSd().getLocation().substring(idx+1));

      tblName = "test_create_insert_table";
      type = TableType.MANAGED_TABLE;
      tProps.put("TBLNAME", tblName);
      tProps.put("TBLTYPE", TableType.MANAGED_TABLE);
      table_params = new StringBuilder();
      table_params.append("key1=val1");
      table_params.append(";");
      table_params.append("transactional_properties=insert_only");
      tProps.put("PROPERTIES", table_params.toString());

      List<String> capabilities = new ArrayList<>();
      capabilities.add("HIVEMANAGEDINSERTWRITE");
      setHMSClient("TestAlterTableMGD#1", (String[])(capabilities.toArray(new String[0])));

      table = createTableWithCapabilities(tProps);

      // retrieve the table
      tbl2 = client.getTable(dbName, tblName);
      tableLocation = tbl2.getSd().getLocation();
      idx = (tableLocation.indexOf(":") > 0) ? tableLocation.indexOf(":") : 0;
      tableLocation = tableLocation.substring(idx+1);

      assertEquals("Table type expected to be MANAGED", "MANAGED_TABLE", tbl2.getTableType());

      newLocation = ext_wh.getAbsolutePath().concat(File.separator).concat(dbName).concat(File.separator)
          .concat(tblName);
      table.getSd().setLocation(newLocation);
      try {
        client.alter_table(dbName, tblName, table);
        fail("alter_table expected to fail but succeeded with new location:" + newLocation);
      } catch (Exception e) {
        LOG.info("alter_table failed with exception as expected");
      }

      // retrieve the table and ensure location has not been changed.
      tbl2 = client.getTable(dbName, tblName);
      assertEquals("Table type expected to be MANAGED", "MANAGED_TABLE", tbl2.getTableType());
      idx = (tbl2.getSd().getLocation().indexOf(":") > 0) ? tbl2.getSd().getLocation().indexOf(":") : 0;
      assertEquals("Table location expected to remain unaltered", tableLocation, tbl2.getSd().getLocation().substring(idx+1));

      newLocation = tableLocation + "_new";
      table.getSd().setLocation(newLocation);
      try {
        client.alter_table(dbName, tblName, table);
        LOG.info("alter_table succeeded with new location as expected");
      } catch (Exception e) {
        fail("alter_table expected to succeed but failed with new location:" + newLocation);
      }
      // retrieve the table and ensure location has not been changed.
      tbl2 = client.getTable(dbName, tblName);
      assertEquals("Table type expected to be MANAGED", "MANAGED_TABLE", tbl2.getTableType());
      idx = (tbl2.getSd().getLocation().indexOf(":") > 0) ? tbl2.getSd().getLocation().indexOf(":") : 0;
      assertEquals("Table location expected to be new location", newLocation, tbl2.getSd().getLocation().substring(idx+1));
      resetHMSClient();

      tblName = "test_create_acid_table";
      type = TableType.MANAGED_TABLE;
      tProps.put("TBLNAME", tblName);
      tProps.put("TBLTYPE", TableType.MANAGED_TABLE);
      table_params = new StringBuilder();
      table_params.append("key1=val1");
      table_params.append(";");
      table_params.append("transactional=true");
      tProps.put("PROPERTIES", table_params.toString());

      capabilities = new ArrayList<>();
      capabilities.add("HIVEFULLACIDWRITE");
      setHMSClient("TestAlterTableMGD#1", (String[])(capabilities.toArray(new String[0])));

      table = createTableWithCapabilities(tProps);

      // retrieve the table
      tbl2 = client.getTable(dbName, tblName);
      tableLocation = tbl2.getSd().getLocation();
      idx = (tableLocation.indexOf(":") > 0) ? tableLocation.indexOf(":") : 0;
      tableLocation = tableLocation.substring(idx+1);

      assertEquals("Table type expected to be MANAGED", "MANAGED_TABLE", tbl2.getTableType());

      newLocation = ext_wh.getAbsolutePath().concat(File.separator).concat(dbName).concat(File.separator)
          .concat(tblName);
      table.getSd().setLocation(newLocation);
      try {
        client.alter_table(dbName, tblName, table);
        fail("alter_table expected to fail but succeeded with new location:" + newLocation);
      } catch (Exception e) {
        LOG.info("alter_table failed with exception as expected");
      }

      // retrieve the table and ensure location has not been changed.
      tbl2 = client.getTable(dbName, tblName);
      assertEquals("Table type expected to be MANAGED", "MANAGED_TABLE", tbl2.getTableType());
      idx = (tbl2.getSd().getLocation().indexOf(":") > 0) ? tbl2.getSd().getLocation().indexOf(":") : 0;
      assertEquals("Table location expected to remain unaltered", tableLocation, tbl2.getSd().getLocation().substring(idx+1));

      newLocation = tableLocation + "_new";
      table.getSd().setLocation(newLocation);
      try {
        client.alter_table(dbName, tblName, table);
        LOG.info("alter_table succeeded with new location as expected");
      } catch (Exception e) {
        e.printStackTrace();
        fail("alter_table expected to succeed but failed with new location:" + newLocation);
      }
      // retrieve the table and ensure location has not been changed.
      tbl2 = client.getTable(dbName, tblName);
      assertEquals("Table type expected to be MANAGED", "MANAGED_TABLE", tbl2.getTableType());
      idx = (tbl2.getSd().getLocation().indexOf(":") > 0) ? tbl2.getSd().getLocation().indexOf(":") : 0;
      assertEquals("Table location expected to be new location", newLocation, tbl2.getSd().getLocation().substring(idx+1));
    } catch (Exception e) {
      System.err.println(org.apache.hadoop.util.StringUtils.stringifyException(e));
      System.err.println("testAlterTable() failed.");
      fail("testAlterTable failed:" + e.getMessage());
    } finally {
      resetHMSClient();
    }
  }
EXTERNAL_TABLE
  1) Old table (name in upper case) with no capabilities
  2) Old table with no capabilities
  3a) New table with capabilities with no client requirements
  3b) New table with capabilities with no matching client requirements
  3c) New table with capabilities with partial match requirements
  3d) New table with capabilities with full match requirements
itests/hive-unit/src/test/java/org/apache/hadoop/hive/metastore/TestHiveMetastoreTransformer.java