esper
esper copied to clipboard
output first(n)
For output suppression Esper allows use of
group by
Issue created to support first(n), to allow more than 1 instant output every
TestEvent with two properties (id1,id2): == event feed == insertEvent A1 = TestEvent("A","1") incrementTimeBy(1 sec) insertEvent A2 = TestEvent("A","2") incrementTimeBy(1 sec) insertEvent A3 = TestEvent("A","3") incrementTimeBy(1 sec)
insertEvent B1 = TestEvent("B","1") incrementTimeBy(1 sec) insertEvent B2 = TestEvent("B","2") incrementTimeBy(1 sec) insertEvent B3 = TestEvent("B","3") incrementTimeBy(1 hour)
insertEvent A4 = TestEvent("A","4") incrementTimeBy(1 sec) insertEvent B4 = TestEvent("B","4") incrementTimeBy(1 hour) == event feed end ==
The statement "select * from TestEvent() group by id1 output first every 1 hour"
results in == begin == TEST_Listener - 0 seconds later, listener called with 1 event(s) TEST_Listener - * A1 TEST_Listener - 3 seconds later, listener called with 1 event(s) TEST_Listener - * B1 TEST_Listener - 3605 seconds later, listener called with 1 event(s) TEST_Listener - * A4 TEST_Listener - 3606 seconds later, listener called with 1 event(s) TEST_Listener - * B4 == end ==
i.e an instant listener call to the for the first event for each id1 groupby.
Would like to add support for the statement "select * from TestEvent() group by id1 output first(2) every 1 hour"
which should result in == begin == TEST_Listener - 0 seconds later, listener called with 1 event(s) TEST_Listener - * A1 TEST_Listener - 1 seconds later, listener called with 1 event(s) TEST_Listener - * A2 TEST_Listener - 3 seconds later, listener called with 1 event(s) TEST_Listener - * B1 TEST_Listener - 4 seconds later, listener called with 1 event(s) TEST_Listener - * B2 TEST_Listener - 3605 seconds later, listener called with 1 event(s) TEST_Listener - * A4 TEST_Listener - 3606 seconds later, listener called with 1 event(s) TEST_Listener - * B4 == end ==
We'd recommend to write a regression test that tests this example. The regression test will fail, at first, because the EPL grammar need to change. Then go ahead and change the grammar and statement object model and retest. The test should then fail because the new functionality is not implemented yet. We can provide guidance where to implement the new functionality.
Thanks, yes I will look at the existing test classes (TestOutputLimit*) in src/test/java/com/espertech/esper/regression/view/ and add a similar regression test.
Initial changes outlined below, please let me know if you have any comments/feedback:
- testcase addition com.espertech.esper.regression.view/TestOutputLimitFirstN.java
- EsperEPL2Grammar.g update, added optional number (n) after 'first' statement
- antlrtool.sh run, numbercontext added to generated EsperEPL2GrammarParser.OutputLimitContext
- com.espertech.esper.epl.spec.OutputLimitSpec, added property rateN
- grab numbercontext in ASTOutputLimitHelper.buildOutputLimitSpec() as ctx.n, add to returned OutputLimitSpec
- extend OutputConditionPolledTime with property nCounter and rateN
- update OutputConditionPolledTime.updateOutputCondition() to return true if nCounter > 0 within interval, add reset
The testcase: (fails without the above changes)
String[] fields = "theString,intPrimitive".split(",");
String epl = "select * from SupportBean\n" +
" group by theString\n" +
" output first 2 every 10 seconds";
EPStatement stmt = epService.getEPAdministrator().createEPL(epl);
SupportUpdateListener listener = new SupportUpdateListener();
stmt.addListener(listener);
epService.getEPRuntime().sendEvent(new SupportBean("E1", 1));
EPAssertionUtil.assertProps(listener.assertOneGetNewAndReset(), fields, new Object[] {"E1", 1});
epService.getEPRuntime().sendEvent(new SupportBean("E1", 2));
EPAssertionUtil.assertProps(listener.assertOneGetNewAndReset(), fields, new Object[] {"E1", 2});
epService.getEPRuntime().sendEvent(new SupportBean("E1", 3));
assertFalse(listener.isInvoked());
Ok that sounds good. The test case seems to no really test much of the new functionality.
Hi Thomas, yes this was just a first testcase to get started. Will create more coverage as I get to know the esper codebase in more detail. Thanks again for the feedback
This can be solved with contexts. The issue will be closed unless you think it is still relevant.