0

Using Siddhi 3.0.3 as Java library.

I've developed custom aggregation functions by extending AttributeAggregator class, and I've seen some strange behavior after processRemove() method is called. When processRemove() is called, I remove the value and return the new aggregation result. However, the event returned by result handler is still receiving the old value. However, processAdd() is working correctly. After some debugging, I've noticed that after each call to processAdd(), the result events contain the object returned by the last call to processAdd(). However, after a call to processRemove(), the event contains the same object it had before (that from last processAdd()), not the last object returned by processRemove().

If I maintain a collection, adding removing from it and always returning the same collection object, all is good. But for aggregation functions that return numeric values, each processAdd()/processRemove() return a boxed Long, which does not get replaced with the return from processRemove().

I've also noticed this same behavior using the built-in aggregate function count().

DBug
  • 2,502
  • 1
  • 12
  • 25

1 Answers1

1

Attribute aggregators are used to perform statefull operations like sum, average, count on a collection of events, a window to be precise. Let me explain how these attribute aggregators behave.

Windows which can collect events emit two types of event. Current and Expired. Current events are the events which just came inside window. Expired events are the events which were expired to make room for newly came events.So after a window reaches it's threshold it will always emit an expired event followed by current event. This expired event and current event will be in same EventChunk, but expired event will always be in-front of current event.

So in the Query Selector level when we call attibute aggregator processRemove will be called first always followed by processAdd. Query Selector will only retain last event to be sent as output unless there is a group by. So if you are looking at the output from query selector you will always see the last event which has object returned by processAdd there.

This is the default behavior of Siddhi. If this behavior does not r requirement, please explain your requirement. We will be able to help you out!!

Regards

Tishan
  • 890
  • 6
  • 11