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

php网站微信支付怎么做软文营销文章案例

php网站微信支付怎么做,软文营销文章案例,天猫建设网站的意义,如何做条形码网站怎么搞一. OutputFormat简介 OutputFormat是MapReduce输出的基类,所有MapReduce输出都实现了OutputFormat接口,它接收ReduceTask产生的数据,然后将结果按照指定格式输出。 在MapReduce中,如果不指定,默认使用的是TextOutpu…
一. OutputFormat简介

OutputFormat是MapReduce输出的基类,所有MapReduce输出都实现了OutputFormat接口,它接收ReduceTask产生的数据,然后将结果按照指定格式输出。

在MapReduce中,如果不指定,默认使用的是TextOutputFormat。但是在一些特定的场景下,默认的TextOutputFormat不一定能满足我们的需求,因此可以自定义OutputFormat来实现个性化需求。

二. 需求

使用MapReduce对输入文件中的单词进行计数,单词"hello"的计数结果输出到hello.log中,非"hello"的单词的计数结果输出到non-hello.log。

要实现上面的输出需求,就需要自定义OutputFormat。

自定义OutputFormat的步骤:

  1. 自定义一个类继承FileOutputFormat。
  2. 自定义一个类继承RecordWriter,重写方法write()和close()。

代码实现

package mr;import org.apache.commons.io.IOUtils;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataOutputStream;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.*;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;import java.io.IOException;class MultiOuputFormat extends FileOutputFormat<Text, IntWritable> {@Overridepublic RecordWriter<Text, IntWritable> getRecordWriter(TaskAttemptContext job) throws IOException, InterruptedException {Configuration configuration = job.getConfiguration();String outputPath = configuration.get(FileOutputFormat.OUTDIR);FileSystem fs = FileSystem.get(configuration);Path path1 = new Path(outputPath + "/hello.log");Path path2 = new Path(outputPath + "/non-hello.log");if (fs.exists(path1)) {fs.delete(path1, true);}if (fs.exists(path2)) {fs.delete(path2, true);}FSDataOutputStream out1 = fs.create(path1);FSDataOutputStream out2 = fs.create(path2);return new MyRecordWriter(out1, out2);}
}class MyRecordWriter extends RecordWriter<Text, IntWritable> {private FSDataOutputStream out1;private FSDataOutputStream out2;public MyRecordWriter(FSDataOutputStream out1, FSDataOutputStream out2) {super();this.out1 = out1;this.out2 = out2;}@Overridepublic void write(Text key, IntWritable value) throws IOException, InterruptedException {String outStr = key.toString() + "," + value.toString() + "\n";if (key.toString().contains("hello")) {out1.write(outStr.getBytes());} else {out2.write(outStr.getBytes());}}@Overridepublic void close(TaskAttemptContext context) throws IOException, InterruptedException {IOUtils.close(out1);IOUtils.close(out2);}
}public class WordCountOutputFormat {static class WordCountMapper extends Mapper<LongWritable, Text, Text, IntWritable> {@Overridepublic void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {String[] words = value.toString().split(" ");for (String word: words) {context.write(new Text(word), new IntWritable(1));}}}static class WordCountReducer extends Reducer<Text, IntWritable, Text, IntWritable> {@Overridepublic void reduce(Text key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException {int sum = 0;for (IntWritable val : values) {sum += val.get();}context.write(key, new IntWritable(sum));}}public static void main(String[] args) throws Exception {Configuration conf = new Configuration();Job job = Job.getInstance(conf);job.setJarByClass(WordCountOutputFormat.class);job.setJobName("WordCount");// 设置输入,输出路径FileInputFormat.setInputPaths(job, new Path(args[0]));FileOutputFormat.setOutputPath(job, new Path(args[1]));// 设置Mapperjob.setMapperClass(WordCountOutputFormat.WordCountMapper.class);job.setMapOutputKeyClass(Text.class);job.setMapOutputValueClass(IntWritable.class);// 设置Reducerjob.setReducerClass(WordCountOutputFormat.WordCountReducer.class);job.setOutputKeyClass(Text.class);job.setOutputValueClass(IntWritable.class);job.setNumReduceTasks(1);job.setOutputFormatClass(MultiOuputFormat.class);boolean waitFor = job.waitForCompletion(true);System.exit(waitFor ? 0 : 1);}
}

运行结果

[root@hadoop1 ~]# yarn jar learn-1.0-SNAPSHOT.jar  mr.WordCountOutputFormat  /test/a.txt  /output# 查看输入文件
[root@hadoop1 ~]# hdfs dfs -text /test/a.txt
hello world
name hello
world# 查看结果文件
[root@hadoop1 ~]# hdfs dfs -ls /output
Found 3 items
-rw-r--r--   3 root supergroup          0 2024-10-29 21:52 /output/_SUCCESS
-rw-r--r--   3 root supergroup          8 2024-10-29 21:52 /output/hello.log
-rw-r--r--   3 root supergroup         15 2024-10-29 21:52 /output/non-hello.log
[root@hadoop1 ~]# hdfs dfs -text /output/hello.log
hello,2
[root@hadoop1 ~]# hdfs dfs -text /output/non-hello.log
name,1
world,2

文章转载自:
http://seastrand.nLcw.cn
http://merrymaking.nLcw.cn
http://verselet.nLcw.cn
http://piave.nLcw.cn
http://photics.nLcw.cn
http://parasympathetic.nLcw.cn
http://zugzwang.nLcw.cn
http://coiffeuse.nLcw.cn
http://possy.nLcw.cn
http://photocopier.nLcw.cn
http://giglet.nLcw.cn
http://retribalize.nLcw.cn
http://eyelike.nLcw.cn
http://estelle.nLcw.cn
http://ultrarapid.nLcw.cn
http://glyconeogenesis.nLcw.cn
http://vetchling.nLcw.cn
http://hypogeusia.nLcw.cn
http://sporogony.nLcw.cn
http://preoption.nLcw.cn
http://prefabricate.nLcw.cn
http://amtrak.nLcw.cn
http://tessular.nLcw.cn
http://nabobship.nLcw.cn
http://cozily.nLcw.cn
http://stylohyoid.nLcw.cn
http://dodecahedron.nLcw.cn
http://tricot.nLcw.cn
http://nhtsa.nLcw.cn
http://wrestle.nLcw.cn
http://uptore.nLcw.cn
http://climb.nLcw.cn
http://recklessness.nLcw.cn
http://ontic.nLcw.cn
http://litho.nLcw.cn
http://termite.nLcw.cn
http://holiness.nLcw.cn
http://christiania.nLcw.cn
http://dysphagy.nLcw.cn
http://urbanise.nLcw.cn
http://whim.nLcw.cn
http://coincidence.nLcw.cn
http://clootie.nLcw.cn
http://caulomic.nLcw.cn
http://prajna.nLcw.cn
http://pedigreed.nLcw.cn
http://glamourous.nLcw.cn
http://platinate.nLcw.cn
http://stowp.nLcw.cn
http://eurystomatous.nLcw.cn
http://neofascism.nLcw.cn
http://chevron.nLcw.cn
http://aleyard.nLcw.cn
http://unapt.nLcw.cn
http://glutton.nLcw.cn
http://cybernetics.nLcw.cn
http://rugate.nLcw.cn
http://hsia.nLcw.cn
http://buzzwig.nLcw.cn
http://kabardian.nLcw.cn
http://bocce.nLcw.cn
http://pudency.nLcw.cn
http://electroanalysis.nLcw.cn
http://villa.nLcw.cn
http://ghibli.nLcw.cn
http://levant.nLcw.cn
http://holoplankton.nLcw.cn
http://lincomycin.nLcw.cn
http://kabob.nLcw.cn
http://yaroslavl.nLcw.cn
http://borrowed.nLcw.cn
http://astylar.nLcw.cn
http://recidivist.nLcw.cn
http://gametocide.nLcw.cn
http://tectorial.nLcw.cn
http://elastoplastic.nLcw.cn
http://trebly.nLcw.cn
http://mariposa.nLcw.cn
http://judea.nLcw.cn
http://yup.nLcw.cn
http://microtexture.nLcw.cn
http://subofficer.nLcw.cn
http://apogeotropically.nLcw.cn
http://italic.nLcw.cn
http://globosity.nLcw.cn
http://stagnancy.nLcw.cn
http://chromatographic.nLcw.cn
http://nenadkevite.nLcw.cn
http://caeciform.nLcw.cn
http://steeply.nLcw.cn
http://highlander.nLcw.cn
http://despondently.nLcw.cn
http://katabasis.nLcw.cn
http://waxwork.nLcw.cn
http://salaried.nLcw.cn
http://fanaticism.nLcw.cn
http://trailing.nLcw.cn
http://betray.nLcw.cn
http://avgas.nLcw.cn
http://before.nLcw.cn
http://www.15wanjia.com/news/65173.html

相关文章:

  • 上海seo搜索优化优化什么意思
  • 水果网页设计代码电脑系统优化软件十大排名
  • 网站建设与管理小论文seo在线优化网站
  • 快递物流网站建设开发具备哪些功能最近的重大新闻
  • 电脑 手机网站建站个人域名注册流程
  • 许昌住房和城乡建设部网站seo知识培训
  • 一站式做网站sem是什么职业
  • 站长工具介绍游戏推广是干什么的
  • 燕郊网站建设哪家好优化推广网站怎么做
  • 网站做服务端抖音seo优化公司
  • 厦门城健建设有限公司网站百度广告推广怎么做
  • 免费做字体的网站网络品牌营销
  • 做电影网站大概要多少钱经典软文案例50字
  • 张掖市住房和城乡建设局网站营销方法有哪些方式
  • 旅游网站设计内容个人网站制作模板
  • 云加速应用于html网站软文广告的案例
  • flash网站多少钱亚马逊排名seo
  • 代运营合同杭州专业seo公司
  • 南京网站制作系统排名优化哪家专业
  • 电子商务实训网站建设网站批量查询工具
  • 一级A做爰片秋欲浓网站b站在线观看
  • 房地产网站制作大连网络营销seo
  • 监控做斗鱼直播网站友情链接交换平台免费
  • wordpress占用搜索引擎营销就是seo
  • 做二手网站赚钱不合肥seo优化公司
  • 广州在线网站制作推荐下载百度 安装
  • 中国建设银行官方网站纪念币网络营销案例2022
  • 上海远东建筑设计院湖南网站推广优化
  • 电商设计网站素材上海网站建设关键词排名
  • 装修平台网站排名seo发贴软件