public static class AggregateArgs.Reducer<K,V> extends Object
Reducers handle group entries in a GROUPBY operation, performing aggregate operations like counting, summing, averaging, or finding min/max values. Each reducer can have an optional alias using the AS keyword.
{
@code
// Count items in each group
Reducer count = Reducer.count().as("item_count");
// Sum numeric values
Reducer totalSales = Reducer.sum("@sales").as("total_sales");
// Calculate average
Reducer avgPrice = Reducer.avg("@price").as("average_price");
// Find extremes
Reducer maxScore = Reducer.max("@score").as("highest_score");
Reducer minPrice = Reducer.min("@price").as("lowest_price");
// Count distinct values
Reducer uniqueUsers = Reducer.countDistinct("@user_id").as("unique_users");
}
If no alias is provided using as(), the resulting field name will be the function name combined with the field
name (e.g., "count_distinct(@user_id)").
| Modifier and Type | Method and Description |
|---|---|
AggregateArgs.Reducer<K,V> |
as(K alias) |
static <K,V> AggregateArgs.Reducer<K,V> |
avg(V field)
Static factory method to create an AVG reducer.
|
void |
build(CommandArgs<K,V> args) |
static <K,V> AggregateArgs.Reducer<K,V> |
count()
Static factory method to create a COUNT reducer.
|
static <K,V> AggregateArgs.Reducer<K,V> |
countDistinct(V field)
Static factory method to create a COUNT_DISTINCT reducer.
|
static <K,V> AggregateArgs.Reducer<K,V> |
max(V field)
Static factory method to create a MAX reducer.
|
static <K,V> AggregateArgs.Reducer<K,V> |
min(V field)
Static factory method to create a MIN reducer.
|
static <K,V> AggregateArgs.Reducer<K,V> |
sum(V field)
Static factory method to create a SUM reducer.
|
public AggregateArgs.Reducer<K,V> as(K alias)
public static <K,V> AggregateArgs.Reducer<K,V> count()
K - Key typeV - Value typepublic static <K,V> AggregateArgs.Reducer<K,V> sum(V field)
K - Key typeV - Value typefield - the field to sumpublic static <K,V> AggregateArgs.Reducer<K,V> avg(V field)
K - Key typeV - Value typefield - the field to averagepublic static <K,V> AggregateArgs.Reducer<K,V> min(V field)
K - Key typeV - Value typefield - the field to find minimumpublic static <K,V> AggregateArgs.Reducer<K,V> max(V field)
K - Key typeV - Value typefield - the field to find maximumpublic static <K,V> AggregateArgs.Reducer<K,V> countDistinct(V field)
K - Key typeV - Value typefield - the field to count distinct valuespublic void build(CommandArgs<K,V> args)
Copyright © 2025 lettuce.io. All rights reserved.