presto-main/src/main/java/io/prestosql/sql/planner/optimizations/PlanNodeSearcher.java/PlanNodeSearcher/replaceAllRecursive
class PlanNodeSearcher:    private PlanNode replaceAllRecursive(PlanNode node, PlanNode nodeToReplace)
    {
        node = lookup.resolve(node);

        if (where.test(node)) {
            return nodeToReplace;
        }
        if (recurseOnlyWhen.test(node)) {
            List<PlanNode> sources = node.getSources().stream()
                    .map(source -> replaceAllRecursive(source, nodeToReplace))
                    .collect(toImmutableList());
            return replaceChildren(node, sources);
        }
        return node;
    }