l********s 发帖数: 358 | 1 我有很多个文件,每个文件中每一行都是一个word。用Hadoop来统计所有的word,和每
个word总共出现的次数。
程序很简单:
Map():
context.write(word, one)
Reduce():
for (IntWritable val : values) {
sum += val.get();
}
context.write(key, new IntWritable(sum));
我的问题是如果我同时想要知道word的总数目,这样我就可以用来计算word出现的频率
。有什么办法我可以在同一个map-reduce的job里面得到word的总数目?(当然,在我
dump out每个word出现的次数后,我可以在建一个map-reduce的job来得到总数目)。 |
z****e 发帖数: 54598 | |
l********s 发帖数: 358 | 3 不是作业啦,纯粹工作之余学点新东西。其实我在map-reduce前逐行把文件读进来,得
到总的count就可以,只是想知道有什么更容易的办法。
我还是自己找本hadoop的cookbook来看看吧 |
y******u 发帖数: 804 | 4 貌似可以调整input format,不过貌似default就是你要求的这种格式
请仔细看 http://hadoop.apache.org/docs/stable/mapred_tutorial.html
搜索 inputformat |
n*******h 发帖数: 67 | 5 First find a string that you know will definitely not appear as a word in
the text files. Let's say the string is 'xiaojiangsb'. Then in your mapper:
emit both (word, 1) and ('xiaojiangsb', 1) for every word
After reducing with your reducer, you will get the total word count
associated with key 'xiaojiangsb'.
To be efficient, you should use a combiner on the mapper nodes.
【在 l********s 的大作中提到】 : 我有很多个文件,每个文件中每一行都是一个word。用Hadoop来统计所有的word,和每 : 个word总共出现的次数。 : 程序很简单: : Map(): : context.write(word, one) : Reduce(): : for (IntWritable val : values) { : sum += val.get(); : } : context.write(key, new IntWritable(sum));
|
c*****a 发帖数: 1638 | 6 没看懂你的问题。
count(distinct word)还是count(×)
不过答案是用counter,前者在reducr里面,后者在mapper里面
【在 l********s 的大作中提到】 : 我有很多个文件,每个文件中每一行都是一个word。用Hadoop来统计所有的word,和每 : 个word总共出现的次数。 : 程序很简单: : Map(): : context.write(word, one) : Reduce(): : for (IntWritable val : values) { : sum += val.get(); : } : context.write(key, new IntWritable(sum));
|