0

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;
carva
  • 35
  • 7

1 Answers1

1

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:

  • The engine stops looking for an AStart event.
  • The engine starts looking for an AEnd event, since that would mean the end of the current SpanA lifecycle.
  • The engine starts looking for a BStart event, in order to detect the beginning of a SpanB lifecycle.

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

  • The engine stops looking for further BStart events.
  • The engine starts looking for a BEnd event, since that would mean the end of the current SpanB lifecycle.
  • The engine keeps looking for an AEnd event, since that would mean the end of the current SpanA lifecycle.
  • The engine starts looking for C events and now starts counting each C that arrives.

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

  • The engine stops looking for a BEnd event.
  • The engine stops looking for C events and stops counting each.
  • The engine starts looking for a BStart event, since that would mean the beginning of another SpanB lifecycle.

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

  • The engine stops looking for an AEnd event.
  • The engine stops looking for a BStart event.
  • The engine starts looking for an AStart event, since that would mean the beginning of another 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]
user650839
  • 2,594
  • 1
  • 13
  • 9
  • could you provide an example where the timer:at is used in the context using the OR operator? – carva Apr 23 '17 at 19:53
  • ... pattern[every timer:at(0, 12, *, *, *) or every timer:at (0, 18, *, *, *) ].. would work, as would ... pattern[every timer:at(0, [12, 18], *, *, *)] – user650839 Apr 24 '17 at 03:16
  • How about the end condition? ___start pattern[every timer:at(0, 12, *, *, *) or every timer:at (0, 18, *, *, *) ] end pattern[ every timer:at(0, 20, *, *, *) or every timer:at(0, 23, *, *, *)]; ___ is this correct? – carva Apr 24 '17 at 15:01
  • It does seem to work on my test data, however its not easy to tell since the timestamps have varying span – carva Apr 24 '17 at 15:18