private List<Task<?>> findStatsTasks(
      List<Task<?>> rootTasks, List<Task<?>> statsTasks) {
    for (Task<? extends  Serializable> t : rootTasks) {
      if (t instanceof StatsTask) {
        if (statsTasks == null) {
          statsTasks = new ArrayList<>();
        }
        statsTasks.add(t);
      }
      if (t.getDependentTasks() != null) {
        statsTasks = findStatsTasks(t.getDependentTasks(), statsTasks);
      }
    }
    return statsTasks;
  }
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