presto-main/src/main/java/io/prestosql/sql/planner/optimizations/UnaliasSymbolReferences.java/UnaliasSymbolReferences/canonicalizeAndDistinct
class UnaliasSymbolReferences:        private OrderingScheme canonicalizeAndDistinct(OrderingScheme orderingScheme)
        {
            Set<Symbol> added = new HashSet<>();
            ImmutableList.Builder<Symbol> symbols = ImmutableList.builder();
            ImmutableMap.Builder<Symbol, SortOrder> orderings = ImmutableMap.builder();
            for (Symbol symbol : orderingScheme.getOrderBy()) {
                Symbol canonical = canonicalize(symbol);
                if (added.add(canonical)) {
                    symbols.add(canonical);
                    orderings.put(canonical, orderingScheme.getOrdering(symbol));
                }
            }

            return new OrderingScheme(symbols.build(), orderings.build());
        }