private Object evaluateNumber(DeferredObject[] arguments)
      throws HiveException, UDFArgumentTypeException {

    if (arguments[0] == null) {
      return null;
    }

    Object input = arguments[0].get();
    if (input == null) {
      return null;
    }

    if (arguments.length == 2 && arguments[1] != null && arguments[1].get() != null
        && !inputSacleConst) {
      Object scaleObj = null;
      switch (inputScaleOI.getPrimitiveCategory()) {
      case BYTE:
        scaleObj = byteConverter.convert(arguments[1].get());
        scale = ((ByteWritable) scaleObj).get();
        break;
      case SHORT:
        scaleObj = shortConverter.convert(arguments[1].get());
        scale = ((ShortWritable) scaleObj).get();
        break;
      case INT:
        scaleObj = intConverter.convert(arguments[1].get());
        scale = ((IntWritable) scaleObj).get();
        break;
      case LONG:
        scaleObj = longConverter.convert(arguments[1].get());
        long l = ((LongWritable) scaleObj).get();
        if (l < Integer.MIN_VALUE || l > Integer.MAX_VALUE) {
          throw new UDFArgumentException(
              getFuncName().toUpperCase() + " scale argument out of allowed range");
        }
        scale = (int) l;
      default:
        break;
      }
    }

    switch (inputType1) {
    case VOID:
      return null;
    case DECIMAL:
      HiveDecimalWritable decimalWritable =
          (HiveDecimalWritable) inputOI.getPrimitiveWritableObject(input);
      HiveDecimal dec = trunc(decimalWritable.getHiveDecimal(), scale);
      if (dec == null) {
        return null;
      }
      return new HiveDecimalWritable(dec);
    case BYTE:
      ByteWritable byteWritable = (ByteWritable) inputOI.getPrimitiveWritableObject(input);
      if (scale >= 0) {
        return byteWritable;
      } else {
        return new ByteWritable((byte) trunc(byteWritable.get(), scale));
      }
    case SHORT:
      ShortWritable shortWritable = (ShortWritable) inputOI.getPrimitiveWritableObject(input);
      if (scale >= 0) {
        return shortWritable;
      } else {
        return new ShortWritable((short) trunc(shortWritable.get(), scale));
      }
    case INT:
      IntWritable intWritable = (IntWritable) inputOI.getPrimitiveWritableObject(input);
      if (scale >= 0) {
        return intWritable;
      } else {
        return new IntWritable((int) trunc(intWritable.get(), scale));
      }
    case LONG:
      LongWritable longWritable = (LongWritable) inputOI.getPrimitiveWritableObject(input);
      if (scale >= 0) {
        return longWritable;
      } else {
        return new LongWritable(trunc(longWritable.get(), scale));
      }
    case FLOAT:
      float f = ((FloatWritable) inputOI.getPrimitiveWritableObject(input)).get();
      return new FloatWritable((float) trunc(f, scale));
    case DOUBLE:
      return trunc(((DoubleWritable) inputOI.getPrimitiveWritableObject(input)), scale);
    default:
      throw new UDFArgumentTypeException(0,
          "Only numeric or string group data types are allowed for TRUNC function. Got "
              + inputType1.name());
    }
  }
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