July 30, 2023

tHMap – Docs for ESB 7.x

tHMap

Executes transformations (called maps) between different sources and destinations
by harnessing the capabilities of Talend Data Mapper , available in the Mapping perspective.

tHMap transforms data from a wide range of sources to a wide range of
destinations, including support for multiple inputs and multiple outputs. If you want to
use multiple inputs, you must use Talend Data Mapper I/O functions. For more information, see Talend Data Mapper User Guide.

tHMap Standard properties

These properties are used to configure tHMap running in the Standard Job framework.

The Standard
tHMap component belongs to the Processing family.

This component is available in Talend Data Management Platform, Talend Big Data Platform, Talend Real Time Big Data Platform, Talend Data Services Platform, Talend MDM Platform and Talend Data Fabric.

Basic settings

Open Map Editor

Click the […]
button to open the tHMap Structure
Generate/Select
wizard where you can either have the
hierarchical mapper structure generated automatically based on the
schema, or select an existing hierarchical mapper structure. You must do
this for both the input and output sides of your Map. The following
lists the options for the output structure:

  • Generate hierarchial mapper structure based on the
    schema
    option: When you connect multiple output
    connections to the tHMap, the page displays a confirmation
    message that informs you that the mapper structures are
    generated based on the output connections.
  • Select an existing hierarchical mapper
    structure
    option: You can connect multiple
    outputs that are payload-based connections to the tHMap. If
    there is a single payload-type connection, you can select the
    Allow support for multiple output
    connections
    checkbox. The generated output map
    inherits from the existing payload structure.

If Talend Studio detects
multiple output connections available, the window displays both output
structure options without the support for multiple output connections
checkboxes.

If neither input nor output connection exists, the Structure Selection
page is displayed.

Map Path

Specifies the map to be executed.

If the map was automatically created using the wizard described above,
this is path is set automatically.

If you want to use an existing map, click the […] button next to the Map
Path
field to open a dialog box in which you can select
the map you want to use, then click the […] button next to Open Map
Editor
to work with the map selected. Note that this map
must have previously been created in the
Mapping
perspective.

Read Input As

Select the radio button which corresponds to how you want the input to
be read. Depending on your map, only some of the options may be
available.

  • Data Integration columns
    (default): Use this option if you are working with Talend Data Integration metadata.

  • Single column: Use this option
    if you are working with Talend Data Mapper metadata.

Write Output As

Select the radio button which corresponds to how you want
the output to be written. Depending on your map, only some of the
options may be available.

  • Data Integration columns
    (default): Use this option if you are working with Talend Data Integration metadata.

  • String (single
    column)
    : Use this option if the data in the
    output column is to be a String.

  • Byte array (single
    column)
    : Use this option if the data in the
    output column is to be a Byte
    array
    .

  • InputStream (single
    column)
    : Use this option if you are working with
    Talend Data Mapper metadata and the input data is a
    stream.

  • Document (single column);
    Use this option if the output column is to be a Document.

    Note: If you have selected Document (single
    column)
    in the Job you created in versions 6.5
    or below of Talend Studio and would
    like to import the same Job to the latest versions 7.0 or
    onwards, ensure that you have updated the output representation
    of the map to XML prior to executing the Job. Versions 7.0 or
    onwards only
    accept
    the Document output type with XML
    representation.

Advanced settings

Map Variable

In this field, enter a context variable that contains a
path to a map. For instance, if you enter context.mymapfile, then mymapfile can
point to different map files at runtime. This can be useful in cases
where you want to use multiple maps without creating a new Job each
time.

In the Contexts
tab, the value must be an relative path. For instance, assuming you have
a map called mapA in the folder Maps/FolderA, your context variable should
contain the value “FolderA/mapA.xml”. You can
write the path to the file with or without the .xml extension.

Note that all maps that might be referenced by the
context variable must be present in the same Project. This way, when the
job is built, it will contain all candidate maps and it will be possible
to switch from one to another at runtime.

For further information on working with
context variables, see Talend Studio
User Guide.

Alternate contextual Map(s)

From the drop-down list, select a map or several maps that can be
referenced by the context variable added in the Map
Variable
at runtime. When the Job is built, it contains
the selected alternate contextual map or maps. For an example scenario
on using Alternate contextual Map(s), see Specifying a map
variable and alternate map in tHMap.

Map each row (disable virtual
component)

Select this check box to have tHMap process the input as a single output row. This
prevents tHMap from buffering the
input rows before delivering them downstream.

This can be useful, for example, when you use the
tHMap component with
tSAPIDocReceiver as the input
component and any schema-aware component as the output component,
because telling the tSAPIDocReceiver component to keep listening forever
would otherwise lead to rows never being delivered.

Exception Threshold

Talend Data Mapper returns an execution status with an severity
value which can be OK, Info, Warning, Error or Fatal. By setting the exception threshold, you can
specify the severity level at which an exception is thrown, thus
enabling downstream components to detect the error in cases other than
the default value of Fatal.

From the drop-down list, select the severity level at
which an exception may be thrown during the execution of a map.

  • Fatal (default): An
    exception is thrown when a fatal error occurs.

  • Error: An exception is
    thrown when an error (or higher) occurs.

  • Warning: An exception is
    thrown when a warning (or higher) occurs.

Note that, in order to help you diagnose problems with
your map, when you test the map in the Studio, any errors that occur
which are at warning level or above will be printed in the console
window, regardless of the setting of the Exception Threshold.

tStatCatcher Statistics

Select this check box to gather the Job processing
metadata at the Job level as well as at each component level.

Global Variables

Global Variables

ERROR_MESSAGE: the error message generated by the
component when an error occurs. This is an After variable and it returns a string. This
variable functions only if the Die on error check box is
cleared, if the component has this check box.

MapExecutionStatus: returns an object of the
org.talend.transform.runtime.common.MapExecutionStatus
class

EXECUTION_SEVERITY: the Overall
Severity
numeric value. This is an After variable and it returns an
integer.

A Flow variable functions during the execution of a component while an After variable
functions after the execution of the component.

To fill up a field or expression with a variable, press Ctrl +
Space
to access the variable list and choose the variable to use from it.

For further information about variables, see
Talend Studio

User Guide.

Usage

Usage rule

tHMap is used for Jobs that
require complex data mapping from a variety of different sources.

The input and output connections can use
Talend Data Mapper metadata, Talend Data Integration
metadata, or a combination of the two. Each connection is
independent.

When you open the Map Editor for the
first time for each connection, it either generates a Talend Data Mapper
structure definition based on the schema of the Talend Data Integration
component, or allows you to select an existing Talend Data Mapper
structure if you are using Talend Data Mapper metadata. It then creates a map
with the structure selected or generated.

This component can be used in several ways:

Advanced use case
  • For the output Structure of the thMap, you can also use the
    WriteURL function in
    Talend Data Mapper .
    In case the output Structure of the tHMap includes both a connection to a Talend Data Integration metadata or
    component and a WriteURL
    function, the WriteURL value
    takes precedence. Talend Data Integration metadata or component does not receive any
    data from tHMap.
  • Using tHMap, you can test the generated
    Talend Data Mapper
    Map in Test Run mode.

    To use the feature, ensure that you have a compatible input
    document of CSV format with these properties:

    • the default delimiter is the (,) comma;
    • the system default line separator is used as the
      newline;
    • there exists no header row in the input file;
    • there will be no header row in the output file.

    Specify your input document in Show Document > Select Sample Input Document > Select Resource/Import Document.

    To execute the transformation, click Test Run. After execution, your
    generated output document is in CSV format, which you can save
    by clicking Save to
    File
    . To configure this feature, see Test
    preferences in the Talend Data Mapper User Guide.

    Tip: If you have multiple inputs and outputs in your
    Map, specify an input document for each row or each ReadURL map
    element. To execute, use the Test Run to External
    Output
    option and specify a file URL for each
    WriteURL in the output structure of the Map.
Limitations
  • If you created a tHMap with multiple input or output connections,
    you can only add new schema-based input or output connections.
  • When you add a new connection with a single column, you cannot
    associate it with a payload structure. The Map Regeneration
    mechanism only generates a single-element record for the new
    connection.
  • If you rename a payload-type connection, regenerate the
    corresponding map and its structure by double-clicking on the tHMap
    before closing the Job editor. The renamed record structure then
    contains the payload structure.
  • If in the event that you closed the Job prior to regenerating a
    renamed payload-type connection, the system treats the connection as
    a schema-type connection. The payload structure does not get
    associated with the new name.
Note:

  • For further information about performing
    transformations using Talend Data Mapper , see Talend Data Mapper User Guide.

  • For tHMap using representations other than Hashmap,
    CSV, Avro, XML, and Cobol: Running tHMap may create
    temporary folders, which are not automatically removed after completing
    the Eclipse runtime. If you frequently run Talend Data Mapper, these files may
    pile up and eventually lead to a disk full error. When the error occurs,
    the runtime fails. To avoid such scenario, ensure that you perform
    periodical cleaning.

Using Talend Data Mapper metadata

This scenario applies only to Talend Data Management Platform, Talend Big Data Platform, Talend Real Time Big Data Platform, Talend Data Services Platform, Talend MDM Platform and Talend Data Fabric.

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.

tHMap_1.png

Copying an editable version of the example files

  1. 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.
  2. 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

  1. In the
    Integration
    perspective,
    create a new Job and call it tdm_to_tdm.
  2. 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.
  3. Do the same to add a tHMap component and a
    tFileOutputRaw component as well.
  4. 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

  1. Select the tFileInputRaw component to define
    its properties.

    tHMap_2.png

  2. 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
    .
  3. Set the Mode as Read
    the file as a string
    , and leave all the other parameters
    unchanged.

Defining the properties of tFileOutputRaw

  1. Select the tFileOutputRaw component to define
    its properties.

    tHMap_3.png

  2. 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

  1. Select the tHMap component to define its
    properties.

    tHMap_4.png

  2. 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.
  3. Check that Read Input As is set to Single Column.
  4. Check that Write Output As is set to String (single column).

Saving and executing the Job

  1. Press Ctrl+S to save your Job.
  2. In the Run tab, click Run to execute the Job.
  3. Browse to the location on your file system where the output file is stored to
    check that an XML file has been created containing the same data as the input
    CSV file.

Using Talend Data Integration metadata

This scenario applies only to Talend Data Management Platform, Talend Big Data Platform, Talend Real Time Big Data Platform, Talend Data Services Platform, Talend MDM Platform and Talend Data Fabric.

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.

tHMap_5.png

Copying an editable version of the example files

  1. 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.
  2. 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

  1. In the
    Integration
    perspective, create a new
    Standard Job and call it di_to_di.
  2. 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.
  3. Do the same to add a tHMap component and a
    tFileOutputXML component as well.
  4. 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

  1. Select the tFileInputDelimited component to
    define its properties.

    tHMap_6.png

  2. In the Basic settings tab, click the […] button next to the File
    name/Stream
    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
    .
  3. Select the CSV options check box.
  4. Change the Field Separator to a comma, between
    double quotes (“,”).
  5. Change the value of Header to 1.
  6. Click the […] button next to Edit schema to define the schema.
  7. 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.
  8. Leave all the other parameters unchanged.

Defining the properties of tFileOutputXML

  1. Select the tFileOutputXML component to define its
    properties.

    tHMap_7.png

  2. 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.
  3. Click the […] button next to Edit schema to define the schema.
  4. 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.
  5. Leave the other elements unchanged.

Defining the properties of tHMap

  1. Select the tHMap component to define its
    properties.

    tHMap_8.png

  2. Click the […] button next to the Open Map Editor field to create a new map based on the input
    and output of tHMap.
  3. 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.
  4. Do the same for the output structure.
  5. In the Map editor 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.

    tHMap_9.png

Saving and executing the Job

  1. Press Ctrl+S to save your Job.
  2. In the Run tab, click Run to execute the Job.
  3. Browse to the location on your file system where the output file is stored to
    check that an XML file has been created containing the same data as the input CSV
    file.

Transforming from a Data Integration schema to a complex content
schema

This scenario applies only to Talend Data Management Platform, Talend Big Data Platform, Talend Real Time Big Data Platform, Talend Data Services Platform, Talend MDM Platform and Talend Data Fabric.

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.

tHMap_10.png

Creating a new structure in the
Mapping
perspective

  1. In the
    Mapping
    perspective, in
    the Data Mapper view, expand the Hierarchical Mapper node, right-click Structures and then select New > Structure.
  2. In the New Structure dialog box that opens,
    select Create a new structure where you manually enter
    elements
    , and then click Next.
  3. Name your structure JSON_structure, and
    then click Next.
  4. In the Select Representation dialog box,
    select JSON from the list of available
    representations, and then click Next.
  5. Select Don’t select a sample document for
    now
    , and then click Finish.

Entering the elements for your new structure

  1. 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.
  2. In the JSON_structure, right-click to add a
    new element, click New element and name the new
    element Root.
  3. 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.
  4. For the person element, change the
    Occurs Max value to -1 (unlimited).

    tHMap_11.png

  5. Press Ctrl + S to save your changes.

Adding and linking the components

  1. In the Integration perspective, in the Repository, right-click Job
    Designs
    , and then click Create Standard
    Job
    to create a Job named di_to_json. Add a Purpose and
    Description if you wish, and then click
    Finish.
  2. 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.
  3. Do the same to add a tHMap component, and a
    tFileOutputRaw component as well.
  4. 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

  1. Select the tRowGenerator component to define
    its properties.
  2. In the Basic settings tab, click the
    […] button next to RowGenerator Editor to define the rows to be generated.
  3. 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.
  4. 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

  1. Select the tFileOutputRaw component to define
    its properties.
  2. 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.json

    Leave the other parameters unchanged.

Defining the properties of tHMap

  1. Select the tHMap component to define its
    properties.

    tHMap_12.png

  2. Click the […] button next to the Open Map Editor field to create a new map.
  3. 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).
  4. For the output structure, select Select an existing
    hierarchical mapper structure
    , and then click Next.
  5. Select the JSON_structure structure that
    you created earlier, and then click Next and
    then Finish.
  6. In the Map editor that opens, drag row from
    Input (Map) to person in Output (JSON) to map
    each of the input elements to its corresponding output element.

    tHMap_13.png

  7. Double click SimpleLoop in Loop tab and, in the properties box that opens, check
    Stream Input and then click OK.
  8. Press Ctrl+S to save your changes to the
    map.

Saving and executing the Job

  1. Press Ctrl+S to save your Job.
  2. In the Run tab, click Run to execute the Job.
  3. Browse to the location on your file system where the output file is stored to
    check that a JSON file showing the expected data has been successfully
    created.

Handling errors

This scenario applies only to Talend Data Management Platform, Talend Big Data Platform, Talend Real Time Big Data Platform, Talend Data Services Platform, Talend MDM Platform and Talend Data Fabric.

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
.

tHMap_14.png

Adding and linking the components

  1. In the
    Integration
    perspective,
    create a new Standard Job and call it error_handling.
  2. 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.
  3. Do the same to add a tHMap component, a
    tJavaRow component, and three tJava components as well.
  4. 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. If you are asked whether you
    want to get the schema of the target component, click Yes.
  5. 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

  1. Select the RunIf trigger to define its
    properties.
  2. Add the following code in the Condition section:!((org.talend.transform.common.MapExecutionStatus)
    globalMap.get("tHMap_1_EXECUTION_STATUS")).isOK()

Defining the properties of tFixedFlowInput

  1. Select the tFixedFlowInput component to
    define its properties.
  2. In the Basic settings tab, click the
    […] button next to Edit schema to define the schema.
  3. Add one column, of type String, rename it inputKey, and then click OK.
  4. 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

  1. Select the tJavaRow component to define its
    properties.
  2. In the Basic settings tab, click the
    […] button next to Edit schema to define the schema.
  3. Click the [+]  button to add a column to the
    input schema on the left, of type String, rename it outputKey, copy it to the output schema on the
    right, and then click OK.
  4. Add the following code in the Code
    section.String actualOutput = out.outputKey;

    System.out.println("======" + actualOutput + "======");

Defining the properties of tHMap

  1. Select the tHMap component to define its
    properties.
  2. Click the […] button next to the Open Map Editor field to create a new map based on
    the input and output of tHMap.
  3. 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.
  4. Do the same for the output structure.
  5. In the Map editor that opens, drag the inputKey element
    of Input (map) to the outputKey element of Output
    (map)
    , and then save your changes.

    tHMap_15.png

  6. Back in the Job, in the tHMap component, leave the value
    of the Exception Threshold drop-down list (in
    the Advanced settings tab) as Fatal.
  7. In the Basic settings tab, check that Read Input As is set to Data
    Integration columns
    .
  8. Check that Write Output As is set to Data Integration columns.

Defining the properties of the first tJava component (OnSubjobError)

  1. Select the first tJava component to define
    its properties. This component displays information in the console when the Job
    contains an error.
  2. Add the following code in the Code
    section.System.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 object
    System.out.println(es.toString());

    // XML version of ExecutionStatus object
    java.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)

  1. Select the second tJava component to define
    its properties. This component displays information in the console when the Job
    runs successfully.
  2. Add the following code in the Code
    section.System.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 object
    System.out.println(es.toString());

    // XML version of ExecutionStatus object
    java.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)

  1. Select the third tJava component to define
    its properties. This component runs if any errors occur within the map itself
    (higher than informational status).
  2. Add the following code in the Code
    section.System.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 object
    System.out.println(es.toString());

    // XML version of ExecutionStatus object
    java.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

  1. Press Ctrl+S to save your Job.
  2. 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.
    tHMap_16.png

  3. Double-click the tHMap component to open the Map
    editor.
  4. Right-click the outputKey element and click
    Go to Structure Element.
  5. 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 an Integer, and since this does not match the input, an
    error will occur.

    tHMap_17.png

  6. 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.
    tHMap_18.png

  7. In the tHMap component, change the value of the Exception Threshold drop-down list (on the Advanced Settings tab) to Error. This causes an exception to be thrown when the map has a
    severity of Error or higher.
  8. 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).
    tHMap_19.png

Generating the Output Using tHMap with Multiple Schema Inputs

tHMap supports multiple inputs coming from either schema-based
input connections or other raw file inputs. In this scenario, you can see how you can
generate outputs using schema-based inputs with Main connections to
the tHMap component.

This scenario applies only to Talend Data Management Platform, Talend Big Data Platform, Talend Real Time Big Data Platform, Talend Data Services Platform, Talend MDM Platform and Talend Data Fabric.

Creating the Schema tHMap Job

The Schema tHMap Job includes three types of components –
tRowGenerator, tHMap, and
tLogRow.

In Talend Studio, create the Schema tHMap Job:

tHMap_20.png
  1. Create a Standard Job and name it thm_schemaInOut.
  2. Add the following components:

    • two tRowGenerator
    • tHMap
    • two tLogRow
  3. Connect the components using the Row > Main connection as shown in the previous image.
  4. When prompted for the output name, enter aa and
    bb respectively.

Configuring tRowGenerator

tRowGenerator creates an input flow in the Schema tHMap Job. In
this scenario, add two tRowGenerator components.

  1. Double-click the first tRowGenerator to display the
    Schema of tRowGenerator window.
  2. Add three columns with the following details:

    • Type: String
    • Functions:
      TalendDataGenerator.getFirstName()
    tHMap_21.png

  3. Double-click the second tRowGenerator to open the Schema of tRowGenerator
    window.
  4. Add two columns with the following details:

    • Type: String
    • Functions: TalendDataGenerator.getLastName()
    tHMap_22.png

Configuring tLogRow

tLogRow displays data or results in the Run console. In this
scenario, use two tLogRow components to connect to tHMap.

  1. Select the first tLogRow component to display the
    Component tab.
  2. In the Component tab, click Edit
    schema
    to open the Schema of tLogRow editor.
  3. Add two columns in both the Input and Output tables as shown in the following
    image:

    tHMap_23.png

  4. Select the second tLogRow to the
    Component tab.
  5. In the Component tab, click Edit
    schema
    to open the Schema of tLogRow editor.
  6. Add three columns in both the Input and Output tables as shown in the following
    image:

    tHMap_24.png

Configuring tHMap

tHMap executes transformations between sources and
destinations.

  1. Double-click tHMap to display the tHMap
    Structure Generate/Select
    window.
  2. Select Generate hierarchical mapper structure based on the
    schema
    and click Next.
  3. Click Next twice.
  4. Click Finish to open the Map Editor.
  5. In the Map Editor, connect the following entries from the Input Map to the
    Output Map:

    • row1 to bb
    • row2 to aa
  6. Save your changes.

Running the Schema tHMap Job

Now that you have configured the components and added the connections, you can run
the Job to see the output in the Run console.

  1. Save the changes you made in the Job.
  2. Click Run to execute the Job. The Run console displays
    the following result:

    tHMap_25.png

Generating the Output using tHMap with Multiple Payload Inputs

tHMap allows you to connect multiple payload inputs and generates
the output in a single result. In this scenario, you will learn how to create a Job with a
tHMap connected to a multiple inputs.

This scenario applies only to Talend Data Management Platform, Talend Big Data Platform, Talend Real Time Big Data Platform, Talend Data Services Platform, Talend MDM Platform and Talend Data Fabric.

Prerequisites

  • Download the attached sample payload input file. See the
    Download tab and save the file in your local
    machine.
  • Download the sample payload structure and import it to the Hierarchical Mapper > Structure list. See the Download tab and save the
    file in your local machine.

Creating the Payload tHMap Job

The Payload tHMap Job contains three types of components – tFileInputRaw, tHMap, and
tLogRow.

In Talend Studio, create the Payload tHMap Job:

tHMap_26.png
  1. Create a Standard Job and name it
    thm_payload.
  2. Add the following components:

    • two FileInputRaw
    • tHMap
    • tLogRow
  3. Connect the components using the Row > Main connection as shown in the previous image.
  4. When prompted for the output name, enter aa.

Configuring tFileInputRaw

tFileInputRaw reads all data in a raw file and sends the data to a
single output column for subsequent processing by another component.

  1. Double-click the first tFileInputRaw to display the
    Component tab.
  2. Specify the file path of the payload input file you downloaded earlier in the
    Filename field as shown below:

    tHMap_27.png

  3. Repeat steps 1-2 for the second tFileInputRaw
    component.

Configuring tLogRow

tLogRow displays data or results in the Run console. In this
scenario, use the tLogRow component to connect to
tHMap.

  1. Select the tLogRow component to display the
    Component tab.
  2. Click Edit schema to display the Schema of
    tLogRow
    window.
  3. Add two columns in both the Input and Output tables as shown below:

    tHMap_28.png

Configuring tHMap

tHMap executes transformations between sources and destinations. In this scenario,
use an existing hierarchical mapper structure, test_payload, which is attached in the
Download tab.

  1. Double-click tHMap to display the tHMap
    Structure Generate/Select
    window.
  2. Click Select an existing hierarchical mapper structure
    for row1 input connection. Click Next.
  3. Select the test_payload structure that you have
    downloaded and imported previously from Hierarchical Mapper > Structures. Click Next.
  4. Repeat steps 2-3 for the row2 input connection. Click
    Next twice.
  5. Select Generate hierarchical mapper structure based on the
    schema
    option for the aa ouput connection. Click
    Next.
  6. Click Finish to display the tHMap mapping.
  7. From the Input Map, drag and drop root/row1/root/x(1:*)/a
    to root/aa/aaRecord(0:*)/newColumn in the Output Map to
    create a connection.
  8. Select root/aa/aaRecord(0:*)/newColumn1 to display the
    Value tab.
  9. Drag and drop AgConcat function in the Value
    tab.
  10. From the Input Map, drag and drop root/row2/root/x(1:*)/b
    to the AgConcat function as shown below:

    tHMap_29.png

  11. Save the changes you made.

Running the Payload tHMap Job

After configuring the components and adding the connections, you can now execute the
Job to see the results in the Run console.

  1. Save the changes you made in the Job.
  2. Click Run to execute the Job. The
    Run console displays the following result:

    tHMap_30.png

Migrating from DatabaseLookup to tHMap

If you have Jobs that use the deprecated DatabaseLookup functionality, you can
migrate these to use the multi-input feature of tHMap.

Prerequisites

This procedure provides you an example of how you import Oracle databases to Talend Studio and create input connections
to the tHMap component.

  • You have a Talend Data Mapper Structure
    created from a database connection.
  • You have a Talend Data Mapper Map,
    where the output element is the output of a DatabaseLookup using the database
    tables imported in Talend Data Mapper.
    See the following example:

    tHMap_31.png
  • If you wish to use the attached sample project from the
    Downloads tab, you need to create databases using the
    sample database scripts in your local server.

Importing the Database Tables

Manually perform the migration by importing the database tables to Talend
Studio.

  1. Create a new database connection in Metadata > Db Connections.
  2. Select Retrieve Schema from the new DB
    Connection
    menu.
  3. Select the table schemas to import.

    tHMap_32.png

Configuring the tHMap

Create a new Job that includes the tHMap component, where you can connect the
imported database tables.

  1. Create a new Job.

    tHMap_33.png

  2. Drag-and-drop the database tables from the Db
    Connections
    and select
    tOracleInput.
  3. Add the following components:

    • tHMap
    • tLogRow
  4. Connect the following components using the Row > Main connection:

    • tOracleInputdatabase connections to the
      tHMap
    • tHMap to the tLogRow
  5. Enter xmlout when prompted for an output name.
  6. Double-click tHMap to display the Structure
    Generate/Select window.
  7. Select the Generate hierarchical mapper structure based on the
    schema
    option to automatically generate Structures.

Migrating the DatabaseLookup to AgConcat

Now that you have successfully configured tHMap, Talend Data Mapperautomatically generates a new map with
multiple records that represent the database input connections.

  1. Select tHMap to show the Input Map and Output XML panes.
    See that the Input pane contains the imported database tables:

    tHMap_34.png

  2. Use the AgConcat function to replace the deprecated
    DatabaseLookup function:

    1. Drag the row2 from the Input (Map) column to the
      AgConcat expression.
    2. Set SimpleLoop on the Loop
      Expression
      .
    3. Use the same filter values. If you have specified filter values in your
      Job using the deprecated DatabaseLookup function, re-use these filter
      values.
    tHMap_35.png

Specifying a map variable and alternate map in tHMap

The Map Variable parameter in tHMap allows you to specify a
contextual variable that contains a path to a map.

This example shows you how you can build a Job using the tHMap component, where you
specify a map variable and an alternate contextual map.

tHMap_36.png

Prerequisites

  • Ensure that you have created several contextual maps. In this example scenario,
    use three alternate contextual maps.

    tHMap_37.png
  • In your local machine, create a text file with the following content, where
    my_map refers to the Map Variable name,
    job_with_tContextLoad refers to the Job name and
    thMap_1_c refers to the Alternate Contextual Map
    name:

    Ensure that you replace the values according to the names of the Map
    variable, the Job, and the Alternate Contextual Map you created.

Creating the Job

Create a Job that includes tHMap, tFileInputRaw, tFileInputDelimited, tContextLoad,
and tLogRow.

  1. Create a Standard Job to add the following components:

    • tFileInputRaw
    • tHMap
    • tLogRow
    • tFileInputDelimited
    • tContextLoad
    Note: tContextLoad allows the contextual variable value to change at runtime.
    This component uses a predefined schema with two columns
    (key, value), where
    key refers to the name of the contextual variable and
    value refers to the new value of the corresponding
    variable.

  2. Connect the components using the Row > Main connection.

    tHMap_36.png

  3. Enter out when prompted for the output name.

Configuring the Components

Before executing the Job, configure the components to add the required configuration
details.

  1. Add three columns in the tRowGenerator component:

    tHMap_39.png

  2. Add three columns in the out(Input) and
    tLogRow(Output) tables in the
    tLogRow component:

    tHMap_40.png

  3. Specify the text file that you have previously created earlier in the
    File name/Stream field of the
    tFileInputDelimited component. See the Prerequisite for more information.
  4. Enter details in the Map Variable and
    Alternate contextual Map(s) fields in the
    Advanced settings menu of
    tHMap.

    tHMap_41.png

  5. Double-click tHMap to display the tHMap
    Structure Generate/Select
    window. For both the Input and Output
    Structures, select Generate hierarchical mapper structure based on
    the schema
    .
  6. Map the input rows to the output rows in the tHMap
    Structure
    :

    tHMap_42.png

Executing the Job

Running the Job automatically exports the referenced contextual maps.

Click Run to execute the Job:

tHMap_43.png

Migrating IO Database functions to tHMap Multi-Output Database Connections

tHMap supports multiple output connections. If you have previously created a Job
using the IO Database functions, you can migrate these into using the multi-output
feature.

Prerequisites

  • You have previously created Talend Data Mapper Structures from a
    database connection.
  • You have a Talend Data Mapper Map that
    uses a wrapped multi-table structure with a DatabaseInsert or DatabaseUpdate
    IO/Database output function for each table.
  • If you wish to use the attached sample project from the
    Downloads tab, you need to create
    databases using the sample database scripts in your local server.

Updating the Map

To start the migration process, you need to change the output representation of the
Map.

  1. Double-click tHMap to display the Input and Output tables.
  2. Replace each DatabaseInsert or
    DatabaseUpdate function with a
    WriteURL function:

    tHMap_44.png

Migrating the Job

Add the databases to the tHMap as output connections.

  1. Right-click Metadata > Db Connections and select Create connection to add a new
    database connection.
  2. Right-click the newly created database connection and select
    Retrieve Schema. Import the necessary schemas.
  3. In the existing Job, drag-and-drop the database connection and select the
    connection component. In this example, use
    tOracleConnection and connect using the Trigger > On Subjob OK connection:

    tHMap_45.png

  4. Drag-and-drop the database tables in the Job and select its corresponding
    output component. In this example, use
    tOracleOutput.
  5. Connect each output component using the Row > Main connection. For the output name, enter the same database table
    name from the Talend Data Mapper Map’s Output Structure.

    When you open the tHMap Map Editor, note that there are no synchronization
    checks or proposals provided even after adding the output connections. To
    synchronize the database table’s schema update on the Structure, see Syncing Database Table
    Schemas
    .
  6. Add tOracleCommit and connect it to the
    tHMap using the Trigger > OnComponentOk.
  7. Run the Job and check the data of the database tables accordingly.

Syncing Database Table Schemas

Reload the changes made in the database table schemas.

  1. Right-click the database connection you created in Metadata > Db Connections and select Retrieve Schema.
  2. Double-click the database output component,
    tOracleOutput, in the Job to display the
    Component tab.

    1. Select Edit Schema.
    2. Sync the columns accordingly.
  3. Go to the Mapping view and access Hierarchical Mapper > Databases.

    1. Right-click on the database you created.
    2. Select [Re]Load Table Definitions.
  4. Access Hierarchical Mapper > Maps.

    1. Select the appropriate Job.
    2. Right-click on the tHMap and select
      Synchronize with Structures.

Document get from Talend https://help.talend.com
Thank you for watching.
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x