Talend Open Studio Cookbook
上QQ阅读APP看书,第一时间看更新

Rejecting rows using tMap

This recipe shows how tMap can be used to ensure that unwanted rows are not propagated downstream. This may be as a result of the filter criteria or a validation rule.

Getting ready

Open the job jo_cook_ch03_0030_tMapRejects.

How to do it…

  1. Open the tMap and click the Activate/unactivate expression filter button for the validRows output.
  2. In the Expression box add the code customer.age >= 18.
    How to do it…
  3. Click on the tMapRejects output and then on the tMapSettings button.
  4. Click on Catch output reject value column to set it to true.
    How to do it…
  5. Run the job. You should see that one of the rows has been rejected.

How it works…

In this example, tMap is working like an if statement. Therefore, if customer's age is greater than eighteen, then write the record to validRows or else pass the data to the tMapRejects.

There's more…

You can use this method to test for multiple different rejects, by adding additional outputs and adding different filter criteria to each output.

The tMap component will process any number of filter criteria from top to bottom, so long as you remember to catch the output rejects for each additional output table.

Tip

Note that if you forget to set catch output rejects to true, then all the input records will be passed to all the outputs. Sometimes, this may be what you want to do, but in the case of the preceding exercise, forgetting to set the catch output rejects would result in rows being duplicated in both of the output streams.