Deletes a row at a particular location (specified by index) in the event cache.
deleteCache (cacheName, index)
index | Row index in the event cache as an integer. |
Deletes a row at a particular location (specifed by the index) in the event cache. This index is 0 based. The function takes an integer as its argument, and the function removes the row. The function does not produce an output. Specifying of an invalid index parameter will result in the generation of a bad record.
This example obtains the top 3 distinct prices per trading symbol. In order to accomplish this task, the example makes use of the getCache(), cacheSize() and deleteCache() functions.
CREATE SCHEMA TradesSchema ( Id integer, TradeTime date, Venue string, Symbol string, Price float, Shares integer ) ; CREATE INPUT WINDOW QTrades SCHEMA TradesSchema PRIMARY KEY (Id) ; CREATE FLEX flexOp IN QTrades OUT OUTPUT WINDOW QTradesStats SCHEMA TradesSchema PRIMARY KEY(Symbol,Price) BEGIN DECLARE typedef [integer Id;| date TradeTime; string Venue; string Symbol; float Price; integer Shares] QTradesRecType; eventCache(QTrades[Symbol], manual, Price asc) tradesCache; typeof(QTrades) insertIntoCache( typeof(QTrades) qTrades ) { integer counter := 0; typeof (QTrades) rec; long cacheSz := cacheSize(tradesCache); while (counter < cacheSz) { rec := getCache( tradesCache, counter ); if( round(rec.Price,2) = round(qTrades.Price,2) ) { deleteCache(tradesCache, counter); insertCache( tradesCache, qTrades ); return rec; break; } else if( qTrades.Price < rec.Price) { break; } counter++; } if(cacheSz < 3) { insertCache(tradesCache, qTrades); return qTrades; } else { rec := getCache(tradesCache, 0); deleteCache(tradesCache, 0); insertCache(tradesCache, qTrades); return rec; } return null; } END; ON QTrades { keyCache( tradesCache, [Symbol=QTrades.Symbol;|] ); typeof(QTrades) rec := insertIntoCache( QTrades ); if(rec.Id) { if(rec.Id <> QTrades.Id) { output setOpcode(rec, delete); } output setOpcode(QTrades, upsert); } }; END;