Class TtlAggregateFunction<IN,ACC,OUT>
- java.lang.Object
-
- org.apache.flink.runtime.state.ttl.AbstractTtlDecorator<AggregateFunction<IN,ACC,OUT>>
-
- org.apache.flink.runtime.state.v2.ttl.TtlAggregateFunction<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,TtlValue<ACC>,OUT>
,Function
public class TtlAggregateFunction<IN,ACC,OUT> extends AbstractTtlDecorator<AggregateFunction<IN,ACC,OUT>> implements AggregateFunction<IN,TtlValue<ACC>,OUT>
This class wraps aggregating function with TTL logic.- See Also:
- Serialized Form
-
-
Field Summary
-
Fields inherited from class org.apache.flink.runtime.state.ttl.AbstractTtlDecorator
config, original, returnExpired, timeProvider, ttl, updateTsOnRead
-
-
Constructor Summary
Constructors Constructor Description TtlAggregateFunction(AggregateFunction<IN,ACC,OUT> aggFunction, StateTtlConfig config, TtlTimeProvider timeProvider)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description TtlValue<ACC>
add(IN value, TtlValue<ACC> accumulator)
Adds the given input value to the given accumulator, returning the new accumulator value.TtlValue<ACC>
createAccumulator()
Creates a new accumulator, starting a new aggregate.OUT
getResult(TtlValue<ACC> accumulator)
Gets the result of the aggregation from the accumulator.TtlValue<ACC>
merge(TtlValue<ACC> a, TtlValue<ACC> b)
Merges two accumulators, returning an accumulator with the merged state.-
Methods inherited from class org.apache.flink.runtime.state.ttl.AbstractTtlDecorator
expired, getElementWithTtlCheck, getUnexpired, getWithTtlCheckAndUpdate, getWrappedWithTtlCheckAndUpdate, rewrapWithNewTs, wrapWithTs
-
-
-
-
Constructor Detail
-
TtlAggregateFunction
public TtlAggregateFunction(AggregateFunction<IN,ACC,OUT> aggFunction, StateTtlConfig config, TtlTimeProvider timeProvider)
-
-
Method Detail
-
createAccumulator
public TtlValue<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 TtlValue<ACC> add(IN value, TtlValue<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 OUT getResult(TtlValue<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 TtlValue<ACC> merge(TtlValue<ACC> a, TtlValue<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
-
-