A site about Talend
The tMap component is part of the Processing family of components. tMap is one of the core components and is primarily used for mapping input data to output data, that is, mapping one Schema to another.
As well as performing mapping functions, tMap may also be used to Join multiple inputs, and to write multiple outputs. Additionally, you can Filter data within the tMap component. We'll cover these features in a later article.
I would recommend that you use tMap in preference to any of the Custom Code Components, if it meets your requirement. If you are writing anything but the most basic of Mapping Expressions and it is an expression that you expect to use a number of times for different columns, or in Talend Jobs, then I would strongly recommend that you consider writing a Routine.
If you're new to Talend and the tMap component, then I'd recommend that you take the tutorial My First Talend Job. This tutorial will provide you with a basic understanding of the components ability to read input data, perform some mapping and then to write output data. The remainder of the documentation, here, will assume that you have this basic understanding of tMap.
The Map Editor allows you to enter a Mapping Expression for each of the columns in each output Schema.
The following is a simple example of an expression.
row1.PostalCode == null ? null : row1.PostalCode.toUpperCase()
You can also perform some nesting, extending your expression as follows.
row1.PostalCode == null ? null : row1.PostalCode.length() == 0 ? null : row1.PostalCode.toUpperCase()
As can be seen from the above examples, we have slowly increased the complexity of our Mapping Expression, for transforming a Postal Code. You should always take the opportunity to look for Design Patterns with a view to Refactor your code for reuse. Is Postal Code code transformation something that you will use more than once?
Also consider if there are existing libraries available that you can use. Google, for example, provides a Phone Number Handling Library.
It is very likely that we'll want to extend the functionality our Postal Code transformation in the future, for example, checking its format. It's better to change this logic once, in a single Routines, rather than numerous times in individual Mapping Expressions.
The following screenshot shows the Map Editor for a trivial Job that reads and writes employee data. No transformation of the data takes place.
comments powered by Disqus