Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Table of Contents
maxLevel3

What is the PEL?

The Pipeline Expression Language (PEL) or just PE (Pipeline Expression) is an expression language that can optionally be used inside a pipeline to do data mapping and to dynamically calculate, set and change values at processing time of the pipeline. This gives you a huge flexibility in your pipeline.

...

Output:

Code Block
Counter: 1

Operators

The PEL supports all common operators as also known for most programming languages. It is similar to the expressions in Microsoft Excel, although the syntax is slightly different and aligned a bit more with the traditional programming syntax.

Relational operators

Is equal (==)

Example 1

Code Block
pipeline:
  - log:
      message: "#{2 == 1}"

Output:

Code Block
false

Is not equal (!=)

Example 1

Code Block
pipeline:
  - log:
      message: "#{2 != 1}"

Output:

Code Block
true

Less than (<)

Example 1

Code Block
pipeline:
  - log:
      message: "#{1 < 5}"

Output:

Code Block
true

Example 2

Code Block
pipeline:
  - log:
      message: "#{0.5 < 1}"

Output:

Code Block
true

Less or equal than (<=)

Example 1

Code Block
pipeline:
  - log:
      message: "#{1 <= 5}"

Output:

Code Block
true

Greater than (>)

Example 1

Code Block
pipeline:
  - log:
      message: "#{1 > 5}"

Output:

Code Block
false

Greater or equal than (>=)

Example 1

Code Block
pipeline:
  - log:
      message: "#{5 >= 5}"

Output:

Code Block
true

Detect alphabetical order with <, >, <=, >=

Example 1

Code Block
pipeline:
  - log:
      message: "#{'Adam' < 'Zacharias'}"

Output:

Code Block
true

Regular expression matching (matches)

Example 1

Code Block
pipeline:
  - log:
      message: "#{'5.0067' matches '^-?\\d+(\\.\\d{2})?$'}"

Output:

Code Block
false

Logical operators

and

Example 1

Code Block
pipeline:
  - log:
      message: "#{true and false}"

Output:

Code Block
false

or

Example 1

Code Block
pipeline:
  - log:
      message: "#{true or false}"

Output:

Code Block
true

not (!)

Example 1

Code Block
pipeline:
  - log:
      message: "#{!true}"

Output:

Code Block
false

Mathematical operators

Addition and subtraction

Example 1 - Addition

Code Block
pipeline:
  - log:
      message: "#{1 + 1}"

Output:

Code Block
2

Example 2 - Subtraction

Code Block
pipeline:
  - log:
      message: "#{10 - 1}"

Output:

Code Block
9

Example 3 - Addition an subtraction

Code Block
pipeline:
  - log:
      message: "#{25 - 5 + 10}"

Output:

Code Block
30

Example 4 - String concatenation

Code Block
pipeline:
  - log:
      message: "#{'Hello ' + 'World!'}"

Output:

Code Block
Hello World!

Multiplication and division

Example 1 - Multiplication

Code Block
pipeline:
  - log:
      message: "#{3 * 5}"

Output:

Code Block
15

Example 2 - Negative multiplication

Code Block
pipeline:
  - log:
      message: "#{-1 * 5}"

Output:

Code Block
-5

Example 3 - Division

Code Block
pipeline:
  - log:
      message: "#{20 / 5}"

Output:

Code Block
4

Example 4 - Modulus

Code Block
pipeline:
  - log:
      message: "#{7 % 4}"

Output:

Code Block
3

Example 5 - Operator precedence

Code Block
pipeline:
  - log:
      message: "#{5 + 4 - 1 * 2}"

Output:

Code Block
7

Example 6 - Brackets

Code Block
pipeline:
  - log:
      message: "#{(5 + 4 - 1) * 2}"

Output:

Code Block
16

Assignment

Example 1

Code Block
pipeline:
  - set:
      value: "1"
      output: "#{vars.counter}"
  - log:
      message: "#{vars.counter}"

Output:

Code Block
1

Example 2

Code Block
vars:
  counter: 12
pipeline:
  - set:
      value: "#{vars.counter + 1}"
      output: "#{vars.counter}"
  - log:
      message: "#{vars.counter}"

Output:

Code Block
13

Working with lists and maps / dictionaries

Creating a new list

Example 1 - A new empty list

Code Block
vars:
  numbers: "#{{}}"
pipeline:
  - log:
      message: "#{vars.numbers}"

Output:

Code Block
[]

Example 2 - A new list with default content

Code Block
languageyaml
vars:
  numbers: "#{{1, 2, 4}}"
pipeline:
  - log:
      message: "#{vars.numbers}"

Output:

Code Block
[1, 2, 4]

Example 3 - A new, nested list

Code Block
languageyaml
vars:
  scores: "#{{ {1, 3}, {5, 8} }}"
pipeline:
  - log:
      message: "#{vars.scores}"

...

Code Block
[[1, 3], [5, 8]]

Accessing lists and arrays

Example 1

Code Block
languageyaml
vars:
  numbers: "#{{1, 2, 4}}"
pipeline:
  - log:
      message: "#{vars.numbers[1]}"

Output:

Code Block
2

Creating a new map / dictionary

Example 1 - A new empty map

Code Block
vars:
  persons: "#{ {:} }"
pipeline:
  - log:
      message: "#{vars.persons}"

Output:

Code Block
{}

Example 2 - A new map with default values

Code Block
vars:
  persons: "#{ {hanna:'burger', max:'hotdog', julie:'salad'} }"
pipeline:
  - log:
      message: "#{vars.persons}"

...

Code Block
{hanna=burger, max=hotdog, julie=salad}

Example 3 - A new map with later binding

Code Block
vars:
  persons: "#{ {:} }"
pipeline:
  - log:
      message: "#{vars.persons['Hanna'] = 23}"

Output:

Code Block
{Hanna=23}

Accessing maps/dictionaries

Example 1

Code Block
vars:
  persons: "#{ {hanna:'burger', max:'hotdog', julie:'salad'} }"
pipeline:
  - log:
      message: "#{vars.persons['max']}"

Output:

Code Block
hotdog

Navigating objects

A PE can point to values inside an object (or nested data structure), like this JSON for example:

...

Code Block
#{person.hobbies[0]}

Example 1

In this more advanced example, there are different things to mention:

...

Code Block
Name:  Bart Simpson
Age:   12
Hobby: skateboard

Selection Expression

With the selection syntax you can select a subset of items from a given collection to be returned as new collection by specifying a selection expression.

...

Whereas collectionName is the variable name of the collection (can be an array, map, list, aso.) and selectionExpression is the expression which selects the items to be returned from the list.

Example 1

Lets assume we have a collection of entities like this stored in the body:

...

Code Block
vars: 
   data: '#{{
        {
          person: {
            name: "Bart Simpson",
            age: 12,
            hobbies: {
              "skateboard",
              "tv",
              "pranks"
            }
          }
        },
        {
          person: {
            name: "Maggie Simpson",
            age: 1,
            hobbies: {
              "drinking milk",
              "crawling",
              "crying"
            }
          }
        }
      }}'
pipeline:
  - log:
      message: "#{vars.data.?[person.name == 'Maggie Simpson']}"

Projection Expression

With the projection syntax you can select specific property values out from a collection of objects.

...

Whereas collectionName is the variable name of the collection (can be an array, map, list, aso.) and projectionExpression is the expression which selects the properties to be returned from each object in the list.

Example 1

Lets assume we have a collection of entities like this stored in the body:

...

Code Block
vars: 
   data: '#{{
        {
          person: {
            name: "Bart Simpson",
            age: 12,
            hobbies: {
              "skateboard",
              "tv",
              "pranks"
            }
          }
        },
        {
          person: {
            name: "Maggie Simpson",
            age: 1,
            hobbies: {
              "drinking milk",
              "crawling",
              "crying"
            }
          }
        }
      }}'
pipeline:
  - log:
      message: "#{vars.data.![person.name]}"

PEL Utils

Inside a PE you can use built-in Utils as helpers to simplify work.

A refecerence about available PEL Utils can be found in this section: PEL Utils Reference.

Example 1

Code Block
vars:
  cities: "Munich, Bratislava, New York"
pipeline:
  - log: 
      message: "#{@list.size(vars.cities)}"

Output:

Code Block
3

Example 2

Code Block
pipeline:
  - log: 
      message: "#{@text.lang('Hallo, Herr Meier!')}"

...