Uploaded image for project: 'Beam'
  1. Beam
  2. BEAM-5307

Allow injection of state in DoFn.FinishBundle

Details

    • Improvement
    • Status: Resolved
    • P2
    • Resolution: Duplicate
    • None
    • Not applicable
    • sdk-java-core

    Description

      Example use case: a stateful DoFn that requires persisting its state to an external database. Instead of writing to the external database for each element, it is much more efficient to flush the state every once in a while, or when cleaning up.

      Currently, this is not possible because the @StateId injection is only available in processing functions and timers. This might be a workaround, but I'm not even sure if it works.

      Instead, by allowing the use of @StateId inside a @FinishBundle function, we can make sure the internal state is persisted in all scenarios:

      @FinishBundle
      public void flush(FinishBundleContext context, @StateId("myState") ValueState<StateObj> state) {
          repository.save(state.read());
      }
      

       

      Attachments

        Issue Links

          Activity

            People

              kenn Kenneth Knowles
              sploegsma Sander Ploegsma
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: