输入数据集:
field1,field2,field3,field4,field5
101,a1,a11,a111,a1111
102,a1,a11,a111,a1111
103,a1,a11,a111,a1111
201,b1,b11,b111,b1111
202,b1,b11,b111,b1111
以下查询将在Pig中提供不同的记录。
details = load 'emp.csv' using PigStorage(',') AS (field1:chararray,field2:chararray,field3:chararray,field4:chararray,field5:chararray);
distinct_detials = DISTINCT details;
我有一个用例,我需要根据field2,field3,field4获取不同的记录。
预期输出
101,a1,a11,a111,a1111
202,b1,b11,b111,b1111
答案 0 :(得分:0)
您可以使用嵌套的foreach来完成您想要的任务:
details = load 'emp.csv' using PigStorage(',') AS (field1:chararray,field2:chararray,field3:chararray,field4:chararray,field5:chararray);
distinct_detials = foreach (GROUP details by (field2, field3, field4) ) {
temp_rel = details.(field1, field5);
temp_limit = LIMIT temp_rel 1;
generate FLATTEN(temp_limit) as (field1, field5), FLATTEN(group) as (field2, field3, field4);
}
DUMP distinct_details;
这将提供以下输出:
(103,a1111,a1,a11,a111)
(202,b1111,b1,b11,b111)
您可以在foreach
上进一步使用distinct_details
按顺序显示字段。