Skip to main content Skip to complementary content

Validating data against schema

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:
ID;Name;BirthDate;State;City
1;Dwight;06-04-2008;Delaware;Concord
2;Warren;25-10-2008;Montana
3;Benjamin;17-08-2008;Washington;Austin
4;Harry;14-04-2008;Kansas;Annapolis
5;Ulysses;2007-04-12;Michigan;Raleigh
6;James;19-08-2007;Delaware;Charleston
.7;Bill;20-04-2007;Illinois;Bismarck
8;Ulysses;04-12-2008;;Saint Paul
9;Thomas;09-05-2008;Maryland;Albany
10;Ronald;11-02-2008;Florida;Hartford

This scenario applies only to Talend Data Management Platform, Talend Big Data Platform, Talend Real-Time Big Data Platform, Talend MDM Platform, Talend Data Services Platform, Talend MDM Platform and Talend Data Fabric.

Setting up the Job

Procedure

  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 one tLogRow component using a Row > Main connection. This output flow will gather the valid data.
  4. Connect the tSchemaComplianceCheck component to the other tLogRow component using a Row > Rejects connection. This 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.
    A Job using the tFileInputDelimited, tSchemaComplianceCheck, and two tLogRow components.

Configuring the components

Procedure

  1. Double-click the tFileInputDelimited component to display its Basic settings view.
  2. Define the basic parameters including the input file name and the number of header rows to skip.
    Configuration of the tFileInputDelimited component.
  3. Click the [...] button next to Edit schema to describe the data structure of the input file. In this example, the schema is made of five columns: ID, Name, BirthDate, State, and City.
  4. Fill the Length field for the Name, State, and City columns with 7, 10 and 10 respectively.
    Schema of the tFileInputDelimited component.
  5. Click OK.
  6. Double-click the tSchemaComplianceCheck component to display its Basic settings view.
  7. Define the validation parameters.
    Configuration of the tSchemaComplianceCheck component.
  8. In the Mode area, select the Custom defined option to perform custom defined checks.
    In this example, you 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.
    • Use another schema for compliance check option and define a new schema as the expected structure of the data.
  9. In the Checked Columns table, define the checks to be performed. In this example:
    • The type of the ID column should be Int|Integer.
    • 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.
    Information noteTip: To send rows containing fields exceeding the defined maximum length to the reject flow, clear the Trim the excess content of column when length checking chosen and the length is greater than defined length check box.
  10. 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.
  11. 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

Procedure

Save your Job and press F6 to launch it.
Two tables are displayed on the console, showing the valid data and rejected data respectively.
Results from the Console.

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!