2

Anybody can give me a example about how to use window.frequent? For example, I write a test,

"define stream cseEventStream (symbol string, price float, time long);" +
"" +
"@info(name = 'query1') " +
"from cseEventStream[700 > price]#window.frequent(3, symbol) " +
"select symbol, price, time " +
"insert expired events into outputStream;";

But from the outputStream, i can't find out the rule.

Thanks.

Community
  • 1
  • 1
fxjwind
  • 31
  • 3

2 Answers2

1

For every event which has a price > 700, this window will retain most frequent 3 items based on symbol and since the output type is 'expired events' you will only receive output once an event loose it's position as a frequent event.

Ex: for frequent window of size 2

Input

WSO2   1000    1
WSO2   1000    2
ABC     700    3
XYZ     800    4

Output

ABC     700    3

ABC event was in the frequent window and was expired upon receiving of XYZ event. If you use default output which is 'current events' it will output all incoming events which are selected as frequent events and put into the window.

Implementation is based on Misra-Gries counting algorithm.

Documentation : https://docs.wso2.com/display/CEP400/Inbuilt+Windows#InbuiltWindows-frequent
Test cases : https://github.com/wso2/siddhi/blob/master/modules/siddhi-core/src/test/java/org/wso2/siddhi/core/query/window/FrequentWindowTestCase.java

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Tishan
  • 890
  • 6
  • 11
  • Thanks. I tested test case and have understood this processor. But my confusing is: From "current events", we can get all incoming events; From "expired events", we can get expired, namely less frequent events; How can get the top frequent events? I think that top frequent events are we wanted – fxjwind Nov 25 '15 at 03:36
  • From "current events" you will always receive top n frequent events only for a frequent window of size n. But you will not receive all n events like a list, rather one by one in their input order. For above you will receive {WSO2 , 1000 , 1 ; WSO2 , 1000 , 2 ; ABC , 700 , 3 ; XYZ , 800 , 4} as current events one after another. ABC is their because before you receive XYZ, ABC is an eligible candidate to frequent window. Then upon XYZ arriving ABC would be emitted as expired and XYZ as current. If new event arrives which is not eligible for frequent n then it will be dropped. – Tishan Nov 26 '15 at 05:34
1

In this particular query 'window.frequent(3, symbol)' will make the query to find the most frequent 3 symbols(or 3 symbols that has the highest number of occurrences). But, when you insert events to outputStream you have inserted only expired events. So that, as the end result this query will output events that are expired from the frequent window.

In a frequent window, expired events are events that are not belonging to a frequent group anymore. In this case events which are the symbol is not among 3 symbols that has the highest number of occurrences.

for an example if you send the following sequence of events,

{"symbolA", 71.36f, 100}
{"symbolB", 72.36f, 100}
{"symbolB", 74.36f, 100}
{"symbolC", 73.36f, 100}
{"symbolC", 76.36f, 100}
{"symbolD", 76.36f, 100}
{"symbolD", 76.36f, 100}

The query will output {"symbolA", 71.36f, 100}.

When you send the events with 'symbolD'. SymbolA will not be among the top3 symbols with highest number of occurrences anymore so that event with symbolA is expired and {"symbolA", 71.36f, 100} is emitted.

Sajith Eshan
  • 696
  • 4
  • 17