@Test
  public void testDateToStringWithFormat() throws HiveException {
    ObjectInspector inputOI = PrimitiveObjectInspectorFactory.writableDateObjectInspector;
    testCast(STRING, inputOI, date("2009-07-30"), "yyyy-MM-dd", "2009-07-30");
    testCast(STRING, inputOI, date("2009-07-30"), "yyyy", "2009");
    testCast(STRING, inputOI, date("1969-07-30"), "dd", "30");

    testCast(CHAR, 3, inputOI, date("2009-07-30"), "yyyy-MM-dd", "200");
    testCast(CHAR, 3, inputOI, date("2009-07-30"), "yyyy", "200");
    testCast(CHAR, 3, inputOI, date("1969-07-30"), "dd", "30 ");

    testCast(VARCHAR, 3, inputOI, date("2009-07-30"), "yyyy-MM-dd", "200");
    testCast(VARCHAR, 3, inputOI, date("2009-07-30"), "yyyy", "200");
    testCast(VARCHAR, 3, inputOI, date("1969-07-30"), "dd", "30");
  }
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