Package org.apache.beam.sdk.transforms
Annotation Interface DoFn.StateId
Annotation for declaring and dereferencing state cells.
To declare a state cell, create a field of type StateSpec
annotated with a DoFn.StateId
. To use the cell during processing, add a parameter of the appropriate State
subclass to your @ProcessElement
or @OnTimer
method, and
annotate it with DoFn.StateId
. See the following code for an example:
new DoFn<KV<Key, Foo>, Baz>() {
@StateId("my-state-id")
private final StateSpec<ValueState<MyState>> myStateSpec =
StateSpecs.value(new MyStateCoder());
@ProcessElement
public void processElement(
@Element InputT element,
@StateId("my-state-id") ValueState<MyState> myState) {
myState.read();
myState.write(...);
}
}
State is subject to the following validity conditions:
- Each state ID must be declared at most once.
- Any state referenced in a parameter must be declared with the same state type.
- State declarations must be final.
-
Required Element Summary
Required Elements
-
Element Details
-
value
String valueThe state ID.
-