public List findImpl()

in zetasql-toolkit-core/src/main/java/com/google/zetasql/toolkit/tools/lineage/ParentColumnFinder.java [115:142]


  public List<ResolvedColumn> findImpl(ResolvedNode containerNode, ResolvedColumn column) {
    // 1. Traverse the containerNode.
    // This will populate this.columnsToParents with the ResolvedColumns in the containerNode
    // and
    // the direct parents for each of them.
    // columnsToParents can be thought of as a tree where the root node is the original
    // ResolvedColumn and the leaves are its terminal parents.
    containerNode.accept(this);

    // 2. Use this.columnsToParents to find the terminal parents for the desired column.
    // Traverses the tree-like structured mentioned above using breadth-first search.
    ArrayList<ResolvedColumn> result = new ArrayList<>();
    Queue<ResolvedColumn> resolutionQueue = new ArrayDeque<>(ImmutableList.of(column));

    while (resolutionQueue.peek() != null) {
      ResolvedColumn currentColumn = resolutionQueue.remove();
      String currentColumnKey = makeColumnKey(currentColumn);
      List<ResolvedColumn> parents = getParentsOfColumn(currentColumn);

      if (parents.isEmpty() && terminalColumns.contains(currentColumnKey)) {
        result.add(currentColumn);
      } else {
        resolutionQueue.addAll(parents);
      }
    }

    return result;
  }