Siddhi supports custom codes within queries.
In the current implementation Windows and Aggregators are implemented in a pluggable manner.
Writing a custom Window
To write a custom window you have to create a class in the package "org.wso2.siddhi.core.query.processor.window" with a name <Name>WindowProcessor, and it has to extend "org.wso2.siddhi.core.query.processor.window.WindowProcessor".
You need to compile that class and add the jar to the class path. (In WSO2 CEP add that to the CEP_HOME/repertory/components/lib)
E.g for creating firstUnique window you class name need to be FirstUniqueWindowProcessor.
You can use your class in the query as follows
from StockExchangeStream[price >= 20]#window.firstUnique(50)
insert into StockQuote symbol, price
Writing a custom Aggregator
To write a custom aggregator you have to create a class in the package "org.wso2.siddhi.core.query.projector.attibute.processor" with a name <Name>AggregateAttributeProcessor, and it has to extend "org.wso2.siddhi.core.query.projector.attibute.processor.AbstractAggregateAttributeProcessor". This will work as the base class for aggregator creation.
Then you also need to create appropriate runtime aggregators implementing "org.wso2.siddhi.core.query.projector.attibute.aggregator.Aggregator" which will be specific for attribute types, such as STRING, INT, LONG, FLOAT, DOUBLE & BOOL.
You need to compile these classes and add the jars to the class path. (In WSO2 CEP add them to the CEP_HOME/repertory/components/lib)
E.g for creating std Aggregator you need to create a class with name StdAggregateAttributeProcessor, and some appropriate Aggregators.
You can use your class in the query as follows
from StockExchangeStream[price >= 20]#window.length(50)
insert into StockQuote symbol, std(price) as stdPrice