Writing code using the Expression Builder
Some Jobs require pieces of code to be written in order to provide components with parameters. In the Component view of some components, an Expression Builder interface can help you write such pieces of code (in Java), known as expressions.
Using the Expression Builder of tMap, you can edit the expression for an input column, an output column, or a variable, or change the expressions for multiple output columns at the same time.
Editing individual expressions
About this task
The following example shows how to use the Expression Builder to edit two individual expressions.
In this example, two input flows are connected to the tMap component.
-
From the DB input, comes a list of names made of a first name and a last name separated by a space char.
-
From the File input, comes a list of US states, in lower case.
In the tMap, use the expression builder to: First, replace the blank char separating the first and last names with an underscore char, and second, change the states from lower case to upper case.
Procedure
Results
These changes will be carried out along the flow processing. The output of this example is as shown below.
Setting expressions for multiple output columns simultaneously
About this task
tMap allows you to define the transformation behavior for multiple output columns at the same time.
Using a simple transformation Job, the following example shows how to define expressions on multiple columns in a batch manner in tMap.
Here is the content of the input CSV file used in this example:
id;firstname;lastname;city;state
1; Andrew;Adams;Madison; Rhode Island
2;Andrew; Garfield; Saint Paul;Colorado
3; Woodrow; Eisenhower ; Juneau; New Hampshire
4;Woodrow; Jackson;Denver;Maine
5; Lyndon;Buchanan; Pierre; Kentucky
6; Bill;Tyler; Helena; New York
7;George;Adams;Oklahoma City ;Alaska
8;Ulysses; Garfield;Santa Fe;Massachusetts
9; Thomas;Coolidge ;Charleston; Mississippi
10;John;Polk; Carson City; Louisiana
In this example, all the output columns of type String will be trimmed to remove preceding and training whitespace and the last names and state names will be transformed to upper case.
Procedure
Results
Now the expressions on those output columns look like below: