protected void processDate(BytesColumnVector outV, int i, Date date) {
    switch (fmt) {
    case "YEAR":
    case "YYYY":
    case "YY":
      date.setMonth(1);
      /* fall through */
    case "MONTH":
    case "MON":
    case "MM":
      date.setDayOfMonth(1);
      break;
    case "QUARTER":
    case "Q":
      int month = date.getMonth() - 1;
      int quarter = month / 3;
      int monthToSet = quarter * 3 + 1;
      date.setMonth(monthToSet);
      date.setDayOfMonth(1);
      break;
    default:
      break;
    }

    byte[] bytes = date.toString().getBytes(StandardCharsets.UTF_8);
    outV.setVal(i, bytes, 0, bytes.length);
  }
Vectorized implementation of trunc(date, fmt) function for timestamp input
ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/TruncDateFromTimestamp.java