Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PIG script IF ELSE statement

Does pig script support if-else statement

here is what I want to do:

if($NAME=='Joey') Do something else Do something

is that doable?

Thanks

like image 529
RhysJ Avatar asked Oct 18 '25 13:10

RhysJ


1 Answers

Its Called a "Bincond" Operator

Statements Like:

(Price > 75 ? 'High':'Low')  

are also valid

For Handling Null Records:

((Name is null or IsEmpty(Name)) ? {('unknown')} : Name)

Use them in a foreach statement with alias along other fields i.e:

A = load 'x/y/Price.csv' as (Name, Product, Price);
B = foreach A generate Name, Product, Price, (Price > 75 ? 'High':'Low') as Indicator;

dump B;
like image 113
Varun Tandra Avatar answered Oct 22 '25 01:10

Varun Tandra