Apama Documentation : Developing Apama Applications : EPL Streams: A Quick Tour : Common stream query patterns : Joining an event with a previous event
Joining an event with a previous event
Another use case that is reasonably common is where an item output from a stream query needs to be compared to the previous output item. For example, suppose you need to detect for a given sensor when the average temperature value was below a threshold value but now is above the threshold value.
01. using com.apama.aggregates.mean;
02. event Temperature { string sensorId; float temperature; }
03. monitor DetectBreach {
04. action onload() {
05. stream<float> temperatures := all Temperature(sensorId="S001");
06. stream<boolean> current := from t in temperatures within 60.0
07. select mean(t.temperatures) > 97.0;
08. stream<boolean> previous := from c in current
09. retain 1 select rstream c;
10. string text;
11. from c in current from p in previous where c and not p
12. select "Temperature breach" : text {
13. print text;
14. }
15. }
16. }
Copyright © 2013-2016 Software AG, Darmstadt, Germany.

Product LogoContact Support   |   Community   |   Feedback