This documentation is for WSO2 CEP 3.0.0. View the home page of the latest release.

Unknown macro: {next_previous_link3}
Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 3 Current »

from <stream-name> {<conditions>}
select ( {<attribute-name>}| ‘*’|)
insert into <stream-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]
select symbol,volume
insert into StockQuote

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]
select symbol, volume, price
insert into StockQuote

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]
select symbol,price
insert into StockQuote 

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']
select symbol,price
insert into StockQuote

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]
select symbol,volume
insert into StockQuote  

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]
select symbol, volume
insert into StockQuote   

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')]
select symbol, volume

insert into StockQuote

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.

  • No labels