Saving state from UDFs with group by in Kapacitor

I have looked at the moving average and outlier examples and want to make sure I am understanding the code correctly.

My concern is “How do you save state for UDFs when there is a group by in the initial stream”

If i’m reading this correctly, This is saying there is a state per group getting saved and its adding new “states” for an unseen group.

if point.group not in self._state:
self._state[point.group] = AvgHandler.state(self._size)
avg = self._state[point.group].update(value)

Then in snapshot / restore we iterate through each one.
Am Interpretting this correctly?

Yes, that is correct, The UDF will be passed all data for all groups. It is the responsibility of the UDF to track the state per group.

1 Like

So then how can you override the group to set a different index?