@Override
  public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException {

    // read operation mode
    if (!(arguments[0] instanceof ConstantObjectInspector)) {
      throw new UDFArgumentTypeException(0,
          getFuncName() + ": may only accept constant as first argument");
    }
    Integer operationMode = getConstantIntValue(arguments, 0);
    if (operationMode == null) {
      throw new UDFArgumentTypeException(0, "must supply operationmode");
    }

    processor = getProcessorMap().get(operationMode);
    if (processor == null) {
      throw new UDFArgumentTypeException(0,
          getFuncName() + ": unsupported operationMode: " + operationMode);
    }

    // check value argument
    if (arguments[1].getCategory() != Category.PRIMITIVE) {
      throw new UDFArgumentTypeException(1,
          "The first argument to " + getFuncName() + " must be primitive");
    }

    inputOI = (PrimitiveObjectInspector) arguments[1];

    PrimitiveCategory inputCategory = inputOI.getPrimitiveCategory();

    if (!isValidInputCategory(inputCategory)) {
      throw new UDFArgumentTypeException(1, "The second argument to " + getFuncName()
          + " must be from the string group or numeric group (except:float/double)");
    }

    if (arguments[1] instanceof ConstantObjectInspector) {
      // return value as constant in case arg is constant
      return PrimitiveObjectInspectorFactory.getPrimitiveWritableConstantObjectInspector(
          processor.getTypeInfo(), processor.evaluate(getConstantStringValue(arguments, 1)));
    } else {
      return PrimitiveObjectInspectorFactory
          .getPrimitiveWritableObjectInspector(processor.getTypeInfo());
    }
  }
GenericUDF Class for support of "INTERVAL (expression) (DAY|YEAR|...)".
ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFInternalInterval.java