presto-main/src/main/java/io/prestosql/sql/analyzer/StatementAnalyzer.java/OrderByExpressionRewriter/rewriteIdentifier
class OrderByExpressionRewriter:            @Override
            public Expression rewriteIdentifier(Identifier reference, Void context, ExpressionTreeRewriter<Void> treeRewriter)
            {
                // if this is a simple name reference, try to resolve against output columns
                QualifiedName name = QualifiedName.of(reference.getValue());
                Set<Expression> expressions = ImmutableSet.copyOf(assignments.get(name));

                if (expressions.size() > 1) {
                    throw semanticException(AMBIGUOUS_NAME, reference, "'%s' in ORDER BY is ambiguous", name);
                }

                if (expressions.size() == 1) {
                    return Iterables.getOnlyElement(expressions);
                }

                // otherwise, couldn't resolve name against output aliases, so fall through...
                return reference;
            }