@Documented @Retention(value=RUNTIME) @Target(value={FIELD,PARAMETER}) @Experimental(value=STATE) public static @interface DoFn.StateId
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:
Modifier and Type | Required Element and Description |
---|---|
java.lang.String |
value
The state ID.
|