学习日志---partitioner和采样器
发表于:2026-11-04 作者:千家信息网编辑
千家信息网最后更新 2026年11月04日,Mapreduce中:shuffle阶段是在map和reduce之间,可以自定义排序,自定义分区和自定义分组!Mapreduce中,map出的数据是键值对,默认的是hashPatitionner来对m
千家信息网最后更新 2026年11月04日学习日志---partitioner和采样器
Mapreduce中:
shuffle阶段是在map和reduce之间,可以自定义排序,自定义分区和自定义分组!
Mapreduce中,map出的数据是键值对,默认的是hashPatitionner来对map出的数据进行分区;
分区的方法还有其他几个:
RandomSamplersampler = new InputSampler.RandomSampler (0.5, 3000, 10);IntervalSampler sampler2 = new InputSampler.IntervalSampler (0.333, 10);SplitSampler sampler3 = new InputSampler.SplitSampler (reduceNumber);
实现和细节
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 sampler = new InputSampler.RandomSampler(1, 3000, 10); IntervalSampler sampler2 = new InputSampler.IntervalSampler(0.333, 10); SplitSampler sampler3 = new InputSampler.SplitSampler(reduceNumber); //任务初始化 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); //设置所有的分区类 job.setPartitionerClass(TotalOrderPartitioner.class); //分区类参考的分区文件 TotalOrderPartitioner.setPartitionFile(conf, partitionFile); //分区使用哪种采样器 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默认的输入格式是TextInputFormat,这个是key-value的形式,key是每行的行标,value是每行的内容。可以更改
job.setInputFormatClass(,....)
一般要设置mapper的输出格式,以备后面使用。
采样器
数据
格式
输入
输出
之间
任务
内容
形式
文件
方法
是在
细节
路径
阶段
分组
参考
排序
日志
学习
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
咖啡
咖啡豆
瑰夏咖啡
上海喔噻互联网科技有限公司
高科技互联网
互联网医疗科技
融势互联网科技
博兴的互联网电子科技公司
互联网科技博主是什么意思
中国的互联网科技企业的崛起
北京华百购互联网科技有限公司
银川新华互联网科技学校联系电话
内蒙古九一互联网科技
群盈汇互联网科技有限公司
领航科技大厦互联网公司
世界互联网科技成果奖
科技互联网行业投资研究
福仕德教育科技互联网
杭州融税互联网科技有限公司
盐城市攀科互联网科技有限公司
互联网科技工作委员会副主任毛军
互联网下的科技发展
科技与互联网发展
互联网科技的英文
上海喔噻互联网科技
互联网科技和法律行业
互联网科技实习生岗位
容联科技互联网电商
众联互联网络科技
科技互联网专业务虚会材料