@Experimental public class GroupBy extends Object implements PostProcessingOperation
Groups the results in the pipeline based on one or more properties. Each group should have at least one reducer function that handles the group entries, either counting them or performing multiple aggregate operations.
{
@code
// Group by category and count items
GroupBy groupBy = GroupBy.of("category").reduce(Reducers.count().as("item_count"));
// Group by multiple fields with multiple reducers
GroupBy complexGroup = GroupBy.of("category", "brand").reduce(Reducers.count().as("count"))
.reduce(Reducers.avg("@price").as("avg_price"));
}
Reducer,
Reducers,
ReduceFunction,
PostProcessingOperation| Constructor and Description |
|---|
GroupBy(List<String> properties)
Creates a new GROUPBY operation.
|
| Modifier and Type | Method and Description |
|---|---|
void |
build(CommandArgs<?,?> args)
Build the operation arguments into the command args.
|
static GroupBy |
of(String... properties)
Static factory method to create a GroupBy instance.
|
GroupBy |
reduce(Reducer reducer)
Add a reducer to this GROUPBY operation.
|
@SafeVarargs public static GroupBy of(String... properties)
properties - the properties to group bypublic GroupBy reduce(Reducer reducer)
reducer - the reducer to addpublic void build(CommandArgs<?,?> args)
PostProcessingOperationbuild in interface PostProcessingOperationargs - the command args to build intoCopyright © 2026 lettuce.io. All rights reserved.