问题
I have a dataset in form:
id1, id2, id3
Either of id1,id2 or id3 (or all three.. or any two) can be missing in a record.
Now if id1 is missing I want to replace it with 1
id2 by 3
id3 by 7
How do I do this. Thanks
回答1:
Use the bincond operator to test if the value is null and then replace it with the desired value. From Programming Pig, Chapter 5:
2 == 2 ? 1 : 4 --returns 1
2 == 3 ? 1 : 4 --returns 4
null == 2 ? 1 : 4 -- returns null
2 == 2 ? 1 : 'fred' -- type error, both values must be of the same type
In your example,
id2 IS NULL ? 3 : id2
来源:https://stackoverflow.com/questions/13386609/replacing-values-in-pig-latin