@Test
  public void testAlterTableExternalTable() throws Exception {
    Table originalTable = externalTable;
    String originalTableName = originalTable.getTableName();
    String originalDatabase = originalTable.getDbName();

    Table newTable = originalTable.deepCopy();
    newTable.setTableName("new_external_table_for_test");
    client.alter_table(originalDatabase, originalTableName, newTable);
    List<String> tableNames = client.getTables(originalDatabase, originalTableName);
    Assert.assertEquals("Original table should be removed", 0, tableNames.size());
    Assert.assertTrue("Original table directory should be kept",
        metaStore.isPathExists(new Path(originalTable.getSd().getLocation())));
    Table alteredTable = client.getTable(newTable.getDbName(), newTable.getTableName());
    Assert.assertEquals("New location should be the same", originalTable.getSd().getLocation(),
        alteredTable.getSd().getLocation());
    Path dataFile = new Path(alteredTable.getSd().getLocation() + "/dataFile");
    Assert.assertTrue("The location should contain data", metaStore.isPathExists(dataFile));

    // The extra parameters will be added on server side, so check that the required ones are
    // present
    for(String key: newTable.getParameters().keySet()) {
      Assert.assertEquals("parameters are present", newTable.getParameters().get(key),
          alteredTable.getParameters().get(key));
    }
    // The parameters are checked manually, so do not check them
    newTable.setParameters(alteredTable.getParameters());
    Assert.assertEquals("The table data should be the same", newTable, alteredTable);
  }
This test creates and queries a table and then drops it. Good for testing the happy path
standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/client/TestTablesCreateDropAlterTruncate.java