0

We have requirement of executing script based on Condition like

IF (true) //execute this statement ELSE //execute this statement

I heard IF else is not present but it can be implement using "?". Any sample around using of trinary operator and execute pig query based on condition

user145610
  • 2,949
  • 4
  • 43
  • 75
  • Its been anwered here http://stackoverflow.com/questions/17669522/is-there-any-conditional-if-like-operator-in-apache-pig – nobody Nov 25 '15 at 16:43

1 Answers1

0

You should use BinCond for that purpose.

For example:

A = LOAD 'your_data' USING PigStorage() AS (name:chararray);
B = FOREACH A GENERATE name, ( name == 'Bieber'? 1: 0) AS canadian_stars;

What we do is check if there is a string matches 'Bieber' in charraray name if yes we assign value 1, else 0.

Hope it helps!

madbitloman
  • 816
  • 2
  • 13
  • 21