@Test
  public void testPartition() throws Throwable {
    try {
      String tableName = "table_for_testpartition";
      try {
        hm.dropTable(Warehouse.DEFAULT_DATABASE_NAME, tableName);
      } catch (HiveException e) {
        System.err.println(StringUtils.stringifyException(e));
        assertTrue("Unable to drop table: " + tableName, false);
      }
      LinkedList<String> cols = new LinkedList<String>();
      cols.add("key");
      cols.add("value");

      LinkedList<String> part_cols = new LinkedList<String>();
      part_cols.add("ds");
      part_cols.add("hr");
      try {
        hm.createTable(tableName, cols, part_cols, TextInputFormat.class,
            HiveIgnoreKeyTextOutputFormat.class);
      } catch (HiveException e) {
        System.err.println(StringUtils.stringifyException(e));
        assertTrue("Unable to create table: " + tableName, false);
      }
      Table tbl = null;
      try {
        tbl = hm.getTable(Warehouse.DEFAULT_DATABASE_NAME, tableName);
      } catch (HiveException e) {
        System.err.println(StringUtils.stringifyException(e));
        assertTrue("Unable to fetch table: " + tableName, false);
      }
      HashMap<String, String> part_spec = new HashMap<String, String>();
      part_spec.clear();
      part_spec.put("ds", "2008-04-08");
      part_spec.put("hr", "12");
      try {
        hm.createPartition(tbl, part_spec);
      } catch (HiveException e) {
        System.err.println(StringUtils.stringifyException(e));
        assertTrue("Unable to create parition for table: " + tableName, false);
      }

      part_spec.clear();
      part_spec.put("ds", "2008-04-08");
      part_spec.put("hr", "13");
      try {
        hm.createPartition(tbl, part_spec);
      } catch (HiveException e) {
        System.err.println(StringUtils.stringifyException(e));
        assertTrue("Unable to create parition for table: " + tableName, false);
      }
      part_spec.clear();
      part_spec.put("ds", "2008-04-08");
      part_spec.put("hr", "14");
      try {
        hm.createPartition(tbl, part_spec);
      } catch (HiveException e) {
        System.err.println(StringUtils.stringifyException(e));
        assertTrue("Unable to create parition for table: " + tableName, false);
      }
      part_spec.clear();
      part_spec.put("ds", "2008-04-07");
      part_spec.put("hr", "12");
      try {
        hm.createPartition(tbl, part_spec);
      } catch (HiveException e) {
        System.err.println(StringUtils.stringifyException(e));
        assertTrue("Unable to create parition for table: " + tableName, false);
      }
      part_spec.clear();
      part_spec.put("ds", "2008-04-07");
      part_spec.put("hr", "13");
      try {
        hm.createPartition(tbl, part_spec);
      } catch (HiveException e) {
        System.err.println(StringUtils.stringifyException(e));
        assertTrue("Unable to create parition for table: " + tableName, false);
      }
      checkPartitionsConsistency(tbl);

      Map<String, String> partialSpec = new HashMap<>();
      partialSpec.put("ds", "2008-04-07");
      assertEquals(2, hm.getPartitions(tbl, partialSpec).size());

      partialSpec = new HashMap<>();
      partialSpec.put("ds", "2008-04-08");
      assertEquals(3, hm.getPartitions(tbl, partialSpec).size());

      partialSpec = new HashMap<>();
      partialSpec.put("hr", "13");
      assertEquals(2, hm.getPartitions(tbl, partialSpec).size());

      partialSpec = new HashMap<>();
      assertEquals(5, hm.getPartitions(tbl, partialSpec).size());

      partialSpec = new HashMap<>();
      partialSpec.put("hr", "14");
      assertEquals(1, hm.getPartitions(tbl, partialSpec).size());

      // Test get partitions with max_parts
      assertEquals(1, hm.getPartitions(tbl, new HashMap(), (short) 1).size());

      hm.dropTable(Warehouse.DEFAULT_DATABASE_NAME, tableName);
    } catch (Throwable e) {
      System.err.println(StringUtils.stringifyException(e));
      System.err.println("testPartition() failed");
      throw e;
    }
  }
Test that tables set up with auto-purge skip trash-directory when tables/partitions are dropped.
@throws Throwable
ql/src/test/org/apache/hadoop/hive/ql/metadata/TestHive.java