Annotation Type DoFn.AlwaysFetched


  • @Documented
    @Retention(RUNTIME)
    @Target({FIELD,PARAMETER})
    @Experimental(STATE)
    public static @interface DoFn.AlwaysFetched
    Annotation for declaring that a state parameter is always fetched.

    A DoFn might not fetch a state value on every element, and for that reason runners may choose to defer fetching state until read() is called. Annotating a state argument with this parameter provides a hint to the runner that the state is always fetched. This may cause the runner to prefetch all the state before calling the processElement or processTimer method, improving performance. This is a performance-only hint - it does not change semantics. 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,
          @AlwaysFetched @StateId("my-state-id") ValueState<MyState> myState) {
         myState.read();
         myState.write(...);
       }
     }
     

    This can only be used on state objects that implement ReadableState.