replacing values in pig latin

感情迁移 提交于 2019-12-23 02:49:09

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!