Scenario 1: Filtering a list of names using simple conditions - 6.3

Talend Open Studio for Big Data Components Reference Guide

EnrichVersion
6.3
EnrichProdName
Talend Open Studio for Big Data
task
Data Governance
Data Quality and Preparation
Design and Development
EnrichPlatform
Talend Studio

The following scenario shows a Job that uses simple conditions to filter a list of records. This scenario will output two tables: the first will list all male persons with a last name shorter than nine characters and aged between 10 and 80 years; the second will list all rejected records. An error message for each rejected record will display in the same table to explain why such a record has been rejected.

Dropping and linking components

  1. Drop tFixedFlowInput, tFilterRow and tLogRow from the Palette onto the design workspace.

  2. Connect the tFixedFlowInput to the tFilterRow, using a Row > Main link. Then, connect the tFilterRow to the tLogRow, using a Row > Filter link.

  3. Drop tLogRow from the Palette onto the design workspace and rename it as reject. Then, connect the tFilterRow to the reject, using a Row > Reject link.

  4. Label the components to better identify their roles in the Job.

Configuring the components

  1. Double-click tFixedFlowInput to display its Basic settings view and define its properties.

  2. Click the [...] button next to Edit schema to define the schema for the input data. In this example, the schema is made of the following four columns: LastName (type String), Gender (type String), Age (type Integer) and City (type String).

    When done, click OK to validate the schema setting and close the dialog box. A new dialog box opens and asks you if you want to propagate the schema. Click Yes.

  3. Set the row and field separators in the corresponding fields if needed. In this example, use the default settings for both, namely the row separator is a carriage return and the field separator is a semi-colon.

  4. Select the Use Inline Content(delimited file) option in the Mode area and type in the input data in the Content field.

    The input data used in this example is shown below:

    Van Buren;M;73;Chicago
    Adams;M;40;Albany
    Jefferson;F;66;New York
    Adams;M;9;Albany
    Jefferson;M;30;Chicago
    Carter;F;26;Chicago
    Harrison;M;40;New York
    Roosevelt;F;15;Chicago
    Monroe;M;8;Boston
    Arthur;M;20;Albany
    Pierce;M;18;New York
    Quincy;F;83;Albany
    McKinley;M;70;Boston
    Coolidge;M;4;Chicago
    Monroe;M;60;Chicago
  5. Double-click tFilterRow to display its Basic settings view and define its properties.

  6. In the Conditions table, add four conditions and fill in the filtering parameters.

    • From the InputColumn list field of the first row, select LastName, from the Function list field, select Length, from the Operator list field, select Lower than, and in the Value column, type in 9 to limit the length of last names to nine characters.

    • From the InputColumn list field of the second row, select Gender, from the Operator list field, select Equals, and in the Value column, type in M in double quotes to filter records of male persons.

      Warning

      In the Value field, you must type in your values between double quotes for all types of values, except for integer values, which do not need quotes.

    • From the InputColumn list field of the third row, select Age, from the Operator list field, select Greater than, and in the Value column, type in 10 to set the lower limit to 10 years.

    • From the InputColumn list field of the four row, select Age, from the Operator list field, select Lower than, and in the Value column, type in 80 to set the upper limit to 80 years.

  7. To combine the conditions, select And as that only those records that meet all the defined conditions are accepted.

  8. In the Basic settings of tLogRow components, select Table (print values in cells of a table) in the Mode area.

Executing the Job

  • Save your Job and press F6 to execute it.

    As shown above, the first table lists the records of male persons aged between 10 and 80 years, whose last names are made up of less than nine characters, and the second table lists all the records that do not match the filter conditions. Each rejected record has a corresponding error message that explains the reason of rejection.