presto-main/src/main/java/io/prestosql/sql/planner/iterative/rule/SingleDistinctAggregationToGroupBy.java/SingleDistinctAggregationToGroupBy/apply
class SingleDistinctAggregationToGroupBy:    @Override
    public Result apply(AggregationNode aggregation, Captures captures, Context context)
    {
        List<Set<Expression>> argumentSets = extractArgumentSets(aggregation)
                .collect(Collectors.toList());

        Set<Symbol> symbols = Iterables.getOnlyElement(argumentSets).stream()
                .map(Symbol::from)
                .collect(Collectors.toSet());

        return Result.ofPlanNode(
                new AggregationNode(
                        aggregation.getId(),
                        new AggregationNode(
                                context.getIdAllocator().getNextId(),
                                aggregation.getSource(),
                                ImmutableMap.of(),
                                singleGroupingSet(ImmutableList.<Symbol>builder()
                                        .addAll(aggregation.getGroupingKeys())
                                        .addAll(symbols)
                                        .build()),
                                ImmutableList.of(),
                                SINGLE,
                                Optional.empty(),
                                Optional.empty()),
                        // remove DISTINCT flag from function calls
                        aggregation.getAggregations()
                                .entrySet().stream()
                                .collect(Collectors.toMap(
                                        Map.Entry::getKey,
                                        e -> removeDistinct(e.getValue()))),
                        aggregation.getGroupingSets(),
                        emptyList(),
                        aggregation.getStep(),
                        aggregation.getHashSymbol(),
                        aggregation.getGroupIdSymbol()));
    }