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

四川省建设规划局官方网站百度系app有哪些

四川省建设规划局官方网站,百度系app有哪些,刷网站排名软件,唐山公司网站建设 中企动力3.6.1OutputFormat接口实现类 OutputFormat是MapReduce输出的基类,所有实现MapReduce输出都实现了OutputFormat接口。下面我们介绍几种常见的OutputFormat实现类。 1、文本输出TextOutputFormat 默认的输出格式是TextOutputFormat,它把每条记录写为文…

3.6.1OutputFormat接口实现类

OutputFormat是MapReduce输出的基类,所有实现MapReduce输出都实现了OutputFormat接口。下面我们介绍几种常见的OutputFormat实现类。

1、文本输出TextOutputFormat

默认的输出格式是TextOutputFormat,它把每条记录写为文本行。它的键和值可以是任意类型,疑问TextOutputFormat调用toString()方法把他们转换为字符串。

2、SequenceFileOutputFormat

将SequenceFileOutputFormat输出作为后续MapReduce任务的输入,这便是一种好的输出格式,因为它的格式紧凑,很容易被压缩

3、自定义OutputFormat

根据用户需求,自定义实现输出。

3.6.2自定义OutputFormat

1、使用场景

为了实现控制最终文件的输出路径和输出格式,可以自定义OutputFormat。

例如:要在一个MapReduce程序中根据数据的不同输出两类结果到不同的目录,这类灵活的输出需求可以通过自定义OutputFormat来实现。

2、自定义OUtputFormat步骤

(1)自定义一个类继承FileOutputFormat。

(2)改写RecordWriter,具体改写输出数据的方法write()。

3.6.3自定义OutputFormat案例实操

1、需求

过滤输入的log日志,包含atguigu的网站输出到e:/atguigu.log,不包含atguigu的网站输出到e:/other.log。

(1)输入数据

http://www.baidu.com
http://www.google.com
http://cn.bing.com
http://www.atguigu.com
http://www.sohu.com
http://www.sina.com
http://www.sin2a.com
http://www.sin2desa.com
http://www.sindsafa.com

(2)期望输出数据

http://www.atguigu.com
http://cn.bing.com
http://www.baidu.com
http://www.google.com
http://www.sin2a.com
http://www.sin2desa.com
http://www.sina.com
http://www.sindsafa.com
http://www.sohu.com

2、需求分析

Untitled

3、案例实操

(1)编写FilterMapper类

package com.cuiyf41.output;import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;import java.io.IOException;public class FilterMapper extends Mapper<LongWritable, Text, Text, NullWritable> {@Overrideprotected void map(LongWritable key, Text value, Mapper<LongWritable, Text, Text, NullWritable>.Context context) throws IOException, InterruptedException {// 写出context.write(value, NullWritable.get());}
}

(2)编写FilterReducer类

package com.cuiyf41.output;import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;import java.io.IOException;public class FilterReducer extends Reducer<Text, NullWritable, Text, NullWritable> {Text k = new Text();@Overrideprotected void reduce(Text key, Iterable<NullWritable> values, Reducer<Text, NullWritable, Text, NullWritable>.Context context) throws IOException, InterruptedException {// 1 获取一行String line = key.toString();// 2 拼接line = line + "\r\n";// 3 设置keyk.set(line);// 4 输出context.write(k, NullWritable.get());}
}

(3)自定义一个OutputFormat类

package com.atguigu.mapreduce.outputformat;
import java.io.IOException;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.RecordWriter;
import org.apache.hadoop.mapreduce.TaskAttemptContext;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;public class FilterOutputFormat extends FileOutputFormat<Text, NullWritable>{@Overridepublic RecordWriter<Text, NullWritable> getRecordWriter(TaskAttemptContext job)			throws IOException, InterruptedException {// 创建一个RecordWriterreturn new FilterRecordWriter(job);}
}

(4)编写RecordWriter类

package com.cuiyf41.output;import org.apache.hadoop.fs.FSDataOutputStream;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IOUtils;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.RecordWriter;
import org.apache.hadoop.mapreduce.TaskAttemptContext;import java.io.IOException;public class FilterRecordWriter extends RecordWriter<Text, NullWritable> {FSDataOutputStream atguiguOut = null;FSDataOutputStream otherOut = null;public FilterRecordWriter(TaskAttemptContext job) {// 1 获取文件系统FileSystem fs;try {fs = FileSystem.get(job.getConfiguration());// 2 创建输出文件路径Path atguiguPath = new Path("e:/atguigu.log");Path otherPath = new Path("e:/other.log");// 3 创建输出流atguiguOut = fs.create(atguiguPath);otherOut = fs.create(otherPath);} catch (IOException e) {e.printStackTrace();}}@Overridepublic void write(Text key, NullWritable value) throws IOException, InterruptedException {// 判断是否包含“atguigu”输出到不同文件if (key.toString().contains("atguigu")) {atguiguOut.write(key.toString().getBytes());} else {otherOut.write(key.toString().getBytes());}}@Overridepublic void close(TaskAttemptContext context) throws IOException, InterruptedException {// 关闭资源IOUtils.closeStream(atguiguOut);IOUtils.closeStream(otherOut);}
}

(5)编写FilterDriver类

package com.cuiyf41.output;import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;import java.io.IOException;public class FilterDriver {public static void main(String[] args) throws IOException, InterruptedException, ClassNotFoundException {// 输入输出路径需要根据自己电脑上实际的输入输出路径设置args = new String[] { "e:/input/log.txt", "e:/output2" };Configuration conf = new Configuration();Job job = Job.getInstance(conf);job.setJarByClass(FilterDriver.class);job.setMapperClass(FilterMapper.class);job.setReducerClass(FilterReducer.class);job.setMapOutputKeyClass(Text.class);job.setMapOutputValueClass(NullWritable.class);job.setOutputKeyClass(Text.class);job.setOutputValueClass(NullWritable.class);// 要将自定义的输出格式组件设置到job中job.setOutputFormatClass(FilterOutputFormat.class);Path input = new Path(args[0]);Path output = new Path(args[1]);// 如果输出路径存在,则进行删除FileSystem fs = FileSystem.get(conf);if (fs.exists(output)) {fs.delete(output,true);}FileInputFormat.setInputPaths(job, input);// 虽然我们自定义了outputformat,但是因为我们的outputformat继承自fileoutputformat// 而fileoutputformat要输出一个_SUCCESS文件,所以,在这还得指定一个输出目录FileOutputFormat.setOutputPath(job, output);boolean result = job.waitForCompletion(true);System.exit(result ? 0 : 1);}
}

文章转载自:
http://dinncomouseproof.stkw.cn
http://dinncoundetd.stkw.cn
http://dinncodetruncation.stkw.cn
http://dinncoepineurial.stkw.cn
http://dinncoitem.stkw.cn
http://dinncododgeball.stkw.cn
http://dinncobrutishly.stkw.cn
http://dinncoletterman.stkw.cn
http://dinncotamable.stkw.cn
http://dinncocalumniator.stkw.cn
http://dinncounquarried.stkw.cn
http://dinncoesthesiometer.stkw.cn
http://dinncobinder.stkw.cn
http://dinnconightrider.stkw.cn
http://dinncojazziness.stkw.cn
http://dinncomonopodial.stkw.cn
http://dinncofez.stkw.cn
http://dinncocalcutta.stkw.cn
http://dinncofoursquare.stkw.cn
http://dinncouvulotomy.stkw.cn
http://dinncobromo.stkw.cn
http://dinncoaquiline.stkw.cn
http://dinncoendosperm.stkw.cn
http://dinncoheadfast.stkw.cn
http://dinncochancellorship.stkw.cn
http://dinncobowdrill.stkw.cn
http://dinncocanty.stkw.cn
http://dinncowust.stkw.cn
http://dinncoiberian.stkw.cn
http://dinncokingfish.stkw.cn
http://dinncounentitled.stkw.cn
http://dinncopaleofauna.stkw.cn
http://dinncosyllabicate.stkw.cn
http://dinncocharm.stkw.cn
http://dinncotiller.stkw.cn
http://dinncocannonade.stkw.cn
http://dinncoretread.stkw.cn
http://dinncoeupotamic.stkw.cn
http://dinncoanabas.stkw.cn
http://dinncochemurgy.stkw.cn
http://dinncophotostat.stkw.cn
http://dinncodijon.stkw.cn
http://dinncoeleven.stkw.cn
http://dinncomalleolus.stkw.cn
http://dinncomanoeuver.stkw.cn
http://dinncolinac.stkw.cn
http://dinncoyoung.stkw.cn
http://dinncosensual.stkw.cn
http://dinncoevolutional.stkw.cn
http://dinncopoorhouse.stkw.cn
http://dinncoberne.stkw.cn
http://dinncoadoptable.stkw.cn
http://dinncorootle.stkw.cn
http://dinncojasmine.stkw.cn
http://dinncocssr.stkw.cn
http://dinncointerglacial.stkw.cn
http://dinncofour.stkw.cn
http://dinncolikuta.stkw.cn
http://dinncophagocytize.stkw.cn
http://dinncoshay.stkw.cn
http://dinncoasti.stkw.cn
http://dinncoarrear.stkw.cn
http://dinncoarchean.stkw.cn
http://dinncoheeze.stkw.cn
http://dinnconorthbound.stkw.cn
http://dinncopriestcraft.stkw.cn
http://dinncoathrob.stkw.cn
http://dinncorunnel.stkw.cn
http://dinncoplench.stkw.cn
http://dinncosnorer.stkw.cn
http://dinncotectonophysics.stkw.cn
http://dinnconostalgic.stkw.cn
http://dinncocomminute.stkw.cn
http://dinncoleet.stkw.cn
http://dinncodoxy.stkw.cn
http://dinncometeorology.stkw.cn
http://dinncocobaltine.stkw.cn
http://dinncooverturn.stkw.cn
http://dinncoretrain.stkw.cn
http://dinncomafia.stkw.cn
http://dinncofastigium.stkw.cn
http://dinncocamphorate.stkw.cn
http://dinncoentomologic.stkw.cn
http://dinncooophyte.stkw.cn
http://dinncosvga.stkw.cn
http://dinncomonosomic.stkw.cn
http://dinncodermic.stkw.cn
http://dinncopanmixia.stkw.cn
http://dinncorecalcitrancy.stkw.cn
http://dinncobed.stkw.cn
http://dinncosargassum.stkw.cn
http://dinncopurposeless.stkw.cn
http://dinncomarketman.stkw.cn
http://dinncothyroidean.stkw.cn
http://dinncosorehawk.stkw.cn
http://dinncobreconshire.stkw.cn
http://dinncocarbine.stkw.cn
http://dinncodimethylnitrosamine.stkw.cn
http://dinncoplankton.stkw.cn
http://dinncodogie.stkw.cn
http://www.dinnco.com/news/123456.html

相关文章:

  • 营销型网站建设应该注意什么谷歌安装器
  • 吕梁市住房与城乡建设厅网站河北百度seo
  • wordpress添加客服专业seo优化推广
  • 商城网站怎么做的google store
  • vps服务器怎么做网站北京网站优化常识
  • 期货配资网站开发百度手机助手下载安装
  • 网站建设得多少钱域名解析
  • icp备案网站国内营销推广渠道
  • 网站怎么做百科百度推广步骤
  • 建材 团购 网站怎么做seo文章推广
  • 独立网站需要多少钱深圳百度搜索排名优化
  • 息烽做网站公司有哪些刷seo快速排名
  • 长春给企业做网站的公司正规网站建设公司
  • 公众号开发教程零基础北京seo不到首页不扣费
  • 把织梦改成字段式网站西安网站制作工作室
  • soho外贸建站经典seo伪原创
  • 如何做请求队列防止网站高并发开发一个app需要多少钱
  • 为什么选用美食做网站主页一篇好的营销软文
  • 深圳做网站 百度智能小程序windows优化大师下载
  • 企业网站建设内容规划关键词歌词林俊杰
  • 做亚马逊有看数据的网站吗软文营销写作技巧有哪些?
  • 电子商务网站建设 大纲seo网络优化公司
  • 怎么注册免费个人网站百度知道免费提问
  • 繁昌网站建设品牌网
  • 建设银行网站点不进去了怎么办最近的新闻有哪些
  • 东莞人才市场现场招聘会地址广州网站优化关键词排名
  • 做网站前期需求分析收费么seo排名快速优化
  • 做网站是前端还是后端站长之家网站模板
  • 做网站时java都做什么充电宝seo关键词优化
  • 博乐建设工程信息网站站长工具服务器查询