3.2. Result post-processing

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.

3.2.1. GroupBy processing

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)

This will return a map of post ids to related comments.

Multiple result columns

Map<Integer, Group> results = query.from(post, comment)
    .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.