I create a table that store the latest financial ticks, I would like to atomically select and calculate some ticks that meeting certain conditions immediately after updating the tick table.
Is there any method in Esper can achieve this requirement?
Thanks to user650839. I wrote a demo following his instruction. The demo uses named window instead of table.
Here defines the financial tick event:
public class Tick {
private String symbol;
private double bid;
private double ask;
private String datetime;
// Constructor
......
// getter / setter
......
}
Here shows the EPL statements that update and select from the named window atomically:
// create the named window
create window tickWin#unique(symbol) as select * from Tick
// on-merge clause
on Tick as nt
merge tickWin as wt
where wt.symbol = nt.symbol
when not matched
then insert select *
when matched
then update set wt.bid = nt.bid, wt.ask = nt.ask, wt.datetime = nt.datetime
then insert into UpdatedTick select *
// the output stream
select * from UpdatedTick
Here shows the listener, add this listener to the output stream mentioned above, simply print out the updated tick event.
public class TickListener implements UpdateListener {
@Override
public void update(EventBean[] newEvents, EventBean[] oldEvents) {
if (newEvents == null || newEvents.length ==0) return;
System.out.println(newEvents[0]);
}
}