espernesper

Why wont this context work?


I want the same statement to select between the times specified in the two contexts below. However I get no output. How can I get output when B is active and C is active using nested contexts in a single statement?

create context A
    context B start (0, 12, *, *, *) end (0, 18, *, *, *),
    context C start (0, 20, *, *, *) end (0, 23, *, *, *);

Statement:

context A select * from MyEvent;

Solution

  • This is because nested context are not an OR relationship. For OR use a pattern like at the end of this example.

    Assume event types AStart, AEnd, BStart, BEnd and C.

    create context CtxSampleNestedContext
      context SpanA start AStart end AEnd,
      context SpanB start BStart end BEnd;
    
    context CtxSampleNestedContext select count(*) from C;
    

    After creating the EPL statements above, the engine starts looking for an AStart event only and does not yet look for AEnd, BStart, BEnd or C events.

    Assume that an AStart event arrives next:

    In the scenario, assume that a BStart event arrives. This is, logically, the beginning of the SpanB lifecycle:

    In the scenario, assume that a BEnd event arrives. This is, logically, the end of the SpanB lifecycle:

    In the scenario, assume that an AEnd event arrives. This is, logically, the end of the SpanA lifecycle:

    In the scenario describe above, after the AEnd arrives, the engine is back to the same state as the engine had after the statements were created originally.

    If your use case calls for a logical OR relationships like for example so (not equivalent to above):

    create context CtxSampleNestedContext 
      start pattern[every a=AStart or every a=BStart] as mypattern 
      end pattern[every AEnd or every BEnd]