Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Excerpt
hiddentrue

Siddhi windows in wiki format

...

A sliding window that keeps last N events.

From the events having price >= 20 of the StockExchangeStream stream, output the expiring events of the length window to the StockQuote stream. Here the output events will have symbol and the per symbol average price as their attributes, only if the  per symbol average price > 50.

from StockExchangeStream[price >= 20]#window.length(50) 
insert expired-events into StockQuote symbol, avg(price) as avgPrice
group by symbol
having avgPrice>50

...

A sliding window that keeps events arrived within the last T time period.

From the events having symbol == 20 of the StockExchangeStream stream, output the both the newly arriving and expiring events of the time window to the IBMStockQuote stream. Here the output events will have maximum, average and minimum prices that has arrived within last minute as their attributes.

from StockExchangeStream[symbol == 'IBM']#window.time(60000) 
insert all-events into IBMStockQuote max(price) as maxPrice, avg(price) as avgPrice, min(price) as minPrice

...

A time window that processes events in batches. This in a loop collects the incoming events arrived within last T time period and outputs them as a batch.

From the events of the StockExchangeStream stream, output the events per every 2 minutes from the timeBatch window to the StockQuote stream. Here the output events will have symbol and the per symbol sum of volume for last 2 minutes as their attributes.

from StockExchangeStream#window.timeBatch(120000) 
insert into StockQuote symbol, sum(volume) as totalVolume
group by symbol

...

A length window that outputs events as a batch only at the nth event arrival.

From the events having price >= 20 of the StockExchangeStream stream, output the expiring events of the lengthBatch window to the StockQuote stream. Here the output events will have symbol and the per symbol average price> 50 as their attributes.

from StockExchangeStream[price >= 20]#window.lengthBatch(50) 
insert expired-events into StockQuote symbol, avg(price) as avgPrice
group by symbol
having avgPrice>50

Supported units for time windows

The following units are supported when specifying the time for a time window.

UnitSyntax
Yearyear | years
Monthmonth | months
Weekweek | weeks
Dayday | days
Hourhour | hours
Minutesminute | minutes | min
Secondssecond | seconds | sec
Millisecondsmillisecond | milliseconds

Note that each unit supports both the singular and plural format (e.g. second, seconds) and some units have a shortened form (i.e. sec, min).

Following examples use different formats available for 'minutes'.

from StockExchangeStream[symbol == 'WSO2']#window.time( 1 minute ) 
select max(price) as maxPrice, avg(price) as avgPrice, min(price) as minPrice
insert into WSO2StockQuote for all-events  

from StockExchangeStream[symbol == 'FBX']#window.timeBatch( 5 minutes ) 
select max(price) as maxPrice, avg(price) as avgPrice, volume
insert into FBStockQuote

from StockExchangeStream[symbol == 'FBX']#window.timeBatch( 5 min ) 
select max(price) as maxPrice, avg(price) as avgPrice, volume
insert into FBStockQuote