Reputation: 11619
I would like to pick up different field if an intended field is empty (null) in a FOREACH
statement. Is something like NULLIF
(from SQL) in Pig?
Upvotes: 0
Views: 670
Reputation: 5186
It sounds like you are looking for a bincond and null operators. You can use it like:
DUMP A ;
-- (foo,)
-- (,bar)
-- (bing,bang)
-- (,)
-- (bosh,)
B = FOREACH A GENERATE ($0 is not null? $0 : $1) AS result ;
DUMP B ;
-- (foo)
-- (bar)
-- (bing)
-- () <-- Note this value is a null
-- (bosh)
Upvotes: 1