Defining the record filter component - Cloud - 7.3

Talend Job Script Reference Guide

Version
Cloud
7.3
Language
English
Product
Talend Big Data
Talend Big Data Platform
Talend Cloud
Talend Data Fabric
Talend Data Integration
Talend Data Management Platform
Talend Data Services Platform
Talend ESB
Talend MDM Platform
Talend Real-Time Big Data Platform
Module
Talend CommandLine
Talend Studio
Content
Design and Development > Designing Jobs
Last publication date
2023-09-13

Procedure

  1. Next to the tFilterColumns component definition, enter another addComponent {} function and its setComponentDefinition {} sub-function to add the tFilterRow component.
    // filter records - accept men between 10 and 80 whose names are shorter than 9 characters
    addComponent {
    	setComponentDefinition {
    		TYPE: "tFilterRow",
    		NAME: "tFilterRow_1",
    		POSITION: 640, 224
    	}
    }
  2. Next to the setComponentDefinition {} function, enter the setSettings {} function to define the filter conditions and label the component.
    	setSettings {
    		LOGICAL_OP : "&&",
    		CONDITIONS {
    			INPUT_COLUMN : "name",
    			FUNCTION : "$source == null? false : $source.length() $operator $target",
    			OPERATOR : "<",
    			RVALUE : "9",
    			INPUT_COLUMN : "gender",
    			FUNCTION : "",
    			OPERATOR : "==",
    			RVALUE : "\"M\"",
    			INPUT_COLUMN : "age",
    			FUNCTION : "",
    			OPERATOR : ">",
    			RVALUE : "10",
    			INPUT_COLUMN : "age",
    			FUNCTION : "",
    			OPERATOR : "<",
    			RVALUE : "80"
    		},
    		LABEL : "filter_records"
    	}
    Warning:

    Be sure to use a backslash (\) when specifying a metacharacter.

  3. Next to the setSettings {} function, enter the following script code to define the schemas for the output flows.

    In this example, the tFilterRow component has two output flows, one for accepted records, which has the same schema structure as defined in the previous component, tFilterColumns, and the other for rejected records, which has one more column, errorMessage. The errorMessage column is mandatory for the reject flow and it has fixed properties - even if you don't define this column, the Studio will automatically add it when generating the Job.

    	// define the schema for the accepted records
    	addSchema {
    		NAME: "ACCEPT",
    		CONNECTOR: "FILTER"
    		addColumn {
    			NAME: "name",
    			TYPE: "id_String"
    		}
    		addColumn {
    			NAME: "gender",
    			TYPE: "id_String"
    		}
    		addColumn {
    			NAME: "age",
    			TYPE: "id_Integer",
    			LENGTH: 2
    		}
    		addColumn {
    			NAME: "city",
    			TYPE: "id_String"
    		}
    	}
    	
    	// define the schema for the rejected records
    	addSchema {
    		NAME: "REJECT",
    		CONNECTOR: "REJECT"
    		addColumn {
    			NAME: "name",
    			TYPE: "id_String"
    		}
    		addColumn {
    			NAME: "gender",
    			TYPE: "id_String"
    		}
    		addColumn {
    			NAME: "age",
    			TYPE: "id_Integer",
    			LENGTH: 2
    		}
    		addColumn {
    			NAME: "city",
    			TYPE: "id_String"
    		}
    		addColumn {
    			NAME: "errorMessage",
    			TYPE: "id_String",
    			NULLABLE: true,
    			LENGTH: 255,
    			PRECISION: 0
    		}
    	}