Details
-
Improvement
-
Status: Resolved
-
P2
-
Resolution: Duplicate
-
None
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
- duplicates
-
BEAM-1589 Add OnWindowExpiration method to Stateful DoFn
- Triage Needed