How to get pulsed output in CCL
CCL is designed for real-time processing of streaming data on an event-driven basis – so the output streams out as fast as the input arrives. But there are times when people need to throttle the output for various reasons. The example below does this.
/* This example shows how you can implement pulsed output from a streaming project. Instead of
streaming output in real-time, it will collect new records (or updates) and publish
them on a fixed interval basis (in this example every 10 seconds).
*/
CREATE INPUT STREAM Trades
SCHEMA (TradeId long, Symbol string, Volume long, Price float);
CREATE FLEX DelayedTrades_Flex
IN Trades
OUT OUTPUT STREAM DelayedTrades
SCHEMA (TradeId long, Symbol string, Volume long, Price float)
BEGIN
DECLARE
//Hold the record in a cache till it is time to release it later.
vector(typeof(Trades)) cache;
END;
ON Trades {
//Cache the events for later output.
push_back(cache, Trades);
};
EVERY 10 SECONDS {
//Now output all the records that have been cached in the last 10 seconds
for(rec in cache) {
output rec;
}
//Reset the cache
resize(cache, 0);
};
END;
Thanks for sharing Jeff, Helps a lot!