【发布时间】:2015-02-04 00:48:39
【问题描述】:
我在一个 txt 文件中有一个 MAP 的数据:
[age#27,height#5.8]
[age#25,height#5.3]
[age#27,height#5.10]
[age#25,height#5.1]
我想显示每个年龄段的平均身高。
这是LAOD 声明:
records = LOAD '~/Documents/Pig_Map.txt' AS (details:map[]);
records: {details: map[]}
然后我根据年龄对数据进行分组:
group_data = GROUP records BY details#'age';
group_data: {group: bytearray,records: {(details: map[])}}
为了访问details,我做了一个像这样的FLATTEN(不知道我是否需要这一步):
flatten_records = FOREACH group_data GENERATE group,FLATTEN(records);
flatten_records: {group: bytearray,records::details: map[]}
DUMP flatten_records 这给了我以下输出:
(25,[height#5.1,age#25])
(25,[height#5.3,age#25])
(27,[height#5.10,age#27])
(27,[height#5.8,age#27])
现在我想得到平均身高;我试过这个:
display_records = FOREACH flatten_records GENERATE group,AVG(records.details#'height');
错误是:
<line 10, column 57> Multiple matching functions for org.apache.pig.builtin.AVG with input schema: ({{(bytearray)}}, {{(double)}}). Please use an explicit cast.
请指教。
【问题讨论】:
标签: hadoop mapreduce apache-pig bigdata