streamz icon indicating copy to clipboard operation
streamz copied to clipboard

How to load initial state or backfill the stream dataframe

Open demiladef opened this issue 2 years ago • 2 comments

Is it possible to start a sdf or stream with an initial state or backfill the sdf with values from a database or cache?

demiladef avatar Jun 23 '22 11:06 demiladef

An dfs or stream doesn't have a state; but you probably mean the various kinds of aggregations and other operations which do. Some of these allow you to specify state upon creation (e.g., DataFrame.aggregate), others maintain their stage in insrtance attributes, so that you can set them whenever you want

s = streamz.Stream()
u = s.unique()
u.sink(print)
u.seen = {1: 1}  # mark value 1 as already seen
s.emit(0)  # prints "0"
s.emit(1)  # doesn't print anything, already seen

You can also pass events in from your original stream (s.emit()) or a stream made for the purpose, to prime the stage of your aggregation node, or even call the node's update method to simulate the same.

martindurant avatar Jun 23 '22 16:06 martindurant

thanks! yes I meant for aggregation. Priming the stage for aggregation using emit makes sense

demiladef avatar Jun 27 '22 10:06 demiladef