日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > java >内容正文

java

java mapreduce教程_Java搭建MapReduce完成二次排序步骤

發(fā)布時間:2025/3/8 java 21 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java mapreduce教程_Java搭建MapReduce完成二次排序步骤 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

1、構(gòu)建新的作業(yè)

Configuration conf=getConf();

Job job=Job.getInstance(conf);

job.setJarByClass(SortYearAndTemp2.class);

2、設(shè)置輸入輸出目錄

Path inpath=new Path(conf.get("inpath"));

Path outpath=new Path(conf.get("outpath"));

FileInputFormat.addInputPath(job, inpath);

FileOutputFormat.setOutputPath(job, outpath);

3、設(shè)置Mapper Reducer函數(shù)

job.setMapperClass(SortYearAndTemp2.SortYearAndTemp2Mapper.class);

public static class SortYearAndTemp2Mapper extends Mapper

job.setReducerClass(SortYearAndTemp2.SortYearAndTemp2Reducer.class);

public static class SortYearAndTemp2Reducer extends Reducer

4、設(shè)置輸出格式

job.setMapOutputKeyClass(Weather.class);

job.setMapOutputValueClass(Text.class);

job.setOutputValueClass(Text.class);

job.setOutputKeyClass(NullWritable.class);

5、指定分區(qū)方式

job.setPartitionerClass(WeatherPartitioner.class); //參數(shù)為Partitioner的子類

創(chuàng)建Partitioner的子類:public static class WeatherPartitioner extends Partitioner

重寫getPartition()方法,返回int //指定分區(qū)方式

6、指定分組方式

job.setGroupingComparatorClass(WeatherGroup.class); //參數(shù)為WritableComparator的子類

創(chuàng)建WritableComparator的子類:public static class WeatherGroup extends WritableComparator

構(gòu)造無參構(gòu)造器WeatherGroup(){super(Weather, true);} //重寫父類帶有參數(shù)的構(gòu)造器

重寫compare()方法 //指定分組方式

7、提交執(zhí)行作業(yè),等待作業(yè)完成之后退出虛擬機

return job.waitForCompletion(true)?0:1;

8、創(chuàng)建傳遞給key的類

public static class Weather implements WritableComparable

重寫write()方法 //序列化

重寫readFields()方法 //反序列化

重寫compareTo()方法 //規(guī)定key參數(shù)類的排序規(guī)則

設(shè)置set() get()方法

構(gòu)造帶有全部參數(shù)和無參的構(gòu)造器

總結(jié)

以上是生活随笔為你收集整理的java mapreduce教程_Java搭建MapReduce完成二次排序步骤的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。