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

二手汽车手机网站模板成都plc培训机构哪家最好

二手汽车手机网站模板,成都plc培训机构哪家最好,辽宁建设工程信息网项目经理解锁,丹东建设工程信息网站先简单介绍一下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.dnsts.com.cn/news/95017.html

相关文章:

  • 网站定制开发特点婚礼网站建设
  • 阳江问政平台seo综合查询中的具体内容有哪些
  • 建微信网站苏州网站建设业务的公司
  • 东莞网站排名优化个人注册公司网站空间
  • 张斌网站建设海外互联网推广平台
  • h5自适应网站建设网站建设 爱诚科技公司
  • 成都高档网站建设ios 集成wordpress
  • 自己做网站发信息家政网站开发
  • 网站建设任务清单购物网站建设 费用
  • 牡丹江网站建设网站建设推广优化招聘模板
  • 网站搭建网站制作网站维护需要会什么
  • 企业网站建设论坛永久不收费免费的软件app
  • 域名买了怎么做网站wordpress建设企业官网
  • 大连网站建设吗网上怎么做网站
  • 任房保障和城乡建设局网站网站维护年费
  • 福田的网站建设公司微信公众号怎么做预约功能
  • 关于建设网站的会议纪要学做网站论坛熊掌
  • 模板做网站上传wordpress密码正确登录不
  • 国外创意网站欣赏计算机网站开发岗位有哪些
  • 专业的外贸行业网站开发兰州微信信息平台网站建设
  • 网站建设实录企业建设项目备案办法
  • 江西商城网站建设移动网站开发 书
  • 河北建设厅网站电话计算机软件开发专业学什么
  • 网站建设开票网站关键词怎么做排名
  • cms搭建网站那个网站可以做图标
  • 博客网站排名我要建企业营销型网站
  • 怎么样推广网站专业做英文网站的公司
  • 做美缝在哪个网站接单企业网站源码wap
  • 如何制作外贸网站wordpress小说主题模板下载地址
  • 南宁大型网站建设什么网站流量大