K - Key type.V - Value type.@Experimental public class GroupBy<K,V> extends Object implements PostProcessingOperation<K,V>
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<K> properties)
Creates a new GROUPBY operation.
|
| Modifier and Type | Method and Description |
|---|---|
void |
build(CommandArgs<K,V> args)
Build the operation arguments into the command args.
|
static <K,V> GroupBy<K,V> |
of(K... properties)
Static factory method to create a GroupBy instance.
|
GroupBy<K,V> |
reduce(Reducer<K> reducer)
Add a reducer to this GROUPBY operation.
|
@SafeVarargs public static <K,V> GroupBy<K,V> of(K... properties)
K - Key typeV - Value typeproperties - the properties to group bypublic GroupBy<K,V> reduce(Reducer<K> reducer)
reducer - the reducer to addpublic void build(CommandArgs<K,V> args)
PostProcessingOperationbuild in interface PostProcessingOperation<K,V>args - the command args to build intoCopyright © 2026 lettuce.io. All rights reserved.