presto-main/src/main/java/io/prestosql/sql/analyzer/Scope.java/Scope/getOuterQueryParent
class Scope:    public Optional<Scope> getOuterQueryParent()
    {
        Scope scope = this;
        while (scope.parent.isPresent()) {
            if (scope.queryBoundary) {
                return scope.parent;
            }
            scope = scope.parent.get();
        }

        return Optional.empty();
    }