private void addExportTask(List<Task<?>> rootTasks,
      Task<ExportWork> exportTask, Task<DDLWork> alterTable) {
    for (Task<? extends  Serializable> t : rootTasks) {
      if (t.getNumChild() <= 0) {
        //todo: ConditionalTask#addDependentTask(Task) doesn't do the right thing: HIVE-18978
        t.addDependentTask(alterTable);
        //this is a leaf so add exportTask to follow it
        alterTable.addDependentTask(exportTask);
      } else {
        addExportTask(t.getDependentTasks(), exportTask, alterTable);
      }
    }
  }
Makes the exportTask run after all other tasks of the "insert into T ..." are done.
ql/src/java/org/apache/hadoop/hive/ql/parse/AcidExportSemanticAnalyzer.java