private void addPartitions(
      String tableName, List<String> candidatePartitions, boolean isTableExternal)
      throws Exception {
    Path path = new Path(EXTERNAL_TABLE_LOCATION);
    FileSystem fs = path.getFileSystem(new Configuration());

    for (String candidatePartition : candidatePartitions) {
      if (isTableExternal) {
        touch(fs, EXTERNAL_TABLE_LOCATION + candidatePartition);
      }

      Map<String, String> partition = new HashMap<String, String>();
      partition.put("ds", candidatePartition); // yyyyMMDD
      partition.put("region", "in");
      HCatAddPartitionDesc addPtn =
          HCatAddPartitionDesc.create(DATABASE_NAME, tableName, null, partition).build();
      client.addPartition(addPtn);
    }
  }
  private void addMultiColDatedPartitions(
      String tableName, List<Map<String, String>> candidatePartitions, boolean isTableExternal)
      throws Exception {
    Path path = new Path(MULTI_COL_DATED_EXTERNAL_TABLE_LOCATION);
    FileSystem fs = path.getFileSystem(new Configuration());

    for (Map<String, String> candidatePartition : candidatePartitions) {
      if (isTableExternal) {
        StringBuilder pathStr = new StringBuilder(MULTI_COL_DATED_EXTERNAL_TABLE_LOCATION);
        for (Map.Entry<String, String> entry : candidatePartition.entrySet()) {
          pathStr.append(entry.getKey()).append("=").append(entry.getValue()).append("/");
        }
        pathStr.append("region=in");
        touch(fs, pathStr.toString());
      }

      candidatePartition.put("region", "in");
      HCatAddPartitionDesc addPtn =
          HCatAddPartitionDesc.create(DATABASE_NAME, tableName, null, candidatePartition).build();
      client.addPartition(addPtn);
    }
  }