@Test
  public void testSmallTinyInt() throws Exception {

    String readTblName = "test_small_tiny_int";
    File dataDir = new File(TEST_DATA_DIR + "/testSmallTinyIntData");
    File dataFile = new File(dataDir, "testSmallTinyInt.tsv");

    String writeTblName = "test_small_tiny_int_write";
    File writeDataFile = new File(TEST_DATA_DIR, writeTblName + ".tsv");

    FileUtil.fullyDelete(dataDir); // Might not exist
    Assert.assertTrue(dataDir.mkdir());

    HcatTestUtils.createTestDataFile(dataFile.getAbsolutePath(), new String[]{
      String.format("%d\t%d", Short.MIN_VALUE, Byte.MIN_VALUE),
      String.format("%d\t%d", Short.MAX_VALUE, Byte.MAX_VALUE)
    });

    // Create a table with smallint/tinyint columns, load data, and query from Hive.
    driver.run("drop table if exists " + readTblName);
    driver.run("create external table " + readTblName +
        " (my_small_int smallint, my_tiny_int tinyint)" +
        " row format delimited fields terminated by '\t' stored as textfile");
    driver.run("load data local inpath '" +
        dataDir.getPath().replaceAll("\\\\", "/") + "' into table " + readTblName);

    PigServer server = HCatBaseTest.createPigServer(false);
    server.registerQuery(
      "data = load '" + readTblName + "' using org.apache.hive.hcatalog.pig.HCatLoader();");

    // Ensure Pig schema is correct.
    Schema schema = server.dumpSchema("data");
    Assert.assertEquals(2, schema.getFields().size());
    Assert.assertEquals("my_small_int", schema.getField(0).alias);
    Assert.assertEquals(DataType.INTEGER, schema.getField(0).type);
    Assert.assertEquals("my_tiny_int", schema.getField(1).alias);
    Assert.assertEquals(DataType.INTEGER, schema.getField(1).type);

    // Ensure Pig can read data correctly.
    Iterator<Tuple> it = server.openIterator("data");
    Tuple t = it.next();
    Assert.assertEquals(Integer.valueOf(Short.MIN_VALUE), t.get(0));
    Assert.assertEquals(Integer.valueOf(Byte.MIN_VALUE), t.get(1));
    t = it.next();
    Assert.assertEquals(Integer.valueOf(Short.MAX_VALUE), t.get(0));
    Assert.assertEquals(Integer.valueOf(Byte.MAX_VALUE), t.get(1));
    Assert.assertFalse(it.hasNext());

    // Ensure Pig can write correctly to smallint/tinyint columns. This means values within the
    // bounds of the column type are written, and values outside throw an exception.
    driver.run("drop table if exists " + writeTblName);
    driver.run("create table " + writeTblName +
        " (my_small_int smallint, my_tiny_int tinyint) stored as rcfile");

    // Values within the column type bounds.
    HcatTestUtils.createTestDataFile(writeDataFile.getAbsolutePath(), new String[]{
      String.format("%d\t%d", Short.MIN_VALUE, Byte.MIN_VALUE),
      String.format("%d\t%d", Short.MAX_VALUE, Byte.MAX_VALUE)
    });
    smallTinyIntBoundsCheckHelper(writeDataFile.getPath().replaceAll("\\\\", "/"), ExecJob.JOB_STATUS.COMPLETED);

    // Values outside the column type bounds will fail at runtime.
    HcatTestUtils.createTestDataFile(TEST_DATA_DIR + "/shortTooSmall.tsv", new String[]{
      String.format("%d\t%d", Short.MIN_VALUE - 1, 0)});
    smallTinyIntBoundsCheckHelper(TEST_DATA_DIR + "/shortTooSmall.tsv", ExecJob.JOB_STATUS.FAILED);

    HcatTestUtils.createTestDataFile(TEST_DATA_DIR + "/shortTooBig.tsv", new String[]{
      String.format("%d\t%d", Short.MAX_VALUE + 1, 0)});
    smallTinyIntBoundsCheckHelper(TEST_DATA_DIR + "/shortTooBig.tsv", ExecJob.JOB_STATUS.FAILED);

    HcatTestUtils.createTestDataFile(TEST_DATA_DIR + "/byteTooSmall.tsv", new String[]{
      String.format("%d\t%d", 0, Byte.MIN_VALUE - 1)});
    smallTinyIntBoundsCheckHelper(TEST_DATA_DIR + "/byteTooSmall.tsv", ExecJob.JOB_STATUS.FAILED);

    HcatTestUtils.createTestDataFile(TEST_DATA_DIR + "/byteTooBig.tsv", new String[]{
      String.format("%d\t%d", 0, Byte.MAX_VALUE + 1)});
    smallTinyIntBoundsCheckHelper(TEST_DATA_DIR + "/byteTooBig.tsv", ExecJob.JOB_STATUS.FAILED);
  }
Ensure Pig can read/write tinyint/smallint columns.
hcatalog/hcatalog-pig-adapter/src/test/java/org/apache/hive/hcatalog/pig/TestHCatLoaderStorer.java