private Optional findInScopeWithEntryByName()

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


  private Optional<ResolvedWithEntry> findInScopeWithEntryByName(String name) {
    Optional<ResolvedWithEntry> maybeWithEntry = Optional.empty();

    // Traverse the scopes stack top-to-bottom and use the first matching WITH in scope
    for (int i = withEntryScopes.size() - 1; i >= 0; i--) {
      List<ResolvedWithEntry> inScopeWithEntries = withEntryScopes.get(i);

      maybeWithEntry =
          inScopeWithEntries.stream()
              .filter(withEntry -> withEntry.getWithQueryName().equalsIgnoreCase(name))
              .findFirst();

      if (maybeWithEntry.isPresent()) {
        break;
      }
    }

    return maybeWithEntry;
  }