Hadoop 如何使用Pig在同一个键的列表中存储不同的值

Hadoop 如何使用Pig在同一个键的列表中存储不同的值,hadoop,apache-pig,Hadoop,Apache Pig,我有一个用例 col1|col2 a101|10 a101|20 a101|10 a101|30 a201|40 a201|50 预期产出: a101 |列表 a201 |列表 下面是查询,但我没有得到预期的输出。我想在列表中存储col2不同的值 input1= load 'list1.csv' using PigStorage('|') as (col1: chararray, col2: int); input2 = DISTINCT (FOREACH input1 generate co

我有一个用例

col1|col2
a101|10
a101|20
a101|10
a101|30
a201|40
a201|50
预期产出:

a101 |列表

a201 |列表

下面是查询,但我没有得到预期的输出。我想在列表中存储col2不同的值

input1= load 'list1.csv' using PigStorage('|') as (col1: chararray, col2: int);
input2 = DISTINCT (FOREACH input1 generate col1,col2);
input3 = GROUP input2 by col1;
dump input3;
(a101,{(a101,30),(a101,20),(a101,10)})
(a201,{(a201,50),(a201,40)})
试试这个:

input1= load 'input.txt' using PigStorage('|') as (col1: chararray, col2: int);
input2 = DISTINCT input1; --distinct not required but will remove duplicate rows 
input3 = GROUP input2 by col1;
data = FOREACH input3 GENERATE FLATTEN(group) as col1, input2.col2 AS col2;
DUMP data;
生成的输出:

(a101,{(30),(20),(10)})
(a201,{(50),(40)})