Search icon CANCEL
Subscription
0
Cart icon
Close icon
You have no products in your basket yet
Save more on your purchases!
Savings automatically calculated. No voucher code required
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Talend Open Studio Cookbook

You're reading from  Talend Open Studio Cookbook

Product type Book
Published in Oct 2013
Publisher Packt
ISBN-13 9781782167266
Pages 270 pages
Edition 1st Edition
Languages
Author (1):
Rick Barton Rick Barton
Profile icon Rick Barton

Table of Contents (21) Chapters

Talend Open Studio Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
1. Introduction and General Principles 2. Metadata and Schemas 3. Validating Data 4. Mapping Data 5. Using Java in Talend 6. Managing Context Variables 7. Working with Databases 8. Managing Files 9. Working with XML, Queues, and Web Services 10. Debugging, Logging, and Testing 11. Deploying and Scheduling Talend Code 12. Common Mistakes and Other Useful Hints and Tips Common Type Conversions
Management of Contexts Index

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 of RestOfWorld.

Ternary in ternary: if-then-elsif-then-else

  1. Open tMap and click the output column multiTernaryLocality.

  2. Enter the following code:

    customer.countryOfBirth.equals("UK") ? "UK" : customer.countryOfBirth.equals("France") ? "Europe" : customer...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}