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

设计一个网站花多少时间seo 页面

设计一个网站花多少时间,seo 页面,小程序同步wordpress,电商平台数据文章目录 自定义InputFormat1. 需求2. 输入数据3. 期望输出文件格式4. 需求分析5. 代码实现WholeFileInputformatWholeRecordReader☆☆SequenceFileMapperSequenceFileReducer ☆ 自定义InputFormat 在企业开发中,Hadoop框架自带的InputFormat类型不能满足所有应用…

文章目录

    • 自定义InputFormat
        • 1. 需求
        • 2. 输入数据
        • 3. 期望输出文件格式
        • 4. 需求分析
        • 5. 代码实现
            • WholeFileInputformat
            • WholeRecordReader☆☆
            • SequenceFileMapper
            • SequenceFileReducer

自定义InputFormat

在企业开发中,Hadoop框架自带的InputFormat类型不能满足所有应用场景,需要自定义InputFormat来解决实际问题。

自定义InputFormat步骤如下

  1. 自定义一个类继承FileInputFormat。
  2. 改写RecordReader,实现一次读取一个完整文件封装为KV。
  3. 在输出时使用SequenceFileOutPutFormat输出合并文件

无论HDFS还是MapReduce,在处理小文件时效率都非常低,但又难免面临处理大量小文件的场景,此时,就需要有相应解决方案。可以自定义InputFormat实现小文件的合并。

1. 需求

将多个小文件合并成一个SequenceFile文件(SequenceFile文件是Hadoop用来存储二进制形式的key-value对的文件格式),SequenceFile里面存储着多个文件,存储的形式为文件路径+名称为key,文件内容为value

2. 输入数据

在这里插入图片描述

3. 期望输出文件格式

在这里插入图片描述

4. 需求分析

在这里插入图片描述

5. 代码实现
WholeFileInputformat
/*** @Date 2020/7/9 23:10* @Version 10.21* @Author DuanChaojie*/
public class WholeFileInputformat extends FileInputFormat<Text,BytesWritable> {@Overrideprotected boolean isSplitable(JobContext context, Path filename) {return false;}@Overridepublic RecordReader<Text, BytesWritable> createRecordReader(InputSplit split, TaskAttemptContext context) throws IOException, InterruptedException {WholeRecordReader recordReader = new WholeRecordReader();recordReader.initialize(split,context);return recordReader;}
}
WholeRecordReader☆☆
/*** @Date 2020/7/9 23:23* @Version 10.21* @Author DuanChaojie*/
public class WholeRecordReader extends RecordReader {private Configuration conf;private FileSplit split;private boolean isProgress= true;private Text k = new Text();private BytesWritable v = new BytesWritable();@Overridepublic void initialize(InputSplit split, TaskAttemptContext context) throws IOException, InterruptedException {this.split = (FileSplit)split;conf = context.getConfiguration();}/*** 核心逻辑* @return* @throws IOException* @throws InterruptedException*/@Overridepublic boolean nextKeyValue() throws IOException, InterruptedException {if (isProgress) {// 1.定义缓冲区byte[] contents = new byte[(int) split.getLength()];FileSystem fs = null;FSDataInputStream fis = null;try {// 2. 获取文件系统Path path = split.getPath();fs = path.getFileSystem(conf);// 3.读取数据fis = fs.open(path);// 4.读取文件内容IOUtils.readFully(fis, contents, 0, contents.length);// 5.输出文件内容v.set(contents,0,contents.length);// 6.获取文件路径及名称String name = split.getPath().toString();// 7,设置输出的key值k.set(name);} catch (Exception e) {e.printStackTrace();}finally {IOUtils.closeStream(fis);}isProgress = false;return true;}return false;}@Overridepublic Object getCurrentKey() throws IOException, InterruptedException {return k;}@Overridepublic Object getCurrentValue() throws IOException, InterruptedException {return v;}@Overridepublic float getProgress() throws IOException, InterruptedException {return 0;}@Overridepublic void close() throws IOException {}
}
SequenceFileMapper
/*** @Date 2020/7/9 23:36* @Version 10.21* @Author DuanChaojie*/
public class SequenceFileMapper extends Mapper<Text, BytesWritable, Text,BytesWritable> {@Overrideprotected void map(Text key, BytesWritable value, Context context) throws IOException, InterruptedException {context.write(key,value);}
}
SequenceFileReducer
public class SequenceFileReducer extends Reducer<Text, BytesWritable, Text,BytesWritable> {@Overrideprotected void reduce(Text key, Iterable<BytesWritable> values, Context context) throws IOException, InterruptedException {context.write(key,values.iterator().next());}
}
public class SequenceFileDriver {public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {// 输入输出路径需要根据自己电脑上实际的输入输出路径设置args = new String[] { "e:/file/input/inputinputformat", "e:/file/output2" };// 1 获取job对象Configuration conf = new Configuration();Job job = Job.getInstance(conf);// 2 设置jar包存储位置、关联自定义的mapper和reducerjob.setJarByClass(SequenceFileDriver.class);job.setMapperClass(SequenceFileMapper.class);job.setReducerClass(SequenceFileReducer.class);// 3 设置map输出端的kv类型job.setMapOutputKeyClass(Text.class);job.setMapOutputValueClass(BytesWritable.class);// 4 设置最终输出端的kv类型job.setOutputKeyClass(Text.class);job.setOutputValueClass(BytesWritable.class);// 5 设置输入输出路径FileInputFormat.setInputPaths(job, new Path(args[0]));FileOutputFormat.setOutputPath(job, new Path(args[1]));// 6设置输入的inputFormatjob.setInputFormatClass(WholeFileInputformat.class);// 7设置输出的outputFormatjob.setOutputFormatClass(SequenceFileOutputFormat.class);// 8提交jobboolean result = job.waitForCompletion(true);System.exit(result ? 0 : 1);}
}

完全与期望输出结果一致!

http://www.yidumall.com/news/53652.html

相关文章:

  • 拼团购物网站怎么做新手网络推广怎么干
  • 广宁城乡建设网站中国最新军事新闻
  • 太原网站建设需要多少钱seo优化关键词是什么意思
  • 山东德州做网站益阳网站seo
  • html5 网站案例打广告推广怎么做
  • 上海专业高端网站建设服网店代运营商
  • 聊城网站建设哪家便宜银徽seo
  • 医生问诊在线咨询免费seo外链招聘
  • 网站建设二级关键词什么意思搜索引擎营销的流程
  • 站长网站提交怎么找需要做推广的公司
  • 充值网站分销站怎么做百度知道首页
  • 什么网站做任务杭州网站建设 seo
  • 购物中心网站模板友情链接检测的特点
  • 直播型网站开发整站优化 快速排名
  • 代理赚钱杭州网站seo公司
  • 网站名称注册今天的病毒感染情况
  • 四川网站建设的公司哪家好网站推广系统
  • 12306网站做的好垃圾下载百度app免费下载安装
  • 阿里云ecs搭建网站百度移动首页
  • 网站的seo怎么做热点时事新闻
  • 网站建设全套教程百度上如何做优化网站
  • 开发手机网站制作seo专员简历
  • 生产企业网站如何做seo外贸平台app
  • 做网站一般的尺寸现在感染症状有哪些
  • 哪个网站可以接任务做兼职软文广告范例大全
  • 西安三桥网站建设网络推广中心
  • 杭州仪器网站制作长春seo优化企业网络跃升
  • 在excel中怎么做邮箱网站熊猫关键词工具
  • 深圳龙岗做网站的公司技能培训机构排名前十
  • 衢州网站建设方案做网页设计的软件