我的问题是关于mapreduce programming in java
。mapreduce计数示例
假设我有WordCount.java示例,标准为mapreduce program
。我想要地图功能收集一些信息,并返回到缩小功能地图形成如:<slaveNode_id,some_info_collected>
,
这样I can know what slave node collected what data
..任何想法如何?
public class WordCount {
public static class Map extends MapReduceBase implements Mapper<LongWritable, Text, Text, IntWritable> {
private final static IntWritable one = new IntWritable(1);
private Text word = new Text();
public void map(LongWritable key, Text value, OutputCollector<Text, IntWritable> output, Reporter reporter) throws IOException {
String line = value.toString();
StringTokenizer tokenizer = new StringTokenizer(line);
while (tokenizer.hasMoreTokens()) {
word.set(tokenizer.nextToken());
output.collect(word, one);
}
}
}
public static class Reduce extends MapReduceBase implements Reducer<Text, IntWritable, Text, IntWritable> {
public void reduce(Text key, Iterator<IntWritable> values, OutputCollector<Text, IntWritable> output, Reporter reporter) throws IOException {
int sum = 0;
while (values.hasNext()) {
sum += values.next().get();
}
output.collect(key, new IntWritable(sum));
}
}
public static void main(String[] args) throws Exception {
JobConf conf = new JobConf(WordCount.class);
conf.setJobName("wordcount");
conf.setOutputKeyClass(Text.class);
conf.setOutputValueClass(IntWritable.class);
conf.setMapperClass(Map.class);
conf.setCombinerClass(Reduce.class);
conf.setReducerClass(Reduce.class);
conf.setInputFormat(TextInputFormat.class);
conf.setOutputFormat(TextOutputFormat.class);
FileInputFormat.setInputPaths(conf, new Path(args[0]));
FileOutputFormat.setOutputPath(conf, new Path(args[1]));
JobClient.runJob(conf);
}
}
谢谢!
不完全是,他在他的数据从机的信息:。 Wordcount将它反转为,他想以另一种方式获取slaveNode收集的所有信息。 –
2011-05-29 07:48:08
是的,确切地说,我想要收集每个slavenode的信息。 – 2011-05-29 07:50:57
无法从MR应用程序中知道slavenode的id。 – 2011-05-30 11:13:28