【问题标题】:apache pig count sortapache 猪计数排序
【发布时间】:2013-12-11 13:05:20
【问题描述】:

我正在从 pig 读取 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】:

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

    counts = FOREACH grp_f5 GENERATE group, COUNT(A) AS cnt;
    counts_ordered = ORDER counts BY cnt DESC;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多