Question

I have to check the below condition in pig script. Is there a easy way code the below conditional statement in PIG.

if VAR1 == 'A' OR 'B' OR 'C' OR 'D'
   VAR1 = ' ' 
else 
   VAR1 = 'Z'
end if

I can use the below statement to achieve this, but is there a easy way to check the below condition.

VAR1 = (VAR1 == 'A' OR VAR1 == 'B' VAR1 == OR 'C' OR VAR1 == 'D') ? ' ' : 'Z';
Was it helpful?

Solution

I believe this will work for you:

INDEXOF('ABCD', VAR1) > -1 ? ' ' : 'Z'

INDEXOF() will return -1 if VAR1 isn't found in the string.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top