Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

output first(n) #3

Open
p00temkin opened this issue Apr 23, 2015 · 6 comments
Open

output first(n) #3

p00temkin opened this issue Apr 23, 2015 · 6 comments

Comments

@p00temkin
Copy link

For output suppression Esper allows use of
group by output first every
which gives instant output for the first unique event, and throttles to maximum of 1 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 ==

@bernhardttom2
Copy link
Contributor

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.

@p00temkin
Copy link
Author

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
Copy link
Author

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

@bernhardttom
Copy link
Contributor

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

@p00temkin
Copy link
Author

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

@bernhardttom
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants