private String check(Byte type, Object o) throws IOException {
    if (o == null) {
      return "";
    }
    if (check(typeMap.get(type), o)) {
      if (type.equals(DataType.MAP)) {
        Map<String, String> m = (Map<String, String>) o;
        check(m);
      } else if (type.equals(DataType.BAG)) {
        DataBag bg = (DataBag) o;
        for (Tuple tuple : bg) {
          Map<String, String> m = (Map<String, String>) tuple.get(0);
          check(m);
        }
      } else if (type.equals(DataType.TUPLE)) {
        Tuple t = (Tuple) o;
        if (!check(Integer.class, t.get(0)) ||
          !check(String.class, t.get(1)) ||
          !check(Double.class, t.get(2))) {
          die("t:tuple(num:int,str:string,dbl:double)", t);
        }
      }
    } else {
      die(typeMap.get(type).getName(), o);
    }
    return o.toString();
  }
This UDF can be used to check that a tuple presented by HCatLoader has the
right types for the fields

Usage is :

register testudf.jar;
a = load 'numbers' using HCatLoader(...);
b = foreach a generate HCatTypeCheck('intnum1000:int,id:int,intnum5:int,intnum100:int,intnum:int,longnum:long,floatnum:float,doublenum:double', *);
store b into 'output';

The schema string (the first argument to the UDF) is of the form one would provide in a 
pig load statement.

The output should only contain the value '1' in all rows. (This UDF returns
the integer value 1 if all fields have the right type, else throws IOException)
hcatalog/src/test/e2e/hcatalog/udfs/java/org/apache/hive/hcatalog/utils/HCatTypeCheck.java