presto-main/src/main/java/io/prestosql/sql/planner/iterative/rule/RemoveRedundantDistinctLimit.java/RemoveRedundantDistinctLimit/apply
class RemoveRedundantDistinctLimit:    @Override
    public Result apply(DistinctLimitNode node, Captures captures, Context context)
    {
        checkArgument(!node.getHashSymbol().isPresent(), "HashSymbol should be empty");
        if (node.getLimit() == 0) {
            return Result.ofPlanNode(new ValuesNode(node.getId(), node.getOutputSymbols(), ImmutableList.of()));
        }
        if (isScalar(node.getSource(), context.getLookup())) {
            return Result.ofPlanNode(node.getSource());
        }
        else if (isAtMost(node.getSource(), context.getLookup(), node.getLimit())) {
            return Result.ofPlanNode(new AggregationNode(node.getId(),
                    node.getSource(),
                    ImmutableMap.of(),
                    singleGroupingSet(node.getDistinctSymbols()),
                    ImmutableList.of(),
                    SINGLE,
                    node.getHashSymbol(),
                    Optional.empty()));
        }
        return Result.empty();
    }