您好,登錄后才能下訂單哦!
Mapreduce中:
shuffle階段是在map和reduce之間,可以自定義排序,自定義分區(qū)和自定義分組!
Mapreduce中,map出的數(shù)據(jù)是鍵值對,默認(rèn)的是hashPatitionner來對map出的數(shù)據(jù)進(jìn)行分區(qū);
分區(qū)的方法還有其他幾個:
RandomSampler<Text, Text> sampler = new InputSampler.RandomSampler<Text, Text>(0.5, 3000, 10); IntervalSampler<Text, Text> sampler2 = new InputSampler.IntervalSampler<Text, Text>(0.333, 10); SplitSampler<Text, Text> sampler3 = new InputSampler.SplitSampler<Text, Text>(reduceNumber);
實現(xiàn)和細(xì)節(jié)
public class TotalSortMR { @SuppressWarnings("deprecation") public static int runTotalSortJob(String[] args) throws Exception { Path inputPath = new Path(args[0]); Path outputPath = new Path(args[1]); Path partitionFile = new Path(args[2]); int reduceNumber = Integer.parseInt(args[3]); //三種采樣器 RandomSampler<Text, Text> sampler = new InputSampler.RandomSampler<Text, Text>(1, 3000, 10); IntervalSampler<Text, Text> sampler2 = new InputSampler.IntervalSampler<Text, Text>(0.333, 10); SplitSampler<Text, Text> sampler3 = new InputSampler.SplitSampler<Text, Text>(reduceNumber); //任務(wù)初始化 Configuration conf = new Configuration(); Job job = Job.getInstance(conf); job.setJobName("Total-Sort"); job.setJarByClass(TotalSortMR.class); job.setInputFormatClass(KeyValueTextInputFormat.class); job.setMapOutputKeyClass(Text.class); job.setMapOutputValueClass(Text.class); job.setNumReduceTasks(reduceNumber); //設(shè)置所有的分區(qū)類 job.setPartitionerClass(TotalOrderPartitioner.class); //分區(qū)類參考的分區(qū)文件 TotalOrderPartitioner.setPartitionFile(conf, partitionFile); //分區(qū)使用哪種采樣器 InputSampler.writePartitionFile(job, sampler); //job的輸入和輸出路徑 FileInputFormat.setInputPaths(job, inputPath); FileOutputFormat.setOutputPath(job, outputPath); outputPath.getFileSystem(conf).delete(outputPath, true); return job.waitForCompletion(true)? 0 : 1; } public static void main(String[] args) throws Exception{ System.exit(runTotalSortJob(args)); } }
job默認(rèn)的輸入格式是TextInputFormat,這個是key-value的形式,key是每行的行標(biāo),value是每行的內(nèi)容??梢愿?/p>
job.setInputFormatClass(,....)
一般要設(shè)置mapper的輸出格式,以備后面使用。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。