admin 管理员组文章数量: 1184232
2024年3月13日发(作者:dubbo连接方式)
mapreduce java代码
以下是一个MapReduce的Java代码示例:
1. Map函数代码:
public static class Map extends Mapper Text, IntWritable> 。 private Text word = new Text();。 private final static IntWritable one = new IntWritable(1);。 public void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException 。 String line = ng();。 StringTokenizer tokenizer = new StringTokenizer(line);。 while (eTokens()) 。 (ken());。 (word, one);。 }。 }。 }。 2. Reduce函数代码: public static class Reduce extends Reducer Text, IntWritable> 。 public void reduce(Text key, Iterable Context context) throws IOException, InterruptedException 。 int sum = 0;。 for (IntWritable val : values) 。 sum += ();。 }。 (key, new IntWritable(sum));。 }。 }。 3. MapReduce主函数代码: public static void main(String [] args) throws Exception 。 Configuration conf = new Configuration();。 Job job = new Job(conf, "wordcount");。 putKeyClass();。 putValueClass();。 perClass();。 ucerClass();。 utFormatClass();。 putFormatClass();。 utPath(job, new Path(args[0]));。 putPath(job, new Path(args[1]));。 }。
版权声明:本文标题:mapreduce java代码 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.roclinux.cn/b/1710341251a568542.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论