我有一个包含此文件的文件:
id_v^id_f^id_s1,id_s2,id_s3,id_s4
id_v1^id_f1^id_s2,id_s3,id_s4
id_v2^id_f2^id_s2,id_s1,id_s4
此文件是“^”分隔的csv。 我想用猪这种方式将其标准化:
id_v^id_f^id_s1
id_v^id_f^id_s2
id_v^id_f^id_s3
id_v^id_f^id_s4
id_v1^id_f2^id_s2
id_v1^id_f2^id_s3
id_v1^id_f2^id_s4
...
任何人都可以帮助我吗?
此致
答案 0 :(得分:1)
确定。假设这是我的文件。假设文件名是id_v.txt
id_v^id_f^id_s1,id_s2,id_s3,id_s4
id_v1^id_f1^id_s2,id_s3,id_s4
id_v2^id_f2^id_s2,id_s1,id_s4
以下是Pig代码
A = load '/user/cloudera/inputfiles/id_v.txt' using PigStorage('^') as(v:chararray,f:chararray,data:chararray);
B = foreach A generate v,f,FLATTEN(TOKENIZE(data)) as data;
dump B;
以下是上述代码制作的O / P ..
(id_v,id_f,id_s1)
(id_v,id_f,id_s2)
(id_v,id_f,id_s3)
(id_v,id_f,id_s4)
(id_v1,id_f1,id_s2)
(id_v1,id_f1,id_s3)
(id_v1,id_f1,id_s4)
(id_v2,id_f2,id_s2)
(id_v2,id_f2,id_s1)
(id_v2,id_f2,id_s4)