pr_*_*_84 8 java hadoop mapreduce
我的问题是关于mapreduce programming in java.
假设我有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);
}
}
Run Code Online (Sandbox Code Playgroud)
谢谢!!
你要问的是让应用程序(你的map-reduce thingy)知道它运行的基础设施.
一般来说,答案是您的应用程序不需要此信息.每次调用Mapper和每次调用Reducer都可以在不同的节点上执行,也可以在同一节点上执行.MapReduce的优点在于结果是一样的,因此对于您的应用程序来说:无所谓.
因此,API没有支持您的此请求的功能.
玩得开心学习Hadoop :)
PS我能想到的唯一方法(至少可以说是令人讨厌的)是你在Mapper中包含某种类型的系统调用,并向底层操作系统询问它的名称/属性/等.这种结构会使你的应用程序非常不便携; 即它不会在Windows或亚马逊上的Hadoop上运行.
| 归档时间: |
|
| 查看次数: |
7523 次 |
| 最近记录: |