Field expressions (also known as “fexes”) are a way to select fields of a record. They also allow you to do certain transformations on the selected fields, such as changing their names.
A FEX comprises a sequence of elements separated by commas:
ELEM_1,ELEM_2,...,ELEM_N
Each element makes a reference to one or more fields in a record identified by a given name and an optional subscript:
Field_Name[min-max]
min and max are zero-based indexes. It is possible to refer to a field occupying a given position. For example, consider the following record:
Name: Mr. Foo Email: foo@foo.com Email: foo@foo.org Email: mr.foo@foo.org
We would select all the emails of the record with:
The first email with:
Email[0]
The third email with:
Email[2]
The second and the third email with:
Email[1-2]
And so on. It is possible to select the same field (or range of fields) more than once just by repeating them in a field expression. Thus, the field expression:
Email[0],Name,Email
will print the first email, the name, and then all the email fields including the first one.
It is possible to include a rewrite rule in an element of a field expression, which specifies an alias for the selected fields:
Field_Name[min-max]:Alias
For example, the following field expression specifies an alias for the
fields named Email
in a record:
Name,Email:ElectronicMail
Since the rewrite rules only affect the fields selected in a single element of the field expression, it is possible to define different aliases to several fields having the same name but occupying different positions:
Name,Email[0]:PrimaryEmail,Email[1]:SecondaryEmail
When that field expression is applied to the following record:
Name: Mr. Foo Email: primary@email.com Email: secondary@email.com Email: other@email.com
the result will be:
Name: Mr. Foo PrimaryEmail: primary@email.com SecondaryEmail: secondary@email.com Email: other@email.com
It is possible to use the dot notation in order to refer to field and
sub-fields. This is mainly used in the context of joins, where new
fields are created having compound names such as Foo_Bar
. A
reference to such a field can be done in the fex using dot notation
as follows:
Foo.Bar