@Test public void testStringTypesToDateWithFormat() throws HiveException {
    ObjectInspector inputOI = PrimitiveObjectInspectorFactory.javaStringObjectInspector;
    testCast(DATE, inputOI, "1969-07-30 13:00", "yyyy-MM-dd hh24:mi", "1969-07-30");
    testCast(DATE, inputOI, "307-2009", "ddmm-yyyy", "2009-07-30");
    testCast(DATE, inputOI, "307-2009", "ddd-yyyy", "2009-11-03");

    inputOI = PrimitiveObjectInspectorFactory.javaHiveCharObjectInspector;
    testCast(DATE, inputOI, new HiveChar("1969-07-30 13:00", 15), "yyyy-MM-dd hh24:mi",
        "1969-07-30");
    testCast(DATE, inputOI, new HiveChar("307-2009", 7), "ddmm-yyyy", "2200-07-30");
    testCast(DATE, inputOI, new HiveChar("307-2009", 7), "ddd-yyyy", "2200-11-03");

    inputOI = PrimitiveObjectInspectorFactory.javaHiveVarcharObjectInspector;
    testCast(DATE, inputOI, new HiveVarchar("1969-07-30 13:00", 15), "yyyy-MM-dd hh24:mi",
        "1969-07-30");
    testCast(DATE, inputOI, new HiveVarchar("307-2009", 7), "ddmm-yyyy", "2200-07-30");
    testCast(DATE, inputOI, new HiveVarchar("307-2009", 7), "ddd-yyyy", "2200-11-03");
  }
Tests CAST (<TIMESTAMP/DATE> AS STRING/CHAR/VARCHAR FORMAT <STRING>) and
CAST (<STRING/CHAR/VARCHAR> AS TIMESTAMP/DATE FORMAT <STRING>).
ql/src/test/org/apache/hadoop/hive/ql/udf/generic/TestGenericUDFCastFormat.java