Looking up values in a database - 7.3

Talend Data Mapper User Guide

Version
7.3
Language
English
Product
Talend Big Data Platform
Talend Data Fabric
Talend Data Management Platform
Talend Data Services Platform
Talend MDM Platform
Talend Real-Time Big Data Platform
Module
Talend Studio
Content
Design and Development > Designing Jobs
Last publication date
2023-01-05

Create a map and use a DatabaseLookup function to get values from a database.

Before you begin

  • You have created an input and an output structure.
  • You have created a connection to your database.

About this task

In this example, two nearly identical JSON files are mapped and one element needs to retrieve its value from a database.

Procedure

  1. In the Hierarchical Mapper, right-click Maps and click New > Map.
  2. Select Standard Map and click Next.
  3. Select a folder and enter a name for your map, then click Finish.
  4. Drag your input and output structures in the map.
  5. Map your elements.

    Example

    In this example, you can drag the input order root on the output order to automatically map all the elements present in both structures.

  6. In the Functions tab, select General > DatabaseLookup and drag it to the Value tab of the country_code element.
  7. In the window that opens, select the database column from which you want to retrieve a value, then click OK.

    Example

  8. Add a condition. If you want to get the country code that matches the country in the input structure, for example, configure it as follows:
    1. Drag an Equal function on the Condition.
    2. Drag the input country element on the First Value.
    3. Drag a DatabaseColumn function on the Second Value.
    4. Select the database column containing the name of the country, NICENAME in this example.

    Example

Results

Your map is now configured and you can test it with a sample document using the Test Run option. In this example, the result looks like this: