Class RichAggregateFunction<IN,ACC,OUT>
- java.lang.Object
-
- org.apache.flink.api.common.functions.AbstractRichFunction
-
- org.apache.flink.api.common.functions.RichAggregateFunction<IN,ACC,OUT>
-
- Type Parameters:
IN
- The type of the values that are aggregated (input values)ACC
- The type of the accumulator (intermediate aggregate state).OUT
- The type of the aggregated result
- All Implemented Interfaces:
Serializable
,AggregateFunction<IN,ACC,OUT>
,Function
,RichFunction
@PublicEvolving public abstract class RichAggregateFunction<IN,ACC,OUT> extends AbstractRichFunction implements AggregateFunction<IN,ACC,OUT>
Rich variant of theAggregateFunction
. As aRichFunction
, it gives access to theRuntimeContext
and provides setup and teardown methods:RichFunction.open(OpenContext)
andRichFunction.close()
.- See Also:
AggregateFunction
, Serialized Form
-
-
Constructor Summary
Constructors Constructor Description RichAggregateFunction()
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description abstract ACC
add(IN value, ACC accumulator)
Adds the given input value to the given accumulator, returning the new accumulator value.abstract ACC
createAccumulator()
Creates a new accumulator, starting a new aggregate.abstract OUT
getResult(ACC accumulator)
Gets the result of the aggregation from the accumulator.abstract ACC
merge(ACC a, ACC b)
Merges two accumulators, returning an accumulator with the merged state.-
Methods inherited from class org.apache.flink.api.common.functions.AbstractRichFunction
close, getIterationRuntimeContext, getRuntimeContext, open, setRuntimeContext
-
-
-
-
Method Detail
-
createAccumulator
public abstract ACC createAccumulator()
Description copied from interface:AggregateFunction
Creates a new accumulator, starting a new aggregate.The new accumulator is typically meaningless unless a value is added via
AggregateFunction.add(Object, Object)
.The accumulator is the state of a running aggregation. When a program has multiple aggregates in progress (such as per key and window), the state (per key and window) is the size of the accumulator.
- Specified by:
createAccumulator
in interfaceAggregateFunction<IN,ACC,OUT>
- Returns:
- A new accumulator, corresponding to an empty aggregate.
-
add
public abstract ACC add(IN value, ACC accumulator)
Description copied from interface:AggregateFunction
Adds the given input value to the given accumulator, returning the new accumulator value.For efficiency, the input accumulator may be modified and returned.
- Specified by:
add
in interfaceAggregateFunction<IN,ACC,OUT>
- Parameters:
value
- The value to addaccumulator
- The accumulator to add the value to- Returns:
- The accumulator with the updated state
-
getResult
public abstract OUT getResult(ACC accumulator)
Description copied from interface:AggregateFunction
Gets the result of the aggregation from the accumulator.- Specified by:
getResult
in interfaceAggregateFunction<IN,ACC,OUT>
- Parameters:
accumulator
- The accumulator of the aggregation- Returns:
- The final aggregation result.
-
merge
public abstract ACC merge(ACC a, ACC b)
Description copied from interface:AggregateFunction
Merges two accumulators, returning an accumulator with the merged state.This function may reuse any of the given accumulators as the target for the merge and return that. The assumption is that the given accumulators will not be used any more after having been passed to this function.
- Specified by:
merge
in interfaceAggregateFunction<IN,ACC,OUT>
- Parameters:
a
- An accumulator to mergeb
- Another accumulator to merge- Returns:
- The accumulator with the merged state
-
-