void ensureDagIdxAtLeast(int min) {
      if (dagIdx >= min) {
        return;
      }
      dagIdx = min;
      for (Edge<V, E> e : edges) {
        if(e.t == this) {
          DagGraph.DagNode<V, E> s = (DagGraph.DagNode<V, E>) e.s;
          s.ensureDagIdxAtLeast(min + 1);
        }
      }
    }
A directed graph extended with support to check dag property.
ql/src/java/org/apache/hadoop/hive/ql/optimizer/graph/DagGraph.java