@Override
    public RES transform(FetchableQuery<?,?> query) {
        // TODO Table<Object, Object, Group> after support for it in https://github.com/querydsl/querydsl/issues/2644
        Table<R, Object, Group> groups = HashBasedTable.create();

        // 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
                Object[] row = iter.next().toArray();
                R groupId = (R) row[0];
                Object rowId = row[1];
                GroupImpl group = (GroupImpl) groups.get(groupId, rowId);
                if (group == null) {
                    group = new GroupImpl(groupExpressions, maps);
                    groups.put(groupId, rowId, group);
                }
                group.add(row);
            }
        } finally {
            iter.close();
        }

        // transform groups
        return transform(groups);

    }
Provides aggregated results as a table

@author Jan-Willem Gmelig Meyling

@param <R> row type
@param <C> column type
@param <V> value type
@param <RES> table type
querydsl-guava/src/main/java/com/querydsl/core/group/guava/GroupByTable.java