Search code examples
javasiddhi

Is it possible to control time in Siddhi Cep


In below example, time is cpu time. What I am struggling is when I run a time series for back test purpose, data would arrive in order but much faster and the subsequent logic basing on the timed window would not be correct My question: - Ideal solution for me is to change the Siddi time using timestamp of arriving time series event. Is that possible to do so? - If not, what's suggestion to fix this issue.

from fooStream#window.timeBatch(10 sec)
select count() as count
insert into barStream;

Solution

  • You can use the externalTimeWindow[1] as previously mentioned. However, what you are looking for is playback [2].

    In Siddhi, internally there are two TimestampGenerators. Namely EventTimeBasedMillisTimestampGenerator and SystemCurrentTimeMillisTimestampGenerator. By default SystemCurrentTimeMillisTimestampGenerator will be used with the Siddhi CEP engine. But, if you use playback annotation, it'll change to EventTimeBasedMillisTimestampGenerator. If you use this, Siddhi will use the timestamp of arriving time series event as the CEP engines time.

    [1] https://wso2.github.io/siddhi/api/latest/#externaltime-window

    [2] https://wso2.github.io/siddhi/documentation/siddhi-4.0/#appplayback

    [3] https://github.com/wso2/siddhi/blob/master/modules/siddhi-core/src/test/java/org/wso2/siddhi/core/managment/PlaybackTestCase.java