O'Reilly logo

Talend Open Studio Cookbook by Rick Barton

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using the ternary operator for conditional logic

The previous recipe mentions that a tMap expression cannot be more than a single line of Java code. This means that we cannot use the normal if-then-else logic to test for conditions.

Fortunately, Java does provide a mechanism by which we can perform tests on a single line: the ternary expression.

Getting ready

Open the job jo_cook_ch04_0030_ternaryExpressions.

How to do it...

We'll be looking at two similar scenarios using the ternary expression.

Single ternary expression: if-then-else

  1. Open tMap and click the output singleTernaryLocality column.
  2. Enter the following code:
    customer.countryOfBirth.equals("UK") ? "UK" : "RestOfWorld"
  3. Run the job. You will see that all countries apart from the UK have a locality ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required