@Test
  public void testStoreExternalTableWithExternalDir() throws Exception {

    File tmpExternalDir = new File(TEST_DATA_DIR, UUID.randomUUID().toString());
    tmpExternalDir.deleteOnExit();

    String part_val = "100";

    driver.run("drop table junit_external");
    String createTable = "create external table junit_external(a int, b string) partitioned by (c string) stored as RCFILE";
    driver.run(createTable);

    int LOOP_SIZE = 3;
    String[] inputData = new String[LOOP_SIZE*LOOP_SIZE];
    int k = 0;
    for(int i = 1; i <= LOOP_SIZE; i++) {
      String si = i + "";
      for(int j=1;j<=LOOP_SIZE;j++) {
        inputData[k++] = si + "\t"+j;
      }
    }
    HcatTestUtils.createTestDataFile(INPUT_FILE_NAME, inputData);
    PigServer server = HCatBaseTest.createPigServer(false);
    server.setBatchOn();
    logAndRegister(server, "A = load '"+INPUT_FILE_NAME+"' as (a:int, b:chararray);");
    logAndRegister(server, "store A into 'default.junit_external' using " + HCatStorerWrapper.class.getName()
        + "('c=" + part_val + "','" + tmpExternalDir.getPath().replaceAll("\\\\", "/") + "');");
    server.executeBatch();

    Assert.assertTrue(tmpExternalDir.exists());

    boolean found = false;
    File[] f = tmpExternalDir.listFiles();
    if (f != null) {
      for (File fin : f){
        if (fin.getPath().contains("part-m-00000")){
          found = true;
        }
      }
    }

    Assert.assertTrue(found);

    driver.run("select * from junit_external");
    ArrayList<String> res = new ArrayList<String>();
    driver.getResults(res);
    driver.run("drop table junit_external");
    Iterator<String> itr = res.iterator();
    for(int i = 1; i <= LOOP_SIZE; i++) {
      String si = i + "";
      for(int j=1;j<=LOOP_SIZE;j++) {
        Assert.assertEquals( si + "\t" + j + "\t" + part_val,itr.next());
      }
    }
    Assert.assertFalse(itr.hasNext());

  }
This test checks the {@link HCatConstants#HCAT_PIG_STORER_EXTERNAL_LOCATION} that we can set in the
UDFContext of {@link HCatStorer} so that it writes to the specified external location.

Since {@link HCatStorer} does not allow extra parameters in the constructor, we use {@link HCatStorerWrapper}
that always treats the last parameter as the external path.
hcatalog/hcatalog-pig-adapter/src/test/java/org/apache/hive/hcatalog/pig/TestHCatStorerWrapper.java