Filters
from <stream-name> {<conditions>}
insert into <stream-name> ( {<attribute-name>}| ‘*’|)
Filter query creates an output stream and inserts any events from the input stream that satisfies the conditions defined with the filters to the output stream.
Filters support following types of conditions
1. >, <, = , <=, <=, !=
2. contains, instanceof
3. and, or, not
Following example shows sample queries for filters.
Stream defined by "define stream StockExchangeStream (symbol string, price int, volume float );" is used in below queries.
>, <, = , <=, <=, !=
From all events of the StockExchangeStream stream, output only the events having price >= 20 and price < 100 to the StockQuote stream, where the output event will only have symbol and volume as its attributes.
from StockExchangeStream[price >= 20 and price < 100]
insert into StockQuote symbol, volume
Here we are only projecting ‘symbol’ and ‘volume’ as the output of the query, and hence the output stream ‘StockQuote’ will only contain ‘symbol’ and ‘volume’ attributes, If the projection is omitted or ‘*’ is used, the query will output all the attributes of input streams.
From all events of the StockExchangeStream stream, output only the events having volume > 100 and price != 100 to the StockQuote stream, where the output event will have symbol, volume and price as its attributes.
from StockExchangeStream[volume > 100 and price!=10]
insert into StockQuote symbol, volume, price
The output stream ‘StockQuote’ will contain ‘symbol’, 'price' and ‘volume’ attribute,
contains, instanceof
From all events of the StockExchangeStream stream, output only the events where symbol is an instance of java.lang.String to the StockQuote stream, where the output event will only have symbol and price as its attributes.
from StockExchangeStream[symbol instanceof 'string']
insert into StockQuote symbol, price
The output stream ‘StockQuote’ will only contain ‘symbol’ and ‘price’ attributes, If the projection is omitted or ‘*’ is used, the query will output all the attributes of input streams.
Other than that we can also use instanceof condition for 'float', 'long' , 'integer', 'double' and 'boolean'.
From all events of the StockExchangeStream stream, output only the events where symbol contains 'ws' to the StockQuote stream, where the output event will only have symbol and price as its attributes.
from StockExchangeStream[symbol contains 'ws']
insert into StockQuote symbol, price
The output stream ‘StockQuote’ will only contain ‘symbol’ and ‘price’ attributes, If the projection is omitted or ‘*’ is used, the query will output all the attributes of input streams.
contains condition can only be applied to strings.
and, or, not
From all events of the StockExchangeStream stream, output only the events having price >= 20 and price < 100 to the StockQuote stream, where the output event will only have symbol and volume as its attributes.
from StockExchangeStream[price >= 20 and price < 100]
insert into StockQuote symbol, volume
Here we are only projecting ‘symbol’ and ‘volume’ as the output of the query, and hence the output stream ‘StockQuote’ will only contain ‘symbol’ and ‘volume’ attribute, If the projection is omitted or ‘*’ is used, the query will output all the attributes of input streams.
From all events of the StockExchangeStream stream, output only the events having price >= 20 or price < 100 to the StockQuote stream, where the output event will only have symbol and price as its attributes.
from StockExchangeStream[price >= 20 or price < 100]
insert into StockQuote symbol, volume
Here we are only projecting ‘symbol’ and ‘volume’ as the output of the query, and hence the output stream ‘StockQuote’ will only contain ‘symbol’ and ‘volume’ attribute, If the projection is omitted or ‘*’ is used, the query will output all the attributes of input streams.
From all events of the StockExchangeStream stream, output only the events where symbol does not contain 'ws' to the StockQuote stream, where the output event will only have symbol and volume as its attributes.
from StockExchangeStream[not (symbol contains 'ws')]
insert into StockQuote symbol, volume
Here we are only projecting ‘symbol’ and ‘volume’ as the output of the query, and hence the output stream ‘StockQuote’ will only contain ‘symbol’ and ‘volume’ attribute, If the projection is omitted or ‘*’ is used, the query will output all the attributes of input streams.