Joining Two Data Sources With The Tmap
Joining Two Data Sources With The Tmap
1. Joining two data sources with the tMap component in Talend Studio
1. Creating a Talend Studio project
2. Creating a Job to join data sources
3. Data joining using the tMap component
1. Creating a metadata definition for the tMap component
2. Configuring a tMap component to join two data sources
3. Exporting the results of data joined using a tMap component
4. Configuring joins in the tMap component
1. Configuring a tMap component join model
2. Exporting the results of a tMap component inner join
5. Configuring filters in a tMap component
1. Configuring a tMap component filter by years
2. Configuring a tMap component filter to catch rejects, and exporting to XML
Joining two data sources with the tMap component in Talend Studio
In this tutorial, discover how to join two data sources with the tMap component in Talend Studio.
This tutorial makes use of a .csv file. If you do not have a .csv file, download the following folder and extract the file: movies.zip.
This tutorial also makes use of another delimited file. If you do not have another delimited file, download and extract the following
file: directors.zip.
Procedure
Example
https://help.talend.com/internal/api/webapp/print/63fa9007-e7c9-4eb6-b641-96f756a2fa2b 1/11
19/04/24, 15:38 PDF Export
TalendDemo
3. Click Create.
4. Click Finish.
Results
Procedure
Example
tMapJoin
Example
Example
Using the tMap component to turn two different data sources into one
5. Click Finish.
Results
Creating a metadata definition allows you to set up reusable information across all of your components.
This tutorial makes use of a delimited file. If you do not have a delimited file, download and extract the following file: directors.zip.
Procedure
https://help.talend.com/internal/api/webapp/print/63fa9007-e7c9-4eb6-b641-96f756a2fa2b 2/11
19/04/24, 15:38 PDF Export
1. In the Repository, expand Metadata then right-click File delimited and click Create file delimited.
Example
directors
Example
Joining the directors data to the movies database
Example
5. Click Next.
6. Click Browse, select the file of your choice in the File Explorer.
https://help.talend.com/internal/api/webapp/print/63fa9007-e7c9-4eb6-b641-96f756a2fa2b 3/11
19/04/24, 15:38 PDF Export
Example
Under File Settings, select your Field Separator and change it, if needed.
Tip: Under Preview, click Refresh Preview to check the parsing results.
8. Click Next.
Example
directorsSchema
10. Update the Schema so it is identical to the structure of the sample file.
Example
Change the name of Column0 to directorID and the name of Column1 to directorName .
Change the Length of directorID to 4 and the Length of directorName to 40 .
Results
In the Repository, under Metadata, you can find and use your metadata.
The tMap component allows you to transform and route data from single or multiple sources to single or multiple destinations. In
this case, discover how to join two data sources.
For the sake of demonstration, this tutorial uses two different metadata definitions: movies 0.1 and directors 0.1. To follow this
tutorial, you can:
You can also learn how to create both metadata definitions (see Creating a metadata definition for the tMap component).
Procedure
1. Drag-and-drop the movies 0.1 and directors 0.1 metadata on the Designer.
a. In both cases, select a tFileInputDelimited component.
https://help.talend.com/internal/api/webapp/print/63fa9007-e7c9-4eb6-b641-96f756a2fa2b 4/11
19/04/24, 15:38 PDF Export
Example
joinedOutput
8. Click OK.
9. In input table row1, select columns movieID, title, releaseYear, url then drag-and-drop them in output table JoinedOutput.
a. Select column directorID then drag-and-drop it in row2, under Expr. key, next to directorID.
10. In input table row2, select column directorsName then drag-and-drop it in output table JoinedOutput.
Results
The tLogRow component displays a table with the joined data of movies 0.1 and directors 0.1.
https://help.talend.com/internal/api/webapp/print/63fa9007-e7c9-4eb6-b641-96f756a2fa2b 5/11
19/04/24, 15:38 PDF Export
Once that you have joined data using the tMap component (see Configuring a tMap component to join two data sources), you can
export it to a delimited file.
You must have joined two data sources (see Configuring a tMap component to join two data sources).
Procedure
4. In File Name, enter the path and name for the output file.
Results
The joined data is read by the tLogRow component and tFileOutputDelimited component, is displayed on the console and also
exported as a .csv file.
https://help.talend.com/internal/api/webapp/print/63fa9007-e7c9-4eb6-b641-96f756a2fa2b 6/11
19/04/24, 15:38 PDF Export
Many of the films available in the movies.zip file lack director data. You can choose to exclude these films from the joined database
with a tMap component join model.
You must have joined two data sources (see Configuring a tMap component to join two data sources).
Procedure
Results
This time, the exported joined data only includes the films that had a directorID.
After configuring a tMap component join model (see Configuring a tMap component join model), you can export it to a delimited file.
1. You must have joined two data sources (see Configuring a tMap component to join two data sources).
2. You must also have configured a tMap component join model (see Configuring a tMap component join model).
3. Begin by removing the tLogRow component added previously and connecting the tFileOutputDelimited component to the
tMap component instead.
Procedure
Example
joinRejects
b. Click OK.
https://help.talend.com/internal/api/webapp/print/63fa9007-e7c9-4eb6-b641-96f756a2fa2b 7/11
19/04/24, 15:38 PDF Export
3. In input table row1, select all columns then drag-and-drop them in output table joinRejects.
8. In File Name, enter the path and name for the output file.
https://help.talend.com/internal/api/webapp/print/63fa9007-e7c9-4eb6-b641-96f756a2fa2b 8/11
19/04/24, 15:38 PDF Export
Results
Talend Studio exports two files: one with films that have a directorID, and who that director is, and another with the movies without
a directorID.
The tMap component provides many possibilities of joining and filtering your data, including numerically.
For the sake of demonstration, this tutorial uses metadata definition: movies 0.1. To follow this tutorial, you can:
You can also learn how to create a metadata definition (see Creating a metadata definition for the tMap component).
Procedure
a. Enter moviesFromThe90s .
b. Click OK.
6. In input table row1, select all columns then drag-and-drop them in output table moviesFromThe90s.
https://help.talend.com/internal/api/webapp/print/63fa9007-e7c9-4eb6-b641-96f756a2fa2b 9/11
19/04/24, 15:38 PDF Export
Results
You have configured a numeric filter in the tMap component, allowing you to automatically sort a category of data.
What to do next
Create another output table: moviesFromThe80s. You can easily create a double condition by using the Java && operator (AND):
row1.releaseYear >=1980 && row1.releaseYear <1990 .
You must have configured a tMap component filter by years (see Configuring a tMap component filter by years).
Procedure
a. Enter a name.
Example
moviesBefore80s
b. Click OK.
3. In input table row1, select all columns then drag-and-drop them in output table moviesBefore80s.
https://help.talend.com/internal/api/webapp/print/63fa9007-e7c9-4eb6-b641-96f756a2fa2b 10/11
19/04/24, 15:38 PDF Export
Example
Example
moviesBefore80s.xml
Results
The Catch output reject Property collects all rows of data which do not match either of the other two conditions, meaning all movies
from before 1980. In customers_unordered.csv , there is only one: Agnès Varda's Cleo from 5 to 7.
https://help.talend.com/internal/api/webapp/print/63fa9007-e7c9-4eb6-b641-96f756a2fa2b 11/11