Annotation Interface DoFn.StateId

Enclosing class:
DoFn<InputT extends @Nullable Object,OutputT extends @Nullable Object>

@Documented @Retention(RUNTIME) @Target({FIELD,PARAMETER}) 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 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
    Modifier and Type
    Required Element
    Description
    The state ID.
  • Element Details

    • value

      String value
      The state ID.