public static String getTaskId(Configuration hconf) {
    String taskid = (hconf == null) ? null : hconf.get("mapred.task.id");
    if (StringUtils.isEmpty(taskid)) {
      return (Integer
          .toString(ThreadLocalRandom.current().nextInt(Integer.MAX_VALUE)));
    } else {
      /*
       * extract the task and attempt id from the hadoop taskid. in version 17 the leading component
       * was 'task_'. thereafter the leading component is 'attempt_'. in 17 - hadoop also seems to
       * have used _map_ and _reduce_ to denote map/reduce task types
       */
      String ret = taskid.replaceAll(".*_[mr]_", "").replaceAll(".*_(map|reduce)_", "");
      return (ret);
    }
  }
Gets the task id if we are running as a Hadoop job. Gets a random number otherwise.
ql/src/java/org/apache/hadoop/hive/ql/exec/Utilities.java