0

Let's say that I have a simple object:

public class StockTick{
    private String symbol;
    private decimal price;
    private Date date;
    private int unixTimestamp
}

How should I modify following query to use StockTick.date or StockTick.unixTimestamp to agregate within .win:time() window?

select avg(price) from StockTick.win:time(30 sec) where symbol='IBM'
Vojtech B
  • 2,837
  • 7
  • 31
  • 59

1 Answers1

1

If events are already ordered by unix timestamp, you don't need to modify the query. Just do this for each event:

runtime.sendEvent(new CurrentTimeEvent(unixTimestamp));
runtime.sendEvent(stockTickEvent);

This above code uses the external time so disable the default internal system time. For completely unordered or unstaged events, don't use a time window at all and instead think about how a group-by would look like.

user650839
  • 2,594
  • 1
  • 13
  • 9
  • Is there some recommedned approach when working in multithreaded environment? This doesn't seem quite atomic – Vojtech B Mar 06 '15 at 21:29
  • Also what would happen if this approach would be used to unordered items? – Vojtech B Mar 06 '15 at 21:31
  • Time always moves forward. The query would be different and would probably use group-by for unordered. For multithreaded we have used one thread that moves time forward and multiple threads to send events that don't send time. – user650839 Mar 06 '15 at 21:55
  • Unordered events can also be staged and reordered of course. – user650839 Mar 06 '15 at 22:18
  • Just a quick note that CurrentTimeEvent "jumps" forward (skipping any times in between), while CurrentTimeSpanEvent kind of rolls the time forward. A statement with "output every 5 seconds" for example will not produce the intermediate events with TimeEvent, but will do so with TimeSpanEvent. – xpa1492 Mar 19 '15 at 08:54