Scenario: Validating data against schema - 6.1

Talend Components Reference Guide

Talend Big Data
Talend Big Data Platform
Talend Data Fabric
Talend Data Integration
Talend Data Management Platform
Talend Data Services Platform
Talend ESB
Talend MDM Platform
Talend Open Studio for Big Data
Talend Open Studio for Data Integration
Talend Open Studio for Data Quality
Talend Open Studio for ESB
Talend Open Studio for MDM
Talend Real-Time Big Data Platform
Data Governance
Data Quality and Preparation
Design and Development
Talend Studio

This scenario presents a Job that checks the type, nullability and length of data from an incoming flow against a defined reference schema, and displays the validation results on the Run console.

The incoming flow comes from a simple CSV file that contains heterogeneous data including wrong data type, data exceeding the maximum length, wrong ID and null values in non-nullable columns, as shown below:

8;Ulysses;04-12-2008;;Saint Paul

Setting up the Job

  1. Drop the following components: a tFileInputDelimited, a tSchemaComplianceCheck, and two tLogRow components from the Palette to the design workspace.

  2. Connect the tFileInputDelimited component to the tSchemaComplianceCheck component using a Row > Main connection.

  3. Connect the tSchemaComplianceCheck component to the first tLogRow component using a Row > Main connection. This output flow will gather the valid data.

  4. Connect the tSchemaComplianceCheck component to the second tLogRow component using a Row > Rejects connection. This second output flow will gather the non-compliant data. It passes two additional columns to the next component: ErrorCode and ErrorMessage. These two read-only columns provide information about the rejected data to ease error handling and troubleshooting if needed.

Configuring the components

  1. Double-click the tFileInputDelimited component to display its Basic settings view and define the basic parameters including the input file name and the number of header rows to skip.

  2. Click the [...] button next to Edit schema to describe the data structure of the input file. In this use case, the schema is made of five columns: ID, Name, BirthDate, State, and City.

  3. Fill the Length field for the Name, State and City columns with 7, 10 and 10 respectively. Then click OK to close the schema dialog box and propagate the schema.

  4. Double-click the tSchemaComplianceCheck component to display its Basic settings view, wherein you will define most of the validation parameters.

  5. Select the Custom defined option in the Mode area to perform custom defined checks.

    In this example, we use the Checked columns table to set the validation parameters. However, you can also select the Check all columns from schema check box if you want to perform all the checks (type, nullability and length) on all the columns against the base schema, or select the Use another schema for compliance check option and define a new schema as the expected structure of the data.

  6. In the Checked Columns table, define the checks to be performed. In this use case:

    - The type of the ID column should be Int.

    - The length of the Name, State and City columns should be checked.

    - The type of the BirthDate column should be Date, and the expected date pattern is dd-MM-yyyy.

    - All the columns should be checked for null values, so clear the Nullable check box for all the columns.


    To send rows containing fields exceeding the defined maximum length to the reject flow, make sure that the Trim the excess content of column when length checking chosen and the length is greater than defined length check box is cleared.

  7. In the Advanced settings view of the tSchemaComplianceCheck component, select the Treat all empty string as NULL option to sent any rows containing empty fields to the reject flow.

  8. To view the validation result in tables on the Run console, double-click each tLogRow component and select the Table option in the Basic settings view.

Executing the Job

  • Save your Job and press F6 to launch it.

    Two tables are displayed on the console, showing the valid data and rejected data respectively.