@Override
  public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException {
    checkArgsSize(arguments, 2, 3);

    checkArgPrimitive(arguments, 0);
    checkArgPrimitive(arguments, 1);

    if (arguments.length == 3) {
      if (arguments[2] instanceof ConstantObjectInspector) {
        checkArgPrimitive(arguments, 2);
        checkArgGroups(arguments, 2, tsInputTypes, STRING_GROUP);
        String fmtStr = getConstantStringValue(arguments, 2);
        if (fmtStr != null) {
          formatter = new SimpleDateFormat(fmtStr);
          formatter.setCalendar(calendar);
        }
      } else {
        throw new UDFArgumentTypeException(2, getFuncName() + " only takes constant as "
            + getArgOrder(2) + " argument");
      }
    }
    if (formatter == null) {
      //If the DateFormat is not provided by the user or is invalid, use the default format YYYY-MM-dd
      formatter = DateUtils.getDateFormat();
      formatter.setCalendar(calendar);
    }

    // the function should support both short date and full timestamp format
    // time part of the timestamp should not be skipped
    checkArgGroups(arguments, 0, tsInputTypes, STRING_GROUP, DATE_GROUP, VOID_GROUP);
    checkArgGroups(arguments, 0, dtInputTypes, STRING_GROUP, DATE_GROUP, VOID_GROUP);

    obtainTimestampConverter(arguments, 0, tsInputTypes, tsConverters);
    obtainDateConverter(arguments, 0, dtInputTypes, dtConverters);

    checkArgGroups(arguments, 1, tsInputTypes, NUMERIC_GROUP, VOID_GROUP);
    obtainIntConverter(arguments, 1, tsInputTypes, tsConverters);

    if (arguments[1] instanceof ConstantObjectInspector) {
      numMonthsConst = getConstantIntValue(arguments, 1);
      isNumMonthsConst = true;
    }

    ObjectInspector outputOI = PrimitiveObjectInspectorFactory.writableStringObjectInspector;
    return outputOI;
  }
GenericUDFAddMonths.

Add a number of months to the date. The time part of the string will be
ignored.
ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFAddMonths.java