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

    argumentOIs = arguments;
    checkArgsSize(arguments, 2, 2);

    returnOIResolver = new GenericUDFUtils.ReturnObjectInspectorResolver(true);
    returnOIResolver.update(arguments[0]);

    switch (arguments[0].getCategory()) {
    case LIST:
    case MAP:
    case STRUCT:
    case PRIMITIVE:
      break;
    case UNION:
    default:
      throw new UDFArgumentTypeException(0, "Unsupported Argument type category: " + arguments[0].getCategory());
    }

    boolean isPrimitive = (arguments[0] instanceof PrimitiveObjectInspector);
    if (isPrimitive)
    {
      PrimitiveObjectInspector primitive0 = (PrimitiveObjectInspector) arguments[0];
      PrimitiveObjectInspector primitive1 = (PrimitiveObjectInspector) arguments[1];
      PrimitiveGrouping pcat0 =
          PrimitiveObjectInspectorUtils.getPrimitiveGrouping(primitive0.getPrimitiveCategory());
      PrimitiveGrouping pcat1 =
          PrimitiveObjectInspectorUtils.getPrimitiveGrouping(primitive1.getPrimitiveCategory());

      if (pcat0 == PrimitiveGrouping.VOID_GROUP) {
        throw new UDFArgumentTypeException(0,
            "NULLIF may not accept types belonging to " + pcat0 + " as first argument");
      }

      if (pcat1 != PrimitiveGrouping.VOID_GROUP && pcat0 != pcat1) {
        throw new UDFArgumentTypeException(1,
            "The expressions after NULLIF should belong to the same category: \"" + pcat0
                + "\" is expected but \"" + pcat1 + "\" is found");
      }
    } else {
      String typeName0 = arguments[0].getTypeName();
      String typeName1 = arguments[1].getTypeName();
      if (!typeName0.equals(typeName1)) {
        throw new UDFArgumentTypeException(1,
            "The expressions after NULLIF should all have the same type: \"" + typeName0
                + "\" is expected but \"" + typeName1 + "\" is found");
      }
    }

    return returnOIResolver.get();
  }
GenericUDF Class for SQL construct "nullif(a,b)".
ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFNullif.java