public static Timestamp decimalToTimestamp(HiveDecimal dec) {
    try {
      HiveDecimalWritable nanosWritable = new HiveDecimalWritable(dec);
      nanosWritable.mutateFractionPortion();               // Clip off seconds portion.
      nanosWritable.mutateScaleByPowerOfTen(9);            // Bring nanoseconds into integer portion.
      if (!nanosWritable.isSet() || !nanosWritable.isInt()) {
        return null;
      }
      int nanos = nanosWritable.intValue();
      if (nanos < 0) {
        nanos += 1000000000;
      }
      nanosWritable.setFromLong(nanos);

      HiveDecimalWritable nanoInstant = new HiveDecimalWritable(dec);
      nanoInstant.mutateScaleByPowerOfTen(9);

      nanoInstant.mutateSubtract(nanosWritable);
      nanoInstant.mutateScaleByPowerOfTen(-9);              // Back to seconds.
      if (!nanoInstant.isSet() || !nanoInstant.isLong()) {
        return null;
      }
      long millis = nanoInstant.longValue() * 1000;
      return Timestamp.ofEpochMilli(millis, nanos);
    } catch (IllegalArgumentException | DateTimeException nfe) {
      // E.g. DateTimeException: Invalid value for Year (valid values -999999999 - 999999999)
      return null;
    }
  }
Take a HiveDecimal and return the timestamp representation where the fraction part is the
nanoseconds and integer part is the number of seconds.
@param dec
@return
common/src/java/org/apache/hadoop/hive/common/type/TimestampUtils.java