streamz
streamz copied to clipboard
How to load initial state or backfill the stream dataframe
Is it possible to start a sdf or stream with an initial state or backfill the sdf with values from a database or cache?
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.
thanks! yes I meant for aggregation. Priming the stage for aggregation using emit makes sense