Querydsl contains result post-processing functionality in form of the
com.mysema.query.ResultTransformer
interface.
Currently this interface has only been used for result aggregation via the GroupBy class.
The com.mysema.query.group.GroupBy
class provides aggregation functionality
which can be used to aggregate query results in memory. Below are some usage examples.
Aggregating parent child relations
import static com.mysema.query.group.GroupBy.*; Map<Integer, List<Comment>> results = query.from(post, comment) .where(comment.post.id.eq(post.id)) .transform(groupBy(post.id).as(list(comment)));
This will return a map of post ids to related comments.
Multiple result columns
Map<Integer, Group> results = query.from(post, comment) .where(comment.post.id.eq(post.id)) .transform(groupBy(post.id).as(post.name, set(comment.id)));
This will return a map of post ids to Group instances with access to post name and comment ids.
Group is the GroupBy equivalent to the Tuple interface.
More examples can be found here.