0

I'm new to Esper and I'm trying to get the results of multiple EPStatements to run through the same UpdateListener. For instance:

EPServiceProvider epService = EPServiceProviderManager.getDefaultProvider();
EPStatement avgStatement = epService.getEPAdministrator()
                        .createEPL("select avg(price) from OrderEvent.win:time(30 sec)");
EPStatement sumStatement = epService.getEPAdministrator()
                        .createEPL("select sum(price) from OrderEvent.win:time(60 sec)");

Is it possible to combine the results of both of those EPStatements into a separate statement? Something like:

EPStatement bothStatements = epService.getEPAdministrator()
                            .createEPL("select * from avg(price), sum(price) where a.id=b.id");
bothStatements.addListener(listener);

I tried using inserting both statements into an Esper Named Window, but it seems like I can't do something like this where:

  • Event = (id, itemName, price)
  • Statement1 = (id, avg)
  • Statement2 = (id, sum)
  • Named Window = (id, avg, sum)

I would like to be able to combine the results of multiple statements and get a set of results (per event) into a single output stream.

Thanks for helping.

1 Answers1

0

Did you consider that the same listener can be attached to two statements. What I means is "avgStatement.addListener(myListener)" and "sumStatement.addListener(myListener)".

As an alternative you can use insert-into to populate the same stream. The would be like "insert into MyStream select avg(price) as avgPrice, 0 as sumPrice from ..." and "insert into MyStream select 0 as avgprice, sum(price) as sumPrice from ...".

There is also the concept of a variant stream like variant types in visual basic. This lets you insert anything into a stream that is variant stream because variant streams don't need to be strongly typed.

user3613754
  • 816
  • 1
  • 5
  • 5
  • I've tried the first way using one listener for both statements, but it looks like I still receive two separate output events for each individual statement. I would like to be able to have my listener receive only a single output event per input event. (Order event enters, then both statements execute, then listener receives single output event with both results.) I haven't tried the insert-into or variant stream methods yet. I will report back when I get the chance to. –  Mar 08 '15 at 17:34
  • Another way is to use subqueries. – user3613754 Mar 09 '15 at 14:33