@Override
    public RES transform(FetchableQuery<?, ?> query) {
        Map<K, Group> groups = (Map) mapFactory.get();

        // create groups
        FactoryExpression<Tuple> expr = FactoryExpressionUtils.wrap(Projections.tuple(expressions));
        boolean hasGroups = false;
        for (Expression<?> e : expr.getArgs()) {
            hasGroups |= e instanceof GroupExpression;
        }
        if (hasGroups) {
            expr = withoutGroupExpressions(expr);
        }
        CloseableIterator<Tuple> iter = query.select(expr).iterate();
        try {
            while (iter.hasNext()) {
                @SuppressWarnings("unchecked") //This type is mandated by the key type
                        K[] row = (K[]) iter.next().toArray();
                K groupId = row[0];
                GroupImpl group = (GroupImpl) groups.get(groupId);
                if (group == null) {
                    group = new GroupImpl(groupExpressions, maps);
                    groups.put(groupId, group);
                }
                group.add(row);
            }
        } finally {
            iter.close();
        }

        // transform groups
        return transform(groups);

    }
Provides aggregated results as a map

@param <K> Map key type
@param <V> Map value type
@param <RES> Resulting map type
@author Jan-Willem Gmelig Meyling
querydsl-core/src/main/java/com/querydsl/core/group/GroupByGenericMap.java