private void addPartition() throws Exception {
    runStatementOnDriver("drop table if exists T");
    runStatementOnDriver("drop table if exists Tstage");
    runStatementOnDriver("create table T (a int, b int) partitioned by (p int) stored as orc" +
        " tblproperties('transactional'='true')");
    runStatementOnDriver("create table Tstage (a int, b int) stored as orc" +
        " tblproperties('transactional'='false')");

    runStatementOnDriver("insert into Tstage values(0,2),(0,4)");
    runStatementOnDriver("export table Tstage to '" + getWarehouseDir() + "/1'");
    runStatementOnDriver("export table Tstage to '" + getWarehouseDir() + "/2'");

    runStatementOnDriver("ALTER TABLE T ADD" +
        " PARTITION (p=0) location '" + getWarehouseDir() + "/1/data'" +
        " PARTITION (p=1) location '" + getWarehouseDir() + "/2/data'" +
        " PARTITION (p=2)");

    String testQuery = "select ROW__ID, p, a, b, INPUT__FILE__NAME from T order by p, ROW__ID";
    String[][] expected = new String[][]{
        {"{\"writeid\":1,\"bucketid\":536870912,\"rowid\":0}\t0\t0\t2",
            "warehouse/t/p=0/delta_0000001_0000001_0000/000000_0"},
        {"{\"writeid\":1,\"bucketid\":536870912,\"rowid\":1}\t0\t0\t4",
            "warehouse/t/p=0/delta_0000001_0000001_0000/000000_0"},
        {"{\"writeid\":1,\"bucketid\":536870912,\"rowid\":0}\t1\t0\t2",
            "warehouse/t/p=1/delta_0000001_0000001_0000/000000_0"},
        {"{\"writeid\":1,\"bucketid\":536870912,\"rowid\":1}\t1\t0\t4",
            "warehouse/t/p=1/delta_0000001_0000001_0000/000000_0"}};
    checkResultAndVectorization(expected, testQuery, "add 2 parts w/data and 1 empty", LOG);

    runStatementOnDriver("export table Tstage to '" + getWarehouseDir() + "/3'");
    //should be an error since p=3 exists
    CommandProcessorException e =
        runStatementOnDriverNegative("ALTER TABLE T ADD PARTITION (p=0) location '" + getWarehouseDir() + "/3/data'");
    Assert.assertTrue("add existing partition",
        e.getMessage() != null && e.getMessage().contains("Partition already exists"));

    //should be no-op since p=3 exists
    String stmt = "ALTER TABLE T ADD IF NOT EXISTS " +
        "PARTITION (p=0) location '" + getWarehouseDir() + "/3/data' "//p=0 exists and is not empty
        + "PARTITION (p=2) location '" + getWarehouseDir() + "/3/data'"//p=2 exists and is empty
        + "PARTITION (p=3) location '" + getWarehouseDir() + "/3/data'";//p=3 doesn't exist
    runStatementOnDriver(stmt);
    String[][] expected2 = new String[][]{
        {"{\"writeid\":1,\"bucketid\":536870912,\"rowid\":0}\t0\t0\t2",
            "warehouse/t/p=0/delta_0000001_0000001_0000/000000_0"},
        {"{\"writeid\":1,\"bucketid\":536870912,\"rowid\":1}\t0\t0\t4",
            "warehouse/t/p=0/delta_0000001_0000001_0000/000000_0"},
        {"{\"writeid\":1,\"bucketid\":536870912,\"rowid\":0}\t1\t0\t2",
            "warehouse/t/p=1/delta_0000001_0000001_0000/000000_0"},
        {"{\"writeid\":1,\"bucketid\":536870912,\"rowid\":1}\t1\t0\t4",
            "warehouse/t/p=1/delta_0000001_0000001_0000/000000_0"},
        {"{\"writeid\":3,\"bucketid\":536870912,\"rowid\":0}\t3\t0\t2",
            "warehouse/t/p=3/delta_0000003_0000003_0000/000000_0"},
        {"{\"writeid\":3,\"bucketid\":536870912,\"rowid\":1}\t3\t0\t4",
            "warehouse/t/p=3/delta_0000003_0000003_0000/000000_0"}};
    checkResultAndVectorization(expected2, testQuery, "add 2 existing parts and 1 empty", LOG);
  }
Tests adding multiple partitions
adding partition w/o location
adding partition when it already exists
adding partition when it already exists with "if not exists"
ql/src/test/org/apache/hadoop/hive/ql/TestTxnAddPartition.java