All expressions (Input, Var or Output) and constraint statements can be viewed and edited from the expression editor. This editor provides visual comfort to write any function or transformation in a handy dedicated view.
You can write the expressions necessary for the data transformation directly in the Expression editor view located in the lower half of the expression editor, or you can open the [Expression Builder] dialog box where you can write the data transformation expressions.
To open the Expression editor view, complete the following:
Double-click the tMap component in your job design to open the Map Editor.
In the lower half of the editor, click the Expression editor tab to open the corresponding view.
To edit an expression, select it in the Input panel and then click the Expression editor tab and modify the expression as required.
Enter the Java code according to your needs. The corresponding expression in the output panel is synchronized.
Refer to the Java documentation for more information regarding functions and operations.
To open the [Expression Builder] dialog box, click the three-dot button next to the expression you want to open in the Var or Output panel of the Map Editor.
The [Expression Builder] dialog box opens on the selected expression.
For a use case showing the usage of the expression editor, see the following section.
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 these pieces of code (in Java).
The following example shows the use of Expression Builder in a tMap component.
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.
From the main (row1) input, drop the Names column to the output area, and the State column from the lookup (row2) input towards the same output area.
Then click in the first Expression field (row1.Name) to display the three-dot button.
The [Expression Builder] dialog box opens up.
In the Category area, select the relevant action you want to perform. In this example, select
StringHandlingand select the
In the Expression area, paste row1.Name in place of the text expression, in order to get:
StringHandling.EREPLACE(row1.Name," ","_"). This expression will replace the separating space char with an underscore char in the char string given.
Now check that the output is correct, by typing in the relevant Value field of the Test area, a dummy value, e.g: Chuck Norris and clicking Test!. The correct change should be carried out, for example, Chuck_Norris.
Click OK to validate the changes, and then proceed with the same operation for the second column (State).
In the tMap output, select the row2.State Expression and click the [...] button to open the Expression builder again.
This time, the
StringHandlingfunction to be used is
UPCASE. The complete expression says:
Once again, check that the expression syntax is correct using a dummy Value in the Test area, for example indiana. The Test! result should display INDIANA for this example. Then, click OK to validate the changes.
Both expressions are now displayed in the tMap Expression field.
These changes will be carried out along the flow processing. The output of this example is as shown below.