Package org.apache.beam.sdk.transforms
Annotation Type DoFn.StateId
-
@Documented @Retention(RUNTIME) @Target({FIELD,PARAMETER}) @Experimental(STATE) public static @interface DoFn.StateId
Annotation for declaring and dereferencing state cells.To declare a state cell, create a field of type
StateSpec
annotated with aDoFn.StateId
. To use the cell during processing, add a parameter of the appropriateState
subclass to your@ProcessElement
or@OnTimer
method, and annotate it withDoFn.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 Modifier and Type Required Element Description java.lang.String
value
The state ID.
-