Checking a column against a list of allowed values

Often it is necessary to ensure that a column contains only values as defined in a list. This recipe shows how this can be achieved using a tMap expression.

Getting ready

Open the job jo_cook_ch03_0040_tMapValuesInList. You will notice that the job is very similar to the previous recipe Rejecting rows using tMap.

How to do it…

  1. Open tMap and click the expression builder button (…), and add the test criteria, as shown in the following screenshot:
    How to do it…
  2. Run the job and you should see that one of the rows is rejected.

How it works…

The tMap conditions are the same as Java conditions, so the symbol || (pipe pipe) is a logical OR.

Thus, the condition checks for the value being UK or USA or France.

There's more…

This method is fine if the list is quite small and isn't liable to change. If the list is too large or subject to frequent changes, then the code will be hard to maintain and/or will need to be changed often, which will require re-testing of the code. In these cases, refer to the next recipe for a more suitable method.

See also

  • Checking a column against a lookup, in this chapter.
  • Rejecting rows using tMap, in this chapter.