apache pig count sort

问题描述 投票:3回答:1

我正在阅读猪的apache日志,它计算了ip的总连接数。

A = LOAD 'access.log' using PigStorage(' ') as (f0:chararray,f1:chararray,f2:chararray,f3:chararray,f4:chararray,f5:chararray,f6:chararray);
grp_f5 = GROUP A by f5; 
counts = FOREACH grp_f5 GENERATE group, COUNT(A);
store counts into '/data/accesslog' using PigStorage(','); 

结果:

2.50.3.29,71
71.5.94.4,30
12.0.19.50,6
12.53.17.3,4
155.69.4.4,37
166.77.6.8,12
218.0.7.30,1956
5.10.83.28,1
5.86.82.80,177
50.18.2.73,1
59.10.5.53,377

但是数据没有按计数排序,任何想法?

hadoop mapreduce apache-pig
1个回答
10
投票

如果不明确对数据进行排序,则不会对其进行排序。可以使用ORDER BY进行排序:

counts = FOREACH grp_f5 GENERATE group, COUNT(A) AS cnt;
counts_ordered = ORDER counts BY cnt DESC;
© www.soinside.com 2019 - 2024. All rights reserved.