@Override
  public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException {
    for (int i = 0; i < arguments.length; i++) {
      checkArgPrimitive(arguments, i);
    }
    if (arguments.length == 2) {
      inputType1 = ((PrimitiveObjectInspector) arguments[0]).getPrimitiveCategory();
      inputType2 = ((PrimitiveObjectInspector) arguments[1]).getPrimitiveCategory();
      if ((PrimitiveObjectInspectorUtils
          .getPrimitiveGrouping(inputType1) == PrimitiveGrouping.DATE_GROUP
          || PrimitiveObjectInspectorUtils
              .getPrimitiveGrouping(inputType1) == PrimitiveGrouping.STRING_GROUP)
          && PrimitiveObjectInspectorUtils
              .getPrimitiveGrouping(inputType2) == PrimitiveGrouping.STRING_GROUP) {
        dateTypeArg = true;
        return initializeDate(arguments);
      } else if (PrimitiveObjectInspectorUtils
          .getPrimitiveGrouping(inputType1) == PrimitiveGrouping.NUMERIC_GROUP
          && PrimitiveObjectInspectorUtils
              .getPrimitiveGrouping(inputType2) == PrimitiveGrouping.NUMERIC_GROUP) {
        dateTypeArg = false;
        return initializeNumber(arguments);
      }
      throw new UDFArgumentException("Got wrong argument types : first argument type : "
          + arguments[0].getTypeName() + ", second argument type : " + arguments[1].getTypeName());
    } else if (arguments.length == 1) {
      inputType1 = ((PrimitiveObjectInspector) arguments[0]).getPrimitiveCategory();
      if (PrimitiveObjectInspectorUtils
          .getPrimitiveGrouping(inputType1) == PrimitiveGrouping.NUMERIC_GROUP) {
        dateTypeArg = false;
        return initializeNumber(arguments);
      } else {
        throw new UDFArgumentException(
            "Only primitive type arguments are accepted, when arguments length is one, got "
                + arguments[0].getTypeName());
      }
    }
    throw new UDFArgumentException("TRUNC requires one or two argument, got " + arguments.length);
  }
GenericUDFTrunc.

Returns the first day of the month which the date belongs to. The time part of the date will be
ignored.
ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFTrunc.java