Expert Consultancy from Yellow Pelican

tMap Transformation

A site about Talend

tMap Component Transformation

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.

My recommendation is to Use tMap for Joining data, as opposed to using tJoin. For more information on tMap vs. tJoin, read Use tJoin or tMap?.

If you are joining database sources, then read our article on Talend Database Joins.

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.

Getting Started with tMap

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.

Mapping Expressions

The Map Editor allows you to enter a Mapping Expression for each of the columns in each output Schema.

A mapping expression may refer to any number of columns from each of the input Schemas You may also use any available Java Class Methods and Talend Routine.

The following is a simple example of an expression.


Of course, it's good practice to perform a null-test before calling a Method, so Talend also allows you to enter the following construct.

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()

Design Patterns

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.

For more information on Refactoring your code, read our tutorial on Routines.

Map Editor

The following screenshot shows the Map Editor for a trivial Job that reads and writes employee data. No transformation of the data takes place.

Image 1

Expert Consultancy from Yellow Pelican
comments powered by Disqus