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

站长做2个网站/百度网址大全设为主页

站长做2个网站,百度网址大全设为主页,数据共享网站建设,wordpress小说主题自定义排序,是基于k2的排序,设现有以下一组数据,分别表示矩形的长和宽,先按照面积的升序进行排序。9 9 6 6 7 8 1 1 5 4现在需要重新定义数据类型,MR的key值必须继承WritableComparable接口&#xff0c…

 

自定义排序,是基于k2的排序,设现有以下一组数据,分别表示矩形的长和宽,先按照面积的升序进行排序。
9    9
6    6
7    8
1    1
5    4

  

现在需要重新定义数据类型,MR的key值必须继承WritableComparable接口,因此定义RectangleWritable数据类型如下
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import org.apache.hadoop.io.WritableComparable;
public class RectangleWritable implements WritableComparable {int length,width;public RectangleWritable() {super();// TODO Auto-generated constructor stub}public RectangleWritable(int length, int width) {super();this.length = length;this.width = width;}public int getLength() {return length;}public void setLength(int length) {this.length = length;}public int getWidth() {return width;}public void setWidth(int width) {this.width = width;}@Overridepublic void write(DataOutput out) throws IOException {// TODO Auto-generated method stubout.writeInt(length);out.writeInt(width);}@Overridepublic void readFields(DataInput in) throws IOException {// TODO Auto-generated method stubthis.length=in.readInt();this.width=in.readInt();}@Overridepublic int compareTo(Object arg0) {// TODO Auto-generated method stubRectangleWritable other = (RectangleWritable)arg0;if (this.getLength() * this.getWidth() > other.length * other.width ) {return 1;}if (this.getLength() * this.getWidth() < other.length * other.width ) {return -1;}return 0;}@Overridepublic String toString() {return   this.getLength() + "\t" + this.getWidth();}}

  

其中,compareTo方法自定义排序规则,然后由框架进行排序。
map函数和Reduce函数并无大变化,还是按照WrodCount的思路进行,具体代码如下:
import java.io.IOException;
import java.net.URI;
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.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.mapreduce.Reducer;
public class SelfDefineSort {/*** @param args* @author nwpulisz* @date 2016.4.1*/static final String INPUT_PATH="hdfs://192.168.255.132:9000/input";static final String OUTPUT_PATH="hdfs://192.168.255.132:9000/output";public static void main(String[] args) throws Exception {// TODO Auto-generated method stubConfiguration conf = new Configuration();Path outPut_path= new Path(OUTPUT_PATH);Job job = new Job(conf, "SelfDefineSort");//如果输出路径是存在的,则提前删除输出路径FileSystem fileSystem = FileSystem.get(new URI(OUTPUT_PATH), conf);if(fileSystem.exists(outPut_path)){fileSystem.delete(outPut_path,true);}job.setJarByClass(RectangleWritable.class);FileInputFormat.setInputPaths(job, INPUT_PATH);FileOutputFormat.setOutputPath(job, outPut_path);job.setMapperClass(MyMapper.class);job.setReducerClass(MyReducer.class);job.setMapOutputKeyClass(RectangleWritable.class);job.setMapOutputValueClass(NullWritable.class);job.setOutputKeyClass(IntWritable.class);job.setOutputValueClass(IntWritable.class);job.waitForCompletion(true);}static class MyMapper extends Mapper<LongWritable, Text, RectangleWritable, NullWritable>{protected void map(LongWritable k1, Text v1, Context context) throws IOException, InterruptedException {String[] splits = v1.toString().split("\t");RectangleWritable k2 = new RectangleWritable(Integer.parseInt(splits[0]),Integer.parseInt(splits[1]));context.write(k2,NullWritable.get());}}static class MyReducer extends Reducer<RectangleWritable, NullWritable,IntWritable, IntWritable>{protected void reduce(RectangleWritable k2,Iterable<NullWritable> v2s,Context context)throws IOException, InterruptedException {// TODO Auto-generated method stubcontext.write(new IntWritable(k2.getLength()), new IntWritable(k2.getWidth()));}}
}

  

根据自定义结果,输出结果如下:



来自为知笔记(Wiz)



转载于:https://www.cnblogs.com/nwpulisz/p/5352359.html

http://www.lbrq.cn/news/794899.html

相关文章:

  • 乌鲁木齐建设工程信息网站/电商数据统计网站
  • b站怎么看视频在线人数/百度推广竞价
  • 有风格的网站/com网站域名注册
  • xp怎么做网站服务器/域名注册管理机构
  • 建设应用型网站的意义/seo百度站长工具
  • 网站地址解析/网站优化排名推广
  • 南充做网站电话/app广告投放价格表
  • 烟台网站推广排名/新冠咳嗽一般要咳多少天
  • 昆明做网站做的好的公司/惠州优化怎么做seo
  • 如何做免费网站推广/2022年百度seo
  • 网站建设和运维单位责任/seo工具大全
  • 河南做网站公司哪家专业/怎样在百度上宣传自己的产品
  • 做基础网站主机要?/建立一个网站需要花多少钱
  • 株洲seo网站优化软件/网站搜索引擎优化案例
  • 宁波网站建设设计制作/seo推广优化平台
  • 做公司网站备案可以个人/如何提升网站搜索排名
  • dw制造网站log怎么做/互联网搜索引擎
  • 敲代码做网站多少钱/百度极速版下载安装
  • 网站空间20g/新产品市场推广方案
  • 厦门掘金网站建设/网盟推广平台
  • 网站建设倒计时单页源码/营销策略4p
  • 两个公司的网站建设/搜索引擎优化seo
  • 喀什做网站/千锋教育怎么样
  • 云建站规划图/网络推广平台软件
  • 信科网络广州建网站/怎么样做seo
  • 网站程序模块/网店推广的重要性
  • 手机在线客服平台/网站seo文章
  • 长沙模板建站定制/网推怎么做最有效
  • 软件制作网站/如何进行网站的宣传和推广
  • 二级a做爰片免费网站/网络推广方案的内容
  • 江协科技STM32 14-1 WDG看门狗
  • 吴恩达【prompt提示词工程】学习笔记
  • 更换KR100门禁读头&主机
  • vscode的Remote-SSH插件配置SSH主机方法
  • web前端React和Vue框架与库安全实践
  • 【vue】computed计算属性