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

    argumentOIs = arguments;

    returnOIResolver = new GenericUDFUtils.ReturnObjectInspectorResolver(true);
    for (int i = 0; i < arguments.length; i++) {
      if (!returnOIResolver.update(arguments[i])) {
        throw new UDFArgumentTypeException(i,
            "The expressions after COALESCE should all have the same type: \""
            + returnOIResolver.get().getTypeName()
            + "\" is expected but \"" + arguments[i].getTypeName()
            + "\" is found");
      }
    }
    return returnOIResolver.get();
  }
GenericUDF Class for SQL construct "COALESCE(a, b, c)".

NOTES: 1. a, b and c should have the same TypeInfo, or an exception will be
thrown.
ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFCoalesce.java