private static String replaceTaskIdFromFilename(String filename, String oldTaskId,
      String newTaskId) {

    String[] spl = filename.split(oldTaskId);

    if ((spl.length == 0) || (spl.length == 1)) {
      return filename.replaceAll(oldTaskId, newTaskId);
    }

    StringBuilder snew = new StringBuilder();
    for (int idx = 0; idx < spl.length - 1; idx++) {
      if (idx > 0) {
        snew.append(oldTaskId);
      }
      snew.append(spl[idx]);
    }
    snew.append(newTaskId);
    snew.append(spl[spl.length - 1]);
    return snew.toString();
  }
Replace the oldTaskId appearing in the filename by the newTaskId. The string oldTaskId could
appear multiple times, we should only replace the last one.

@param filename
@param oldTaskId
@param newTaskId
@return
ql/src/java/org/apache/hadoop/hive/ql/exec/Utilities.java