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

常德市网站建设_网站建设公司_营销型网站_seo优化

深圳网站设计设计,做招聘网站要多久,可以建设网站的公司,汉中软件开发项目管理数据排序是许多实际任务执行时要完成的第一项工作#xff0c;比如学生成绩评比、数据建立索引等。这个实例和数据去重类似#xff0c;都是先对原始数据进行初步处理#xff0c;为进一步的数据操作打好基础 1 实例描述 对输入文件中数据进行排序。输入文件中的…数据排序是许多实际任务执行时要完成的第一项工作比如学生成绩评比、数据建立索引等。这个实例和数据去重类似都是先对原始数据进行初步处理为进一步的数据操作打好基础 1 实例描述 对输入文件中数据进行排序。输入文件中的每行内容均为一个数字即一个数据。要求在输出中每行有两个间隔的数字其中第一个代表原始数据在原始数据集中的位次第二个代表原始数据。 样例输入如下所示  1file1   2 32 654 32 15 756 65223 2file2   5956 22 650 923file3 26 54 6期望输出 1    2 2    6 3    15 4    22 5    26 6    32 7    32 8    54 9    92 10    650 11    654 12    756 13    5956 14    652232 问题分析 这个实例仅仅要求对输入数据进行排序 分析    MapReduce过程中就有排序,它的默认排序规则按照key值进行排序的如果key为封装int的IntWritable类型那么MapReduce按照数字大小对key排序如果key为封装为String的Text类型那么MapReduce按照字典顺序对字符串排序。   使用封装int的IntWritable型数据结构了。也就是在map中将读入的数据转化成IntWritable型然后作为key值输出value任意。reduce拿到keyvalue-list之后将输入的key作为value输出并根据value-list中元素的个数决定输出的次数。输出的key即代码中的linenum是一个全局变量它统计当前key的位次。需要注意的是这个程序中没有配置Combiner也就是在MapReduce过程中不使用Combiner。这主要是因为使用map和reduce就已经能够完成任务了。 3.实现步骤 在map中将读入的数据转化成IntWritable型然后作为key值输出value任意。 reduce拿到keyvalue-list之后将输入的key作为value输出并根据value-list中元素的个数决定输出的次数输出的key是一个全局变量它统计当前key的位次  4.关键代码 正序 package com.mk.mapreduce;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.LongWritable; import org.apache.hadoop.io.NullWritable; import org.apache.hadoop.io.Text; import org.apache.hadoop.mapreduce.Job; import org.apache.hadoop.mapreduce.Mapper; import org.apache.hadoop.mapreduce.Reducer; import org.apache.hadoop.mapreduce.lib.input.FileInputFormat; import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;import java.io.IOException; import java.net.URI;public class Sort {public static class SortMapper extends MapperLongWritable, Text, IntWritable, IntWritable {Overrideprotected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {IntWritable v new IntWritable(Integer.parseInt(value.toString().trim()));context.write(v, new IntWritable(1));}}public static class SortReducer extends ReducerIntWritable, IntWritable, IntWritable, IntWritable {int count 1;Overrideprotected void reduce(IntWritable key, IterableIntWritable values, Context context) throws IOException, InterruptedException {for (IntWritable v: values) {context.write(new IntWritable(count ), key);}}}public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {String uri hdfs://192.168.150.128:9000;String input /sort/input;String output /sort/output;Configuration conf new Configuration();if(System.getProperty(os.name).toLowerCase().contains(win))conf.set(mapreduce.app-submission.cross-platform,true);FileSystem fileSystem FileSystem.get(URI.create(uri), conf);Path path new Path(output);fileSystem.delete(path,true);Job job new Job(conf,Sort);job.setJar(./out/artifacts/hadoop_test_jar/hadoop-test.jar);job.setJarByClass(Sort.class);job.setMapperClass(SortMapper.class);job.setReducerClass(SortReducer.class);job.setMapOutputKeyClass(IntWritable.class);job.setMapOutputValueClass(IntWritable.class);job.setOutputKeyClass(IntWritable.class);job.setOutputValueClass(IntWritable.class);FileInputFormat.addInputPaths(job, uri input);FileOutputFormat.setOutputPath(job, new Path(uri output));boolean ret job.waitForCompletion(true);System.out.println(job.getJobName() ----- ret);} }逆序 package com.mk.mapreduce;import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; import org.apache.hadoop.io.*; import org.apache.hadoop.mapreduce.Job; import org.apache.hadoop.mapreduce.Mapper; import org.apache.hadoop.mapreduce.Reducer; import org.apache.hadoop.mapreduce.lib.input.FileInputFormat; import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;import java.io.IOException; import java.net.URI;public class Sort {public static class SortMapper extends MapperLongWritable, Text, IntWritable, IntWritable {Overrideprotected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {IntWritable v new IntWritable(Integer.parseInt(value.toString().trim()));context.write(v, new IntWritable(1));}}public static class SortReducer extends ReducerIntWritable, IntWritable, IntWritable, IntWritable {int count 1;Overrideprotected void reduce(IntWritable key, IterableIntWritable values, Context context) throws IOException, InterruptedException {for (IntWritable v: values) {context.write(new IntWritable(count ), key);}}}public static class SortComparator implements RawComparatorIntWritable {Overridepublic int compare(byte[] b1, int s1, int l1, byte[] b2, int s2, int l2) {return IntWritable.Comparator.compareBytes(b2, s2, l2, b1, s1, l1);}Overridepublic int compare(IntWritable o1, IntWritable o2) {return o2.get() - o1.get();}}public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {String uri hdfs://192.168.150.128:9000;String input /sort/input;String output /sort/output;Configuration conf new Configuration();if(System.getProperty(os.name).toLowerCase().contains(win))conf.set(mapreduce.app-submission.cross-platform,true);FileSystem fileSystem FileSystem.get(URI.create(uri), conf);Path path new Path(output);fileSystem.delete(path,true);Job job new Job(conf,Sort);job.setJar(./out/artifacts/hadoop_test_jar/hadoop-test.jar);job.setJarByClass(Sort.class);job.setMapperClass(SortMapper.class);job.setReducerClass(SortReducer.class);job.setMapOutputKeyClass(IntWritable.class);job.setMapOutputValueClass(IntWritable.class);job.setOutputKeyClass(IntWritable.class);job.setOutputValueClass(IntWritable.class);FileInputFormat.addInputPaths(job, uri input);FileOutputFormat.setOutputPath(job, new Path(uri output));job.setSortComparatorClass(SortComparator.class);boolean ret job.waitForCompletion(true);System.out.println(job.getJobName() ----- ret);} }
http://www.lebaoying.cn/news/2617.html

相关文章:

  • 怎样做公司自己的官方网站男科医院收费一览表
  • 响应式网站建设平台wordpress yinhu
  • 申请域名后可以做自己的网站吗wordpress小米主题
  • 爱做网站外国wordpress新闻
  • 模版营销型网站怎么做建设工程类公司网站
  • 没有网站可以做seo吗常州网警
  • 网站编程图多用户商城思维导图
  • 网站设计公司北京域名解析管理网站
  • 自己的电脑怎么做网站信息类网站 wordpress
  • 渭南做网站电话网站推广策略的主要方式
  • 空间坐标系做图网站免费网页模板之家
  • 商城网站制作明细网站域名绑定破解
  • 高端手机网站定制学网络运营在哪里学比较好
  • 北京品牌网站建设公司哪家好注册城乡规划师有什么用
  • 武进网站建设哪家好重庆市建设岗位培训中心
  • 网站制作系统哪个好网络推广公司推荐
  • 福州网站seo优化公司python做电商网站
  • 网站是先解析还是先备案上海大型外贸公司
  • 做公司网站需要几天做网站需要网络服务器
  • 网站你应该明白什么意思吗百度视频推广
  • 六盘水网站开发长沙关键词优化平台
  • html网站制作答辩ppt山西省煤炭厅基本建设局网站
  • 做网站编辑怎么样服务器建站
  • 宜宾网站建设价格网页qq注册新账号免费
  • 手机建站平台网站免费的不用下载
  • 房产网站的全景图怎么做关键词检测工具
  • 做网站phpwordpress 按钮样式
  • 深圳优化网站方法网站页面设计需求
  • 建设第三方公众号平台网站教程广州网站制作托管
  • 网站建设 58同城网站建设得步骤