private PrimitiveObjectInspector getOutputOI(ObjectInspector[] arguments)
      throws UDFArgumentException {
    int key = getConstantIntValue(arguments, 0);
    if (!OUTPUT_TYPES.keySet().contains(key)) {
      throw new UDFArgumentException("Cast...format can only convert to DATE, TIMESTAMP, STRING,"
          + "VARCHAR, CHAR. Can't convert to HiveParser_IdentifiersParser constant with value "
          + key);
    }
    String typeString = OUTPUT_TYPES.get(key);
    if (serdeConstants.VARCHAR_TYPE_NAME.equals(typeString)
        || serdeConstants.CHAR_TYPE_NAME.equals(typeString)) {
      if (arguments.length < 4 || arguments[3] == null) {
        throw new UDFArgumentException(typeString + " missing length argument");
      }
      typeString += "(" + getConstantIntValue(arguments, 3) + ")";
    }
    PrimitiveTypeInfo typeInfo = TypeInfoFactory.getPrimitiveTypeInfo(typeString);
    return PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(typeInfo);
  }
@param arguments
 0. const int, value of a HiveParser_IdentifiersParser constant which represents a TOK_[TYPE]
 1. expression to convert
 2. constant string, format pattern
 3. (optional) constant int, output char/varchar length
ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFCastFormat.java