presto-main/src/main/java/io/prestosql/sql/planner/SortExpressionExtractor.java/SortExpressionExtractor/visitComparisonExpression
class SortExpressionExtractor:        @Override
        protected Optional<SortExpressionContext> visitComparisonExpression(ComparisonExpression comparison, Void context)
        {
            switch (comparison.getOperator()) {
                case GREATER_THAN:
                case GREATER_THAN_OR_EQUAL:
                case LESS_THAN:
                case LESS_THAN_OR_EQUAL:
                    Optional<SymbolReference> sortChannel = asBuildSymbolReference(buildSymbols, comparison.getRight());
                    boolean hasBuildReferencesOnOtherSide = hasBuildSymbolReference(buildSymbols, comparison.getLeft());
                    if (!sortChannel.isPresent()) {
                        sortChannel = asBuildSymbolReference(buildSymbols, comparison.getLeft());
                        hasBuildReferencesOnOtherSide = hasBuildSymbolReference(buildSymbols, comparison.getRight());
                    }
                    if (sortChannel.isPresent() && !hasBuildReferencesOnOtherSide) {
                        return sortChannel.map(symbolReference -> new SortExpressionContext(symbolReference, singletonList(comparison)));
                    }
                    return Optional.empty();
                default:
                    return Optional.empty();
            }
        }