Interface CombiningState<InputT,AccumT,OutputT>
-
- Type Parameters:
InputT
- the type of values added to the stateAccumT
- the type of accumulatorOutputT
- the type of value extracted from the state
- All Superinterfaces:
GroupingState<InputT,OutputT>
,ReadableState<OutputT>
,State
@Experimental(STATE) public interface CombiningState<InputT,AccumT,OutputT> extends GroupingState<InputT,OutputT>
AReadableState
cell defined by aCombine.CombineFn
, accepting multiple input values, combining them as specified into accumulators, and producing a single output value.Implementations of this form of state are expected to implement
GroupingState.add(InputT)
efficiently, not via a sequence of read-modify-write.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
addAccum(AccumT accum)
Add an accumulator to this state cell.AccumT
getAccum()
Read the merged accumulator for this state cell.AccumT
mergeAccumulators(java.lang.Iterable<AccumT> accumulators)
Merge the given accumulators according to the underlyingCombine.CombineFn
.OutputT
read()
Read the current value, blocking until it is available.CombiningState<InputT,AccumT,OutputT>
readLater()
Indicate that the value will be read later.-
Methods inherited from interface org.apache.beam.sdk.state.GroupingState
add, isEmpty
-
-
-
-
Method Detail
-
read
@Nonnull OutputT read()
Description copied from interface:ReadableState
Read the current value, blocking until it is available.If there will be many calls to
ReadableState.read()
for different state in short succession, you should first callReadableState.readLater()
for all of them so the reads can potentially be batched (depending on the underlying implementation}.The returned object should be independent of the underlying state. Any direct modification of the returned object should not modify state without going through the appropriate state interface, and modification to the state should not be mirrored in the returned object.
- Specified by:
read
in interfaceReadableState<InputT>
-
getAccum
AccumT getAccum()
Read the merged accumulator for this state cell. It is implied that reading the state involves reading the accumulator, soreadLater()
is sufficient to prefetch for this.
-
addAccum
void addAccum(AccumT accum)
Add an accumulator to this state cell. Depending on implementation this may immediately merge it with the previous accumulator, or may buffer this accumulator for a future merge.
-
mergeAccumulators
AccumT mergeAccumulators(java.lang.Iterable<AccumT> accumulators)
Merge the given accumulators according to the underlyingCombine.CombineFn
.
-
readLater
CombiningState<InputT,AccumT,OutputT> readLater()
Description copied from interface:ReadableState
Indicate that the value will be read later.This allows an implementation to start an asynchronous prefetch or to include this state in the next batch of reads.
- Specified by:
readLater
in interfaceGroupingState<InputT,AccumT>
- Specified by:
readLater
in interfaceReadableState<InputT>
- Returns:
- this for convenient chaining
-
-