protected long getField(byte[] bytes, int start, int length) throws ParseException {
    int field = 0;
    for (int i = 0; i < length; i++) {
      char ch = (char) bytes[start + i];
      if (ch < patternMin.charAt(i) || ch > patternMax.charAt(i)) {
        throw new ParseException("A timestamp string should match 'yyyy-MM-dd HH:mm:ss.fffffffff' pattern.", i);
      }
    }

    if (length < fieldLength) {
      throw new ParseException("A timestamp string should be longer.", 0);
    }
    for (int i = fieldStart; i < fieldStart + fieldLength; i++) {
      byte ch = bytes[start + i];
      field = 10 * field + (ch - '0');
    }
    return field;
  }
Abstract class to return various fields from a String.
ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/VectorUDFTimestampFieldString.java