protected void replaceTask(
      Task<?> currTask, Task<?> newTask) {
    // add this task into task tree
    // set all parent tasks
    List<Task<?>> parentTasks = currTask.getParentTasks();
    currTask.setParentTasks(null);
    if (parentTasks != null) {
      for (Task<?> tsk : parentTasks) {
        // remove the current task from its original parent task's dependent task
        tsk.removeDependentTask(currTask);
        // make new generated task depends on all the parent tasks of current task.
        tsk.addDependentTask(newTask);
      }
    } else {
      // remove from current root task and add conditional task to root tasks
      physicalContext.removeFromRootTask(currTask);
      physicalContext.addToRootTask(newTask);
    }

    // set all child tasks
    List<Task<?>> oldChildTasks = currTask.getChildTasks();
    currTask.setChildTasks(null);
    if (oldChildTasks != null) {
      for (Task<?> tsk : oldChildTasks) {
        // remove the current task from its original parent task's dependent task
        tsk.getParentTasks().remove(currTask);
        // make new generated task depends on all the parent tasks of current task.
        newTask.addDependentTask(tsk);
      }
    }
  }
Common iteration methods for converting joins and sort-merge joins.
ql/src/java/org/apache/hadoop/hive/ql/optimizer/physical/AbstractJoinTaskDispatcher.java