Talend Open Studio Tutorials

 

Tutorial 8: Adding condition-based filters by using the tMap component

 

 

Adding condition-based filters by using the tMap component
 
In this tutorial, discover how to set filters on your tMap outputs and learn how to configure them.
 

This tutorial uses Talend Open Studio Data Integration version 6

 

1.  Create a new Job and add a tMap component

  1. In a new Job, add the movies metadata file as input delimited component.
  2. Add a tMap component to create new filters.
  3. Create a flow of data from the movies component to the tMap_1 component by linking the two components and rename the link as movies.

 

2.  Add a filter to select only movies that were released in 1990 or later

  1. To create a new output, double-click the tMap_1 component and in the output section of the tMap wizard, click the [+] button and name the output as moviesFromThe90s.
  2. Select all columns from the input movies, drag, and drop them to the output moviesFromThe90s output.
  3. To create a new condition-based filter, click the Activate Expression Filter
  4. To create a filter condition, click the releaseYear column and drop it on the expression filter field, and type >=1990.

 

3.  Store the result in a file

  1. Add a tFileOutputXML component to the Job.
  2. Link the Row > moviesFromThe90s output to the tFileOutputXML_1 component. Rename the tFileOutputXML_1 component movies>=1990.
  3. To configure the movies >= 1990 component, in the Component view of the component, specify the path and name for the output file.
  4. To rename the root document, in the Row tag field, type “movies” and run the Job.
  5. To check the moviesFromThe90s.xml file, navigate to the folder in which the file was created and open the file.

The file with the list of movies released in or after 1990 will be displayed.

 

4.  Create a second filter using two conditions

  1. Create a second filter that will filter movies from the 80s only.

Condition filters follow the Java syntax rules. You can easily create a double condition by using the java && operator (AND).

  1. Run the Job.

The file with the list of movies released from 1980 to 1989 will be displayed.

 

5.  Create a filter reject output

  1. To create a third filter, in the tMap_1 interface, add another output named moviesBefore80s and add all columns from the input movies to it.
  2. To create a filter reject output, click the tMap Settings
  3. Click the […] in the value field of Catch output reject property and click true.

This will collect all rows of data which do not match either of the other two conditions.

  1. Add a tFileOutputXML component named movies<1980, and link the moviesBefore80s row from tMap_1 to it.
  2. To configure the movies<1980 component, in the Component view, specify the path and name for the output file.
  3. Run the Job.
  4. To check the filterRejects.xml file, navigate to the folder in which the file was created and open it.

The file with the list of movies released before 1980 will be displayed.

 

← PREVIOUS TUTORIAL   |   NEXT TUTORIAL  →