Apama 10.15.0 | Developing Apama Applications | Developing Apama Applications in EPL | Working with Streams and Stream Queries | Using dynamic expressions in stream queries | Ordering and side effects in stream queries
 
Ordering and side effects in stream queries
To determine when it is safe to use dynamic expressions in stream queries, it is important to understand that:
*In a query, the order in which the correlator executes the action calls is not defined. Although the order is not defined, the correlator always executes the action calls in the same order for a particular Apama release.
*When processing each item passed to the query, if an action call with a given set of arguments appears multiple times within a stream query, then the number of times the correlator executes the action is not specified. It might be equal to or less than the number of times that the action call appears within the query. However, this number is always the same for a particular release.
*In a stream network, the order in which the correlator executes the queries is not defined except for when the output of a query forms the input to a second query. In this case, the correlator always executes the first query before the second. Again, in a particular release, the execution order is always the same.
Because of these points, it is best to avoid actions with side effects in expressions executed in stream queries. Such actions can make a program more difficult to understand and debug. Instead, execute any such actions in stream listeners.
A method or expression that produces a value has a side effect if it modifies something or interacts with something outside the program. This includes, but is not limited to:
*Modifying a global variable
*Changing the value of an argument
*Calling plug-in methods
*Routing, enqueuing, emitting or sending an event
*Calling another action that has side effects
*Setting up event listeners or new streams