当前位置: 首页 > news >正文

龙岗商城网站建设上海十大策划公司排名

龙岗商城网站建设,上海十大策划公司排名,wordpress 所见即所得,天元建设集团有限公司长清分公司先简单介绍一下partitioner 和 combiner Partitioner类 用于在Map端对key进行分区 默认使用的是HashPartitioner 获取key的哈希值使用key的哈希值对Reduce任务数求模决定每条记录应该送到哪个Reducer处理自定义Partitioner 继承抽象类Partitioner#xff0c;重写getPartiti…先简单介绍一下partitioner 和 combiner  Partitioner类 用于在Map端对key进行分区 默认使用的是HashPartitioner 获取key的哈希值使用key的哈希值对Reduce任务数求模决定每条记录应该送到哪个Reducer处理自定义Partitioner 继承抽象类Partitioner重写getPartition方法job.setPartitionerClass(MyPartitioner.class) Combiner类 Combiner相当于本地化的Reduce操作 在shuffle之前进行本地聚合用于性能优化可选项输入和输出类型一致Reducer可以被用作Combiner的条件 符合交换律和结合律实现Combiner job.setCombinerClass(WCReducer.class) 我们进入案例来看这两个知识点 一 案例需求 一个存放电话号码的文本我们需要136 137138 139和其它开头的号码分开存放统计其每个数字开头的号码个数 效果 二 PhoneMapper 类 import org.apache.hadoop.io.IntWritable; import org.apache.hadoop.io.LongWritable; import org.apache.hadoop.io.Text; import org.apache.hadoop.mapreduce.Mapper;import java.io.IOException;public class PhoneMapper extends MapperLongWritable, Text,Text, IntWritable {Overrideprotected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {String phone value.toString();Text text new Text(phone);IntWritable intWritable new IntWritable(1);context.write(text,intWritable);} }三 PhoneReducer 类 import org.apache.hadoop.io.IntWritable; import org.apache.hadoop.io.Text; import org.apache.hadoop.mapreduce.Reducer;import java.io.IOException;public class PhoneReducer extends ReducerText, IntWritable,Text,IntWritable {Overrideprotected void reduce(Text key, IterableIntWritable values, Context context) throws IOException, InterruptedException {int count 0;for (IntWritable intWritable : values){count intWritable.get();}context.write(key, new IntWritable(count));} }四 PhonePartitioner 类 import org.apache.hadoop.io.IntWritable; import org.apache.hadoop.io.Text; import org.apache.hadoop.mapreduce.Partitioner;public class PhonePartitioner extends PartitionerText, IntWritable {Overridepublic int getPartition(Text text, IntWritable intWritable, int i) {//136,137 138,139 其它号码放一起if(136.equals(text.toString().substring(0,3)) || 137.equals(text.toString().substring(0,3))){return 0;}else if (138.equals(text.toString().substring(0,3)) || 139.equals(text.toString().substring(0,3))){return 1;}else {return 2;}} }五 PhoneCombiner 类 import org.apache.hadoop.io.IntWritable; import org.apache.hadoop.io.Text; import org.apache.hadoop.mapreduce.Reducer;import java.io.IOException;public class PhoneCombiner extends ReducerText, IntWritable,Text,IntWritable {Overrideprotected void reduce(Text key, IterableIntWritable values, Context context) throws IOException, InterruptedException {int count 0;for(IntWritable intWritable : values){count intWritable.get();}context.write(new Text(key.toString().substring(0,3)), new IntWritable(count));} }六 PhoneDriver 类 import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; import org.apache.hadoop.io.IntWritable; import org.apache.hadoop.io.Text; import org.apache.hadoop.mapreduce.Job; import org.apache.hadoop.mapreduce.lib.input.FileInputFormat; import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;import java.io.IOException;public class PhoneDriver {public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {Configuration conf new Configuration();Job job Job.getInstance(conf);job.setJarByClass(PhoneDriver.class);job.setMapperClass(PhoneMapper.class);job.setMapOutputKeyClass(Text.class);job.setMapOutputValueClass(IntWritable.class);job.setCombinerClass(PhoneCombiner.class);job.setPartitionerClass(PhonePartitioner.class);job.setNumReduceTasks(3);job.setReducerClass(PhoneReducer.class);job.setOutputKeyClass(Text.class);job.setOutputValueClass(IntWritable.class);Path inPath new Path(in/demo4/phone.csv);FileInputFormat.setInputPaths(job, inPath);Path outPath new Path(out/out6);FileSystem fs FileSystem.get(outPath.toUri(),conf);if (fs.exists(outPath)){fs.delete(outPath, true);}FileOutputFormat.setOutputPath(job, outPath);job.waitForCompletion(true);} }七 小结 该案例新知识点在于分区partition和结合combine 这次代码的流程是  driver——》mapper——》partitioner——》combiner——》reducer map 每处理一条数据都经过一次 partitioner 分区然后存到环形缓存区中去然后map再去处理下一条数据以此反复直至所有数据处理完成 combine 则是将环形缓存区溢出的缓存文件合并并提前进行一次排序和计算对每个溢出文件计算后再合并最后将一个大的文件给到 reducer这样大大减少了 reducer 的计算负担
http://www.hkea.cn/news/14298570/

相关文章:

  • 建网站岑溪哪家强?wordpress维护
  • 网站建设高端网站网站开发用什么简单
  • 淮安建设企业网站公司做个官网要多少钱
  • 网站怎么样排名个人网页制作全过程
  • 保定专业做网站程序员接私活要达到什么水平
  • 影响网站速度因素 dns软件开发语言都有哪些
  • 网站建设在电子商务中意义政协机关网站建设
  • joomla 网站图标设计网站的步骤
  • 设计优秀网站作品湛江电气建站软件
  • 视频网站自己怎么做的福建省建设招投标网站
  • 软件项目网站建设实验报告蓟县做网站公司
  • 珠海做网站费用足球世界积分榜
  • 网站建设费用明细湖南岚鸿wordpress 读取分类
  • 企业网站建设要注意什么营销网站有四大要素构成
  • 网站建设过程小结建站网站插件
  • 自己建设购物网站wordpress域名后缀
  • 网站规划的意义创作图片的软件
  • 网站名称在哪里注册购物网站建设与开发
  • 正规网站建设公司哪个比较好wordpress4.9.8升级包
  • 网站备案方案263企业邮箱登录入口收费
  • 网站视觉艺术设计及色彩搭配服装网站建设的规模和类别
  • 管理网站建设哪里好品牌网站建设搜搜磐石网络
  • 南阳市网站制作网站建设 职责
  • 上海建网站开发公司山东聊城建设学校网站
  • 合作公司做网站东莞黄页网广告
  • asp网站建设教程西地那非的作用与功效
  • flash网站php源码网站优化 图片
  • 个人网站制作模板主页软件设计师考试
  • 舞钢网站建设平面设计接单价格表
  • 做淘宝的网站的多少钱官方网站建设情况说明