presto-main/src/main/java/io/prestosql/sql/planner/EqualityInference.java/EqualityInference/getScopedCanonical
class EqualityInference:    @VisibleForTesting
    Expression getScopedCanonical(Expression expression, Predicate<Symbol> symbolScope)
    {
        Expression canonicalIndex = canonicalMap.get(expression);
        if (canonicalIndex == null) {
            return null;
        }

        Collection<Expression> equivalences = equalitySets.get(canonicalIndex);
        if (expression instanceof SymbolReference) {
            boolean inScope = equivalences.stream()
                    .filter(SymbolReference.class::isInstance)
                    .map(Symbol::from)
                    .anyMatch(symbolScope);

            if (!inScope) {
                return null;
            }
        }

        Set<Expression> candidates = equivalences.stream()
                .filter(e -> isScoped(e, symbolScope))
                .collect(Collectors.toSet());

        return getCanonical(candidates);
    }