private void linkRealDependencies(LinkedHashMap<CTEClause, LinkedHashSet<CTEClause>> realDependencies) {
    LinkedHashMap<CTEClause, List<Task<?>>> dependentTasks = new LinkedHashMap<>();
    for (CTEClause child : realDependencies.keySet()) {
      for (CTEClause parent : realDependencies.get(child)) {
        if (!dependentTasks.containsKey(parent)) {
          dependentTasks.put(parent, new ArrayList<>());
        }
        dependentTasks.get(parent).addAll(getRealTasks(child));
      }
    }
    // This operation must be performed only once per CTE since it creates new leaves
    for (CTEClause parent : dependentTasks.keySet()) {
      List<Task<?>> sources = Task.findLeafs(getRealTasks(parent));
      linkTasks(sources, dependentTasks.get(parent));
    }
  }
Links tasks based on dependencies among CTEs which have actual tasks.
For example, when materialized CTE X depends on materialized CTE Y,
the leaf tasks of Y must have the root tasks of X as its child tasks.
ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java