esper icon indicating copy to clipboard operation
esper copied to clipboard

output first(n)

Open p00temkin opened this issue 9 years ago • 6 comments

For output suppression Esper allows use of group by output first every

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 ==

p00temkin avatar Apr 23 '15 20:04 p00temkin

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.

bernhardttom2 avatar Apr 23 '15 22:04 bernhardttom2

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.

p00temkin avatar Apr 26 '15 21:04 p00temkin

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());

p00temkin avatar May 04 '15 21:05 p00temkin

Ok that sounds good. The test case seems to no really test much of the new functionality.

bernhardttom avatar May 07 '15 11:05 bernhardttom

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

p00temkin avatar May 29 '15 10:05 p00temkin

This can be solved with contexts. The issue will be closed unless you think it is still relevant.

bernhardttom avatar Oct 15 '20 17:10 bernhardttom