@Experimental public abstract class Reducer extends Object
Reducers.
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.
// Count items in each group
Reducers.count().as("item_count")
// Sum numeric values
Reducers.sum("@sales").as("total_sales")
// Calculate average
Reducers.avg("@price").as("average_price")
// Quantile with percentile parameter
Reducers.quantile("@price", 0.5).as("median_price")
// First value with optional sort by
Reducers.firstValue("@name").by("@timestamp").as("first_name")
// Random sample
Reducers.randomSample("@id", 10).as("sample_ids")
Reducers,
ReduceFunction,
GroupBy,
FT.AGGREGATE,
FT.HYBRID| Modifier | Constructor and Description |
|---|---|
protected |
Reducer(ReduceFunction function)
Creates a new reducer with the specified function.
|
protected |
Reducer(String function)
Creates a new reducer with the specified function name.
|
| Modifier and Type | Method and Description |
|---|---|
<T extends Reducer> |
as(String alias)
Set an alias for the reducer result using AS keyword.
|
void |
build(CommandArgs<?,?> args)
Build the reducer into command args.
|
String |
getFunction()
Get the reduce function name.
|
protected abstract List<Object> |
getOwnArgs()
Get the reducer-specific arguments.
|
protected Reducer(ReduceFunction function)
function - the reduce function enumprotected Reducer(String function)
ReduceFunction.function - the reduce function name (e.g., "COUNT", "SUM", "MY_CUSTOM_REDUCER")public final String getFunction()
protected abstract List<Object> getOwnArgs()
public <T extends Reducer> T as(String alias)
alias - the alias namepublic final void build(CommandArgs<?,?> args)
Format: REDUCE function nargs arg [arg ...] [AS name]
args - the command args to build intoCopyright © 2026 lettuce.io. All rights reserved.