Apama 10.3 | Apama Documentation | Developing Apama Applications | Developing Apama Applications in EPL | Working with Streams and Stream Queries | Defining stream queries | Linking stream queries together
 
Linking stream queries together
A stream query definition is an expression and its result is a stream. Consequently, with one exception described below, you can use a stream query definition anywhere that you can use a stream value. For example, you can assign the resulting value to a stream variable:
stream <float> values := from a in sA select a.value;
Alternatively, you can use a stream query definition as the return value from an action. For example:
action createPriceStream (stream<Tick> ticks) returns stream<float> {
return from t in ticks select t.price;
}
Another option is to embed a stream query within another stream query. For example:
from p in (from t in ticks where t.price > threshold select t.price)
within period
select wavg(t.price,t.volume) as vwap {
   processVwap(vwap);
}
You can use stream variables to link stream queries together, as detailed in the next section.
The exception is that you cannot use a stream query immediately after the from keyword in the first form of the from statement. For example, the following is not a valid statement:
from from t in ticks select t.price as tickPrice {
   print tickPrice.toString();
}
Instead, use the second form of the from statement and specify a stream variable or a stream source template. The following example specifies a stream variable:
from t in ticks select t.price as tickPrice{
   print tick.price.toString();
}
For more information on the different forms of the from statement, see Using output from streams.

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.