@Test
  public void testAddPartitions() {
    try {
      // Create source table.
      HiveMetaStoreClient hmsc = new HiveMetaStoreClient(conf);
      clearAndRecreateDB(hmsc);
      createTable(hmsc, true);
      Table table = hmsc.getTable(dbName, tableName);
      Assert.assertTrue(table.isSetId());
      table.unsetId();
      populatePartitions(hmsc, table, Arrays.asList("isLocatedInTablePath", "isLocatedOutsideTablePath"));

      // Clone the table,
      String targetTableName = "cloned_" + tableName;
      Table targetTable = new Table(table);
      targetTable.setTableName(targetTableName);
      StorageDescriptor targetTableSd = new StorageDescriptor(targetTable.getSd());
      targetTableSd.setLocation(
          targetTableSd.getLocation().replace( tableName, targetTableName));
      hmsc.createTable(targetTable);

      // Get partition-list from source.
      PartitionSpecProxy partitionsForAddition
          = hmsc.listPartitionSpecsByFilter(dbName, tableName, "blurb = \"isLocatedInTablePath\"", -1);
      partitionsForAddition.setTableName(targetTableName);
      partitionsForAddition.setRootLocation(targetTableSd.getLocation());

      Assert.assertEquals("Unexpected number of partitions added. ",
          partitionsForAddition.size(), hmsc.add_partitions_pspec(partitionsForAddition));

      // Check that the added partitions are as expected.
      PartitionSpecProxy clonedPartitions = hmsc.listPartitionSpecs(dbName, targetTableName, -1);
      Assert.assertEquals("Unexpected number of partitions returned. ",
          partitionsForAddition.size(), clonedPartitions.size());

      PartitionSpecProxy.PartitionIterator sourceIterator = partitionsForAddition.getPartitionIterator(),
                                           targetIterator = clonedPartitions.getPartitionIterator();

      while (targetIterator.hasNext()) {
        Partition sourcePartition = sourceIterator.next(),
                  targetPartition = targetIterator.next();
        Assert.assertEquals("Mismatched values.",
            sourcePartition.getValues(), targetPartition.getValues());
        Assert.assertEquals("Mismatched locations.",
            sourcePartition.getSd().getLocation(), targetPartition.getSd().getLocation());
      }
    }
    catch (Throwable t) {
      LOG.error("Unexpected Exception!", t);
      t.printStackTrace();
      Assert.assertTrue("Unexpected Exception!", false);
    }
  }
Test to confirm that partitions can be added using PartitionSpecs.
standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/TestHiveMetaStorePartitionSpecs.java