Apama 10.3 | Apama Documentation | Developing Apama Applications | Developing Apama Applications in EPL | Defining Queries | Finding and acting on event patterns | Defining event patterns | Query or operator
Query or operator
In a find statement, you can specify the or operator in the event pattern. The events on one side or the other of the or operator must be matched for the query to fire. The condition on each side of an or operator can be a single event template or a more complex expression.
In the next example, assuming that a FlagAccount event and an OrderPlaced event have already been added to the query's window, adding either a CreditCardAdded or OrderCancelled event to its window causes a match.
FlagAccount as account -> (CreditCardAdded as added or
(OrderPlaced as placed and OrderCancelled as cancelled) )
A pattern normally only matches one side of an or operator, as it matches the most recent events. However, if one event matches both sides of an or operator, then both events may be coassigned.
Optional or-terms
Events on one side of the or operator are not required to be present when matching the pattern. In the example above, the added, placed and cancelled coassignments are not all required to be present. It will match if either an added event, or a placed and canceled event appears in the query's window. These terms are referred to as "or-terms". It is possible for the pattern to match with matching only some of those events, and others are left without an event assigned to them. These or-terms are thus optional rather than definitely having a value matched by the pattern. The following rules apply to or-terms:
*Or-terms can only be used in where clauses (see Query conditions) if the where clause does not make use of or-terms on the opposite side of the or operator in the pattern. In the above example, added is opposite placed and cancelled. Therefore, the following where clauses are not legal:
*where added.cardId = placed.cardId
*where added.cardId = 5 or placed.cardId = 5
(but see the next point for an example of how to express these conditions)
*If one of the where clauses uses or-terms that are not being matched by the pattern, then they are ignored as they cannot be evaluated. For example, only one of the following where clauses is required to match (as it is not possible for both to match):
*where added.cardId = 5
*where placed.cardId = 5
*In the action of the query (see Acting on pattern matches), the type of an or-term is optional<EventType>. The types in the above example are:
Use the ifpresent statement to handle the contents of such events. See Defining conditional logic with the ifpresent statement for further information.
*If using the %send construct (see Adding query send event actions), any or-terms required by the fields of the event should be included in an ifpresent entry of the %send. This uses the ifpresent statement, thus the contents of the or-terms events are available to the send action. When using the Query Send Event Action dialog in Software AG Designer, the ifpresent is automatically filled out.
*If one side of an or term matches and the other side is incomplete, then no or-terms from the incomplete side of the or operator are included in the matched events. Each side of an or operator can either match completely or not at all. In the above example, if a CreditCardAdded event occurs, the OrderPlaced event is discarded, despite being present in the window. Thus, detecting the presence of just the placed or canceled event with ifpresent is sufficient to detect which side of the or has matched.
*Aggregates (see Aggregating event field values) cannot use or-terms.
The or operator has a higher precedence than the and operator, and lower precedence than the followed-by (->) operator. For clarity, use brackets in expressions that specify more than one type of operator.

Copyright © 2013-2018 | Software AG, Darmstadt, Germany and/or Software AG USA, Inc., Reston, VA, USA, and/or its subsidiaries and/or its affiliates and/or their licensors.