Skip to main content Skip to complementary content

Using a basic validation rule

After setting up a validation rule, you can apply it on your Job designs. For example, let's apply a basic check for correct values validation rule when reading a database table. This scenario is based on the basic check validation rule created in the Basic rule section of Talend Studio User Guide.

Setting up the Job environment for a basic validation rule

Procedure

  1. From the Palette, place these components onto the design workspace: a database input component, here tMysqlInput, that you will read and check the values of, two tFileOutputDelimited components to extract the valid data in one file and the rejected ones in another file, and a tJava component to display the number of lines processed in the console.
  2. Connect the input database component to the first tFileOutputDelimited component using a Row > Main connection, and connect the tMysqlInput component to the tJava component with a Trigger > OnSubjobOk connection.
    Information noteNote:

    You will be able to create the reject link between the tMysqlInput and the second tFileOutputDelimited component only when you will have applied the validation rule to the tMysqlInput component.

    Screenshot of the Job in the Designer.

Configuring tMysqlInput

Procedure

  1. Double-click the tMysqlInput component to display its Basic settings.
    Screenshot of the component basic settings.
  2. Select Repository as Property type and click the three-dot button next to the field to retrieve the connection properties that corresponds to the metadata you want to check.
  3. Select Repository from the Schema drop-down list and click the three-dot button next to the field to retrieve the schema that corresponds to your database table.
  4. Click the three-dot button next to the Table field to select the table to check.
  5. Click Guess Query to automatically retrieve the query corresponding to the table schema.

Configuring the output components and viewing the Job execution result

Procedure

  1. Double-click the first tFileOutputDelimited component to display its Basic settings.
    Screenshot of the component basic settings.
  2. In the File Name field, specify the path and name of the file to write with the valid data.
  3. Define the row and field separators in the corresponding fields.
  4. Select the Include Header check box to include column headers in the output data.
  5. Repeat the steps above on the second tFileOutputDelimited component to configure the output of the rejected data.
    Screenshot of the component basic settings.
  6. Double-click the tJava component to display its Basic settings.
    Screenshot of the component basic settings.
  7. In the Code field, type in the code that will display the number of updated, inserted, and rejected lines processed:
    System.out.println("Valid data: "+((Integer)globalMap.get("tFileOutputDelimited_1_NB_LINE"))+"\nRejected
    data: "+((Integer)globalMap.get("tFileOutputDelimited_2_NB_LINE")));
  8. Save your Job and press F6 to execute it.
    Screenshot of the console after successfully running the Job.

Results

Valid data is outputted in the first delimited file and rejects to the second, and the console displays the number of valid lines and the number of rejects processed in the Job.

Did this page help you?

If you find any issues with this page or its content – a typo, a missing step, or a technical error – please let us know!