
Warning
This component will be available in the Palette of
Talend Studio on the condition that you have subscribed to one of
the Talend Platform products.
Component family |
Processing |
|
Function |
tHMap transforms data from a wide |
|
Purpose |
tHMap executes transformations |
|
Basic settings |
Open Map Editor |
Click the […] button |
|
Map Path |
Specifies the map to be executed. If the map was automatically created using the wizard described If you want to use an existing map, click the […] button next to the Map Path field to open a dialog box in |
Log Level |
From the drop-down list, select how often you want events to be
|
|
Exception Threshold |
Talend Data Mapper returns an execution From the drop-down list, select the severity level at which an
Note that, in order to help you diagnose problems with your map, |
|
Read Input As |
Select the radio button which corresponds to how you want the
|
|
Write Output As |
Select the radio button which corresponds to how you want the
|
|
Advanced settings | tStatCatcher Statistics |
Select this check box to gather the Job processing metadata at the |
Global Variables |
ERROR_MESSAGE: the error message generated by the EXECUTION_STATUS: the pointer to the ExecutionStatus object, which is returned whenever tHMap executes a Talend Data Mapper map. This is an EXECUTION_SEVERITY: the Overall A Flow variable functions during the execution of a component while an After variable To fill up a field or expression with a variable, press Ctrl + For further information about variables, see Talend Studio |
|
Usage |
tHMap is used for Jobs that The input and output connections can use Talend Data Mapper metadata, Talend Data Integration metadata, or a combination When you open the Map Editor for the first time for each This component can be used in several ways:
|
|
Limitation |
n/a |
Note
For further information about performing transformations using Talend Data Mapper, see Talend Data Mapper User
Guide.
The following scenario creates a three-component Job, reading data from an input file
that is transformed using a map that was previously created in the Mapping
perspective and then outputting the transformed data in a new file. It works with
Talend Data Mapper metadata.

Copying an editable version of the example files
-
In the Mapping perspective, in
the Data Mapper view, expand the Hierarchical Mapper node and the Other Projects folder, right-click Examples and then select Copy in the contextual menu. -
In the Data Mapper view, right-click at the
root of the Hierarchical Mapper node, and then
select Paste in the contextual menu.This copies an editable version of all the read-only example files to your
local workspace.
Adding and linking the components
-
In the Integration perspective,
create a new Job and call it tdm_to_tdm. -
Click the point in the design workspace where you want to add the first
component, start typing tFileInputRaw, and then
click the name of the component when it appears in the list proposed in order to
select it. -
Do the same to add a tHMap component and a
tFileOutputRaw component as well. -
Connect the tFileInputRaw component to the
tHMap component using a Row > Main link and rename it input, then connect the tHMap
component to the tFileOutputRaw component using
a Row > Main link and name it output. When you are asked if you want to get the
schema of the target component, click Yes.
Defining the properties of tFileInputRaw
-
Select the tFileInputRaw component to define
its properties. -
In the Basic settings tab, click the
[…] button next to the Filename field then browse to the location on your
file system where the input file is stored, or enter the path manually between
double quotes. For this example, use <PATH_TO_WORKSPACE>/<PROJECT_NAME>/Sample
Data/CSV/PurchaseOrderPayPal/PayPalPO.csv. -
Set the Mode as Read
the file as a string, and leave all the other parameters
unchanged.
Defining the properties of tFileOutputRaw
-
Select the tFileOutputRaw component to define
its properties. -
In the Basic settings tab, click the
[…] button then browse to the location on
your file system where the output file is to be stored, or enter the path
manually between double quotes. Leave the other parameters unchanged.
Defining the properties of tHMap
-
Select the tHMap component to define its
properties. -
Click the […] button next to the Map Path field to open the picker and select the map
to use, Maps/CSV/POPayPalCsv_PO2, then click
OK. This map transforms a CSV file into an
XML file. -
Set Read Input As to Single Column.
-
Set Write Output As to String (single column).
The following scenario creates a three-component Job, reading data from an input file
that is transformed using a map that you create in the Mapping
perspective and then outputting the transformed data in a new file. It works with
Talend Data Integration metadata.

Copying an editable version of the example files
-
In the Mapping perspective,
in the Data Mapper view, expand the
Hierarchical Mapper node and the
Other Projects folder, right-click
Examples and then select Copy in the contextual menu. -
In the Data Mapper view, right-click at
the root of the Hierarchical Mapper node,
and then select Paste in the contextual
menu.This copies an editable version of all the read-only example files to your
local workspace.
Adding and linking the components
-
In the Integration
perspective, create a new Job and call it di_to_di. -
Click the point in the design workspace where you want to add the first
component, start typing tFileInputDelimited, and then click the name of the component
when it appears in the list proposed in order to select it. -
Do the same to add a tHMap component and
a tFileOutputXML component as well. -
Connect the tFileInputDelimited component
to the tHMap component using a Row > Main link, then connect the tHMap component to the tFileOutputXML component using a Row >
Main link.
Defining the properties of tFileInputDelimited
-
Select the tFileInputDelimited component
to define its properties. -
In the Basic settings tab, click the […] button next to the Filename field then browse to the location on your file system
where the input Excel file is stored, or enter the path manually between
double quotes. For this example, use <PATH_TO_WORKSPACE>/<PROJECT_NAME>/Sample
Data/CSV/PurchaseOrderPayPal/PayPalPO.csv. -
Select the CSV options check box.
-
Change the Field Separator to a comma,
between double quotes (“,”). -
Change the value of Header to 1.
-
Click the […] button next to Edit schema to define the schema.
-
Add three columns and rename them txn_id, payment_date and
first_name (which correspond to the
names of the first three columns in the input file, and is sufficient for
the purposes of this example), and then click OK. -
Leave all the other parameters unchanged.
Defining the properties of tFileOutputXML
-
Select the tFileOutputXML component to
define its properties. -
In the Basic settings tab, click the
[…] button next to the File Name field then browse to the location on
your file system where the output file will be stored, or enter the path
manually between double quotes. -
Click the […] button next to Edit schema to define the schema.
-
Add three columns to the input schema on the left and rename them
id, date and name, copy them
to the output schema on the right, and then click OK. -
Leave the other elements unchanged.
Defining the properties of tHMap
-
Select the tHMap component to define its
properties. -
Click the […] button next to the
Open Map Editor field to create a new
map based on the input and output of tHMap. -
In the tHMap Structure Generate/Select
dialog box that opens, select Generate hierarchical
mapper structure based on the schema and then click Next to generate the input structure. -
Do the same for the output structure.
-
In the Mapping perspective
that opens, drag the txn_id element of
Input (map) to the id element of Output
(map). Do the same to map payment_date to date and
first_name to name, and then save your changes. -
In the Integration
perspective, in the Job, check that Read Input
As is set to Data Integration
columns.
The following scenario creates a three-component Job, generating some random data from
an input component, transforming this data using a map which was previously created in
the Mapping
perspective, and then outputting the transformed data in a JSON file. It works with
Talend Data Integration metadata for the input and Talend Data Mapper metadata for the output.

Creating a new structure in the Mapping perspective
-
In the Mapping perspective, in
the Data Mapper view, expand the Hierarchical Mapper node, right-click Structures and then select New > Structure. -
In the [New Structure] dialog box that opens,
select Create a new structure where you manually enter
elements, and then click Next. -
Name your structure JSON_structure, and
then click Next. -
In the [Select Representation] dialog box,
select JSON from the list of available
representations, and then click Next. -
Select Don’t select a sample document for
now, and then click Finish.
Entering the elements for your new structure
-
In the Mapping perspective, in
the Data Mapper view, expand the Hierarchical Mapper node and the Structures node, and then open the JSON_structure structure you created
earlier. -
In the JSON_structure, right-click to add a
new element, click New element and name the new
element Root. -
Follow the same steps to create a new element called people under the Root
element, a person element under people, and four new elements under the person element: firstname, lastname,
address and city. -
For the person element, change the
Occurs Max value to -1 (unlimited). -
Press Ctrl + S to save your changes.
Adding and linking the components
-
In the Integration perspective, in the
Repository, right-click Job Designs, and then click Create Job to create a Job named di_to_json. Add a Purpose and
Description if you wish, and then click
Finish. -
Click the point in the design workspace where you want to add the first
component, start typing tRowGenerator, and then
click the name of the component when it is displayed in the list proposed in
order to select it. -
Do the same to add a tHMap component, and a
tFileOutputRaw component as well. -
Connect the tRowGenerator component to the
tHMap component using a Row > Main link, then connect the tHMap component to the tFileOutputRaw component using a Row >
Main link. When you are asked if you want to get the schema of
the target component, click Yes.
Defining the properties of tRowGenerator
-
Select the tRowGenerator component to define
its properties. -
In the Basic settings tab, click the
[…] button next to RowGenerator Editor to define the rows to be generated. -
In the dialog box that opens, click four times the [+] button to add four new columns to the schema, and name them
firstname, lastname, address and
city. -
For each of the columns you just added, change the function to match what is
shown in the table below by clicking in the Functions column and scrolling through the list of available
functions until you find the one you want, and then click OK when you’re done.firstname
TalendDataGenerator.getFirstName
lastname
TalendDataGenerator.getFirstName
address
TalendDataGenerator.getUsStreet
city
TalendDataGenerator.getUsCity
Defining the properties of tFileOutputRaw
-
Select the tFileOutputRaw component to define
its properties. -
In the Basic settings tab, click the
[…] button then browse to the location on
your file system where the output file is to be stored, or enter the path
manually between double quotes, and call the output file output.jsonLeave the other parameters unchanged.
Defining the properties of tHMap
-
Select the tHMap component to define its
properties. -
Click the […] button next to the Open Map Editor field to create a new map.
-
In the [tHMap Structure Generate/Select]
dialog box that opens, select Generate hierarchical mapper
structure based on the schema for the input structure, and then
click Next and then Finish. This means that Talend Data Mapper will
automatically generate a structure for you, based on the schema of the input
component (tRowGenerator in this case). -
For the output structure, select Select an existing
hierarchical mapper structure, and then click Next. -
Select the JSON_structure structure that
you created earlier, and then click Next and
then Finish. -
In the Mapping perspective that opens, drag
row from Input
(Map) to person in Output (JSON) to map each of the input elements to
its corresponding output element. -
Double click SimpleLoop in Loop tab and, in the properties box that opens, check
Stream Input and then click OK. -
Press Ctrl+S to save your changes to the
map. -
Switch back to the Integration perspective to
complete the settings for the tHMap component
in your Job. -
Set Read Input As to Data Integration columns.
-
Set Write Output As to InputStream (single column).
This following scenario creates a six-component Job that shows how to handle error
conditions using the tHMap component.
When tHMap executes a Talend Data Mapper map, an ExecutionStatus object is always returned. A pointer to this object is
stored in the globalMap as EXECUTION_STATUS. In
addition, the Overall Severity numeric value (the
constants are defined in ExecutionStatus) is also
stored in the globalMap as EXECUTION_SEVERITY.
Finally, a parameter called Execution Threshold is
defined that specifies the severity on which to throw an exception, thus triggering
Job-related or component-related error processing. The default value for this parameter
is Fatal.
To consult the Javadoc for the ExecutionStatus
object, see the Camel Runtime documentation included in the Talend Data Mapper runtime kits and the Talend Data Mapper User Guide.

Adding and linking the components
-
In the Integration perspective,
create a new Job and call it error_handling. -
Click the point in the design workspace where you want to add the first
component, start typing tFixedFlowInput, and
then click the name of the component when it appears in the list proposed in
order to select it. -
Do the same to add a tHMap component, a
tJavaRow component, and three tJava components as well. -
Connect the tFixedFlowInput component to the
tHMap component using a Row > Main link, then connect the tHMap component to the tJavaRow component using a Row >
Main link and rename the link out. When you are asked if you want to get the schema of the
target component, click Yes. -
Connect the tFixedFlowInput component to the
first tJava component using an OnSubjobError trigger and to the second tJava component using an OnSubjobOk trigger, then connect the tHMap component to the third tJava component using a RunIf
trigger.
Defining the properties of the RunIf trigger
-
Select the RunIf trigger to define its
properties. -
Add the following code in the Condition
section.1!((org.talend.transform.runtime.api.ExecutionStatus) globalMap.get("tHMap_1_EXECUTION_STATUS")).isOK()
Defining the properties of tFixedFlowInput
-
Select the tFixedFlowInput component to
define its properties. -
In the Basic settings tab, click the
[…] button next to Edit schema to define the schema. -
Add one column, of type
String
, rename it inputKey, and then click OK. -
In the Mode area. select the Use Inline Table radio button, then add three values
to the inputKey column by clicking the
[+] button and then entering the value
between double quotes in each case. In this example, the values used are
value1, value2 and value3.
Defining the properties of tJavaRow
-
Select the tJavaRow component to define its
properties. -
In the Basic settings tab, click the
[…] button next to Edit schema to define the schema. -
Click the [+] button to add a column to the
input schema on the left, of typeString
, rename it outputKey, copy it to the output schema on the
right, and then click OK. -
Add the following code in the Code
section.123String actualOutput = out.outputKey;System.out.println("======" + actualOutput + "======");
Defining the properties of tHMap
-
Select the tHMap component to define its
properties. -
Click the […] button next to the Open Map Editor field to create a new map based on
the input and output of tHMap. -
In the tHMap Structure Generate/Select dialog
box that opens, select Generate hierarchical mapper
structure based on the schema and then click Next to generate the input structure. -
Do the same for the output structure.
-
In the Mapping perspective that
opens, drag the inputKey element of Input (map) to the outputKey element of Output
(map), and then save your changes. -
Back in the Integration perspective, in
the tHMap component in your Job, leave the
value of the Exception Threshold drop-down list
as Fatal. -
In the Read Input As area, select the
Data Integration columns radio
button. -
In the Write Output As area, select the
Data Integration columns radio
button.
Defining the properties of the first tJava component (OnSubjobError)
-
Select the first tJava component to define
its properties. This component displays information in the console when the Job
contains an error. -
Add the following code in the Code
section.1234567891011121314System.out.println("tJava_1: Subjob ERROR");org.talend.transform.runtime.api.ExecutionStatus es = (org.talend.transform.runtime.api.ExecutionStatus)globalMap.get("tHMap_1_EXECUTION_STATUS");System.out.println("Execution result:" + es.getOverallSeverity());// ExecutionStatus objectSystem.out.println(es.toString());// XML version of ExecutionStatus objectjava.io.StringWriter sw = new java.io.StringWriter();es.exportToXml(sw);System.out.println("ExecutionStatus as XML");System.out.println(sw.toString());
Defining the properties of the second tJava component (OnSubjobOk)
-
Select the second tJava component to define
its properties. This component displays information in the console when the Job
runs successfully. -
Add the following code in the Code
section.1234567891011121314System.out.println("tJava_2: Subjob OK");org.talend.transform.runtime.api.ExecutionStatus es = (org.talend.transform.runtime.api.ExecutionStatus)globalMap.get("tHMap_1_EXECUTION_STATUS");System.out.println("Execution result:" + es.getOverallSeverity());// ExecutionStatus objectSystem.out.println(es.toString());// XML version of ExecutionStatus objectjava.io.StringWriter sw = new java.io.StringWriter();es.exportToXml(sw);System.out.println("ExecutionStatus as XML");System.out.println(sw.toString());
Defining the properties of the third tJava component (RunIf)
-
Select the third tJava component to define
its properties. This component runs if any errors occur within the map itself
(higher than informational status). -
Add the following code in the Code
section.1234567891011121314System.out.println("tJava_3: Run If");org.talend.transform.runtime.api.ExecutionStatus es = (org.talend.transform.runtime.api.ExecutionStatus)globalMap.get("tHMap_1_EXECUTION_STATUS");System.out.println("Execution result:" + es.getOverallSeverity());// ExecutionStatus objectSystem.out.println(es.toString());// XML version of ExecutionStatus objectjava.io.StringWriter sw = new java.io.StringWriter();es.exportToXml(sw);System.out.println("ExecutionStatus as XML");System.out.println(sw.toString());
Running the Job under different conditions
-
Press Ctrl+S to save your Job.
-
In the Run tab, click Run to execute the Job.
In this case, no errors occur, so the Job triggers the second tJava component only.
-
Double-click the tHMap component to open the
Mapping
perspective. -
Right-click the outputKey element and click
Go to Structure Element. -
Change the tHMap_1_output structure that
opens from Read Only to Editable and then change the Data
Type for outputkey to
Integer (32). This means that this element
can only be anInteger
, and since this does not match the input, an
error will occur. -
In the Run tab, click Run to execute the Job again.
In this case, the Job still triggers the second tJava component even though there is an error, because the
threshold above which an exception should be thrown (thus enabling the
downstream components to detect the error) is set as Fatal. However, the third tJava
component is also triggered since there is an error in the execution of the
map. -
In the tHMap component, change the value of
the Exception Threshold drop-down list to
Error. This causes an exception to be
thrown when the map has a severity of Error
or higher. -
In the Run tab, click Run to execute the Job for a third time.
In this case, the Job detects the error and triggers the first tJava component (OnSubjobError).