天天看點

hadoop統計檔案行數

hadoop中有自帶的計數器,原理及定義,網上到處都是解釋,這裡不再班門弄斧。

介紹使用方法:

context有一個方法getCounter,參數類型為(Enum)枚舉類型。

1、定義枚舉

static enum AA{

A

}

如果有多種計數類型,可以繼續定義。

2、在Mapper或reduce中寫入:

context.getCounter(AA.A).increment(1);  

3、在job執行完以後,

Counters counters = job.getCounters();  

Counter counter = counters.findCounter(AA.A);  

System.out.println(counter.getValue());  

Counter也可用來統計指定字元串出現的次數等。

繼續閱讀