Skip to main content Skip to complementary content

Defining the record filter component

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"
    	}
    Information noteWarning:

    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, Talend 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
    		}
    	}

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 – let us know how we can improve!