Page tree
Skip to end of metadata
Go to start of metadata

In this tutorial you will learn to write simple queries that filter elements and attributes.

We will use the same setting as in Simple Query Processing. So you should follow steps 1-4.

Selection

With the selection operator you can filter out elements that are not relevant for further processing. Create a new Odysseus Script file with the PQL template and name it query2.

The first example will select only those auction, that are created by the seller with the id 1:

out = SELECT({predicate='seller=1'}, nexmark:auction)

Execute the script and show the output as table. After some time, you should see only auctions opened by the seller with the id 1

In this script you define a SELECT-Operator. In Procedural Query Language (PQL) each operator is identified by a name. Inside the operator there are two parts. The first part is the configuration inbetween "{" and "}". The seconds part is the source part, i.e. here the sources are listed that should deliver the input.

In this example the used source is nexmark:auction (A selection can only filter out elements from one source, so no further sources can be used in a selection). In the configuration area predicate describes the predicate that should be used in the selection. For each incoming event the predicate is evaluated and the event is send to the next operator if the predicate evaluates to true. In other cases the event will be discarded.

If you look at the query plan, you will see, the following

The filter step is done by the top most operator Select.

Now modify the query and change the predicate to 'seller=1 || seller=2'. This meens you are only interested in auctions opened by seller 1 or seller 2.

Remove the old query and execute the new script. The output should look like in the following.

More complex predicates can be defined. See MEP: Functions and Operators for further information.

Project

With the SELECT-Operator you choose which events you will see in the output, with the PROJECT you will choose, which attributes should be in the output.

Create a new Odysseus Script file with the PQL template and name it query3.

out = PROJECT({ATTRIBUTES=['id', 'initialbid', 'seller']},nexmark:auction)

After translating the following output will be displayed. You can see, that only the selected attributes are printed.

Although, the examples only contain one operator, the operators can be connected. E.g. first a selection and than a projection:

selected = SELECT({predicate='seller=1 || seller=2'}, nexmark:auction)
out = PROJECT({ATTRIBUTES=['id', 'initialbid', 'seller']},selected)

Map

PROJECT only allow the selection of attributes. With the MAP-Operator calculations can be done on the input. The simpliest calculation is the output of an input attribute, so Map is more general than Project. (Warning: You should not use Map instead of Project, because it requires more processing capabilties).

Create a new Odysseus Script file with the PQL template and name it query4.

out = MAP({EXPRESSIONS=['id','id+id','dolToEur(initialbid)']},nexmark:auction)

As you can see, the output is the printed expression. Sometimes (especially when the output should be processed by another operator) this names should be more handy. You could use the RENAME Operator or an additional feature of Map. Instead of giving an expression, there can be a pair of expression and output name.

out = MAP({EXPRESSIONS=['id',['id+id','DoubleId'],['dolToEur(initialbid)','Bid €']]},nexmark:auction)


  • No labels