presto-main/src/main/java/io/prestosql/sql/planner/optimizations/PlanNodeSearcher.java/PlanNodeSearcher/findFirstRecursive
class PlanNodeSearcher:    private <T extends PlanNode> Optional<T> findFirstRecursive(PlanNode node)
    {
        node = lookup.resolve(node);

        if (where.test(node)) {
            return Optional.of((T) node);
        }
        if (recurseOnlyWhen.test(node)) {
            for (PlanNode source : node.getSources()) {
                Optional<T> found = findFirstRecursive(source);
                if (found.isPresent()) {
                    return found;
                }
            }
        }
        return Optional.empty();
    }