Apama 10.15.0 | Developing Apama Applications | Developing Apama Applications in EPL | Defining Queries | Implementing parameterized queries | Referring to parameters in queries
 
Referring to parameters in queries
You can refer to parameters throughout a query definition.
You cannot change parameter values in the query code itself. Parameter values can be modified only by the Scenario Service.
CAUTION: 
Apama recommends that you do not change parameter values used in input filters because it is possible to miss events that would cause a match. In a given parameterization, when an input filter refers to a parameter and you change the value of that parameter, it causes the parameterization to stop and restart. Events sent during the changeover are ignored. Also, there might have been earlier events that match the new parameter value but that did not make it into the window because they did not match the previous parameter value. An alternative is to use a parameter in a where clause in the find statement instead. This can be more efficient when the parameter value needs to be changed frequently. Using parameter values in input filters can also increase memory usage, see Queries can share windows.
Examples of using parameters in queries:
*In retain and within expressions that are in the inputs block:
parameters {
integer maxRetention;
float maxDuration;
}
inputs {
A() key id retain maxRetention;
B() key id with maxDuration;
}
*In the filter of the event template in the inputs block:
parameters {
float threshold;
}
inputs {
Withdrawal(amount > threshold) key k;
}
*In where and within clauses that are in the find pattern:
parameters {
float maxDuration;
float maxDifference;
}
inputs {
A() key id retain 2;
}
find A as a1 -> A as a2 where (a2.cost - a1.cost) >
maxDifference within maxDuration {
...
}
*In wait expression(s) that are in the find pattern:
parameters {
float interval;
}
inputs {
A() key id retain 2;
}
find A as a1 -> wait(interval) as w1 -> A as a2 {
...
}
*In an aggregate expression that is in the find pattern:
parameters {
float avg;
}
inputs {
A() key id within 1 day;
}
find every A as a
select avg(a.cost - avg) as avgDeviation {
...
}
*In an action that is in the find block:
parameters {
float avg;
}
inputs {
A() key id retain 1;
}
find A as a {
log "Deviation from mean = " + (a.value - avg).toString();
}
*In a user-defined action block:
parameters {
float avg;
}
inputs {
A() key id retain 1;
}
find A as a {
log "Deviation from mean = " + getDeviation(a).toString();
}
action getDeviation(A a) returns float {
return (a.value - avg);
}
While parameter values can be used anywhere within the query it is illegal to mutate the parameter values. They can be modified only by the Scenario Service.