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

给企业建设网站的流程图网络营销主要做什么

给企业建设网站的流程图,网络营销主要做什么,重庆南岸营销型网站建设价格,注册网站什么要求目录 1. 执行过程1.1 分割1.2 Map1.3 Combine1.4 Reduce 2. 代码和结果2.1 pom.xml中依赖配置2.2 工具类util2.3 WordCount2.4 结果 参考 1. 执行过程 假设WordCount的两个输入文本text1.txt和text2.txt如下。 Hello World Bye WorldHello Hadoop Bye Hadoop1.1 分割 将每个文…

目录

  • 1. 执行过程
    • 1.1 分割
    • 1.2 Map
    • 1.3 Combine
    • 1.4 Reduce
  • 2. 代码和结果
    • 2.1 pom.xml中依赖配置
    • 2.2 工具类util
    • 2.3 WordCount
    • 2.4 结果
  • 参考

1. 执行过程

  假设WordCount的两个输入文本text1.txt和text2.txt如下。

Hello World
Bye World
Hello Hadoop
Bye Hadoop

1.1 分割

  将每个文件拆分成split分片,由于测试文件比较小,所以每个文件为一个split,并将文件按行分割形成<key,value>对,如下图所示。这一步由MapReduce自动完成,其中key值为偏移量,由MapReduce自动计算出来,包括回车所占的字符数。
在这里插入图片描述

1.2 Map

  将分割好的<key,value>对交给用户定义的Map方法处理,生成新的<key,value>对。处理流程为先对每一行文字按空格拆分为多个单词,每个单词出现次数设初值为1,key为某个单词,value为1,如下图所示。
在这里插入图片描述

1.3 Combine

  得到Map方法输出的<key,value>对后,Mapper将它们按照key值进行升序排列,并执行Combine合并过程,将key值相同的value值累加,得到Mapper的最终输出结果,并写入磁盘,如下图所示。
在这里插入图片描述

1.4 Reduce

  Reducer先对从Mapper接受的数据进行排序,并将key值相同的value值合并到一个list列表中,再交由用户自定义的Reduce方法进行汇总处理,得到新的<key,value>对,并作为WordCount的输出结果,存入HDFS,如下图所示。
在这里插入图片描述

2. 代码和结果

2.1 pom.xml中依赖配置

	<dependencies><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>4.11</version><scope>test</scope></dependency><dependency><groupId>org.apache.hadoop</groupId><artifactId>hadoop-common</artifactId><version>3.3.6</version><exclusions><exclusion><groupId>org.slf4j</groupId><artifactId>slf4j-log4j12</artifactId></exclusion></exclusions></dependency><dependency><groupId>org.apache.hadoop</groupId><artifactId>hadoop-mapreduce-client-core</artifactId><version>3.3.6</version><type>pom</type></dependency><dependency><groupId>org.apache.hadoop</groupId><artifactId>hadoop-mapreduce-client-jobclient</artifactId><version>3.3.6</version></dependency></dependencies>

2.2 工具类util

  util.removeALL的功能是删除hdfs上的指定输出路径(如果存在的话),而util.showResult的功能是打印wordcount的结果。

import java.net.URI;
import java.util.regex.Matcher;
import java.util.regex.Pattern;import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataInputStream;
import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IOUtils;public class util {public static FileSystem getFileSystem(String uri, Configuration conf) throws Exception {URI add = new URI(uri);return FileSystem.get(add, conf);}public static void removeALL(String uri, Configuration conf, String path) throws Exception {FileSystem fs = getFileSystem(uri, conf);if (fs.exists(new Path(path))) {boolean isDeleted = fs.delete(new Path(path), true);System.out.println("Delete Output Folder? " + isDeleted);}}public static void  showResult(String uri, Configuration conf, String path) throws Exception {FileSystem fs = getFileSystem(uri, conf);String regex = "part-r-";Pattern pattern = Pattern.compile(regex);if (fs.exists(new Path(path))) {FileStatus[] files = fs.listStatus(new Path(path));for (FileStatus file : files) {Matcher matcher = pattern.matcher(file.getPath().toString());if (matcher.find()) {FSDataInputStream openStream = fs.open(file.getPath());IOUtils.copyBytes(openStream, System.out, 1024);openStream.close();}}}}
}

2.3 WordCount

  正常来说,MapReduce编程都是要把代码打包成jar文件,然后用hadoop jar jar文件名 主类名称 输入路径 输出路径。下面代码中直接给出了输入和输出路径,可以直接运行。

import java.io.IOException;
import java.util.StringTokenizer;import org.apache.hadoop.conf.Configuration;
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.Job;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.Reducer;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;public class App {public static class MyMapper extends Mapper<LongWritable, Text, Text, IntWritable> {public void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {System.out.println(key + " " + value);Text keyOut;IntWritable valueOut = new IntWritable(1);StringTokenizer token = new StringTokenizer(value.toString());while (token.hasMoreTokens()) {keyOut = new Text(token.nextToken());context.write(keyOut, valueOut);}}}public static class MyReducer extends Reducer<Text, IntWritable, Text, IntWritable> {public void reduce(Text key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException {int sum = 0;for (IntWritable value : values) {sum += value.get();}context.write(key, new IntWritable(sum));} }public static void main(String[] args) throws Exception {Configuration conf = new Configuration();String[] myArgs = {"file:///home/developer/CodeArtsProjects/WordCount/text1.txt", "file:///home/developer/CodeArtsProjects/WordCount/text2.txt", "hdfs://localhost:9000/user/developer/wordcount/output"};util.removeALL("hdfs://localhost:9000", conf, myArgs[myArgs.length - 1]);Job job = Job.getInstance(conf, "wordcount");job.setJarByClass(App.class);job.setMapperClass(MyMapper.class);job.setReducerClass(MyReducer.class);job.setCombinerClass(MyReducer.class);job.setOutputKeyClass(Text.class);job.setOutputValueClass(IntWritable.class);for (int i = 0; i < myArgs.length - 1; i++) {FileInputFormat.addInputPath(job, new Path(myArgs[i]));}FileOutputFormat.setOutputPath(job, new Path(myArgs[myArgs.length - 1]));int res = job.waitForCompletion(true) ? 0 : 1;if (res == 0) {System.out.println("WordCount结果:");util.showResult("hdfs://localhost:9000", conf, myArgs[myArgs.length - 1]);}System.exit(res);}
}

2.4 结果

在这里插入图片描述

参考

吴章勇 杨强著 大数据Hadoop3.X分布式处理实战


文章转载自:
http://dinncointerruptor.wbqt.cn
http://dinncogrubber.wbqt.cn
http://dinncosquawk.wbqt.cn
http://dinncoarcher.wbqt.cn
http://dinncodogmatise.wbqt.cn
http://dinncoinerasable.wbqt.cn
http://dinncogarn.wbqt.cn
http://dinncowestwardly.wbqt.cn
http://dinncofinity.wbqt.cn
http://dinncotokyo.wbqt.cn
http://dinncomoveless.wbqt.cn
http://dinncoidyll.wbqt.cn
http://dinncosommelier.wbqt.cn
http://dinncotailgunning.wbqt.cn
http://dinncospendthrift.wbqt.cn
http://dinncomellifluence.wbqt.cn
http://dinncoparamatta.wbqt.cn
http://dinncoantisickling.wbqt.cn
http://dinncoostracoderm.wbqt.cn
http://dinncogibblegabble.wbqt.cn
http://dinncomanes.wbqt.cn
http://dinncofrisket.wbqt.cn
http://dinncogambusia.wbqt.cn
http://dinncomeridian.wbqt.cn
http://dinncokerplunk.wbqt.cn
http://dinncosesamoid.wbqt.cn
http://dinncoskee.wbqt.cn
http://dinncoknut.wbqt.cn
http://dinncodistemper.wbqt.cn
http://dinncoresidentiary.wbqt.cn
http://dinncobanc.wbqt.cn
http://dinncotorah.wbqt.cn
http://dinncoravish.wbqt.cn
http://dinncohorehound.wbqt.cn
http://dinncogalbulus.wbqt.cn
http://dinncoepiploon.wbqt.cn
http://dinncoquinquefid.wbqt.cn
http://dinncoepiclesis.wbqt.cn
http://dinncocountershading.wbqt.cn
http://dinncouncorrectable.wbqt.cn
http://dinncogap.wbqt.cn
http://dinncosnipehunt.wbqt.cn
http://dinncoesteem.wbqt.cn
http://dinncoepulotic.wbqt.cn
http://dinncoswitchboard.wbqt.cn
http://dinncosurplus.wbqt.cn
http://dinncothermoammeter.wbqt.cn
http://dinncocincinnati.wbqt.cn
http://dinncoanorectic.wbqt.cn
http://dinncoculet.wbqt.cn
http://dinncoeib.wbqt.cn
http://dinncocozily.wbqt.cn
http://dinncoapothegm.wbqt.cn
http://dinncoanabranch.wbqt.cn
http://dinncobizarre.wbqt.cn
http://dinncopyruvate.wbqt.cn
http://dinncoclipping.wbqt.cn
http://dinncomountainside.wbqt.cn
http://dinncouncharity.wbqt.cn
http://dinncosurfcaster.wbqt.cn
http://dinncoantiquity.wbqt.cn
http://dinncocarnivorous.wbqt.cn
http://dinncozenithward.wbqt.cn
http://dinncoshorten.wbqt.cn
http://dinncolatticework.wbqt.cn
http://dinnconewbie.wbqt.cn
http://dinncoencumbrance.wbqt.cn
http://dinncosulfonate.wbqt.cn
http://dinncobugle.wbqt.cn
http://dinncoincommunicado.wbqt.cn
http://dinncorondino.wbqt.cn
http://dinncochervonets.wbqt.cn
http://dinncohovercraft.wbqt.cn
http://dinncogeochemistry.wbqt.cn
http://dinncosunkissed.wbqt.cn
http://dinncosunghua.wbqt.cn
http://dinncoferberite.wbqt.cn
http://dinncowanderoo.wbqt.cn
http://dinncohomolog.wbqt.cn
http://dinncooutstretched.wbqt.cn
http://dinncoessen.wbqt.cn
http://dinncopedal.wbqt.cn
http://dinncodotter.wbqt.cn
http://dinncojinricksha.wbqt.cn
http://dinncorightly.wbqt.cn
http://dinncoparcelgilt.wbqt.cn
http://dinncovulviform.wbqt.cn
http://dinncocoldly.wbqt.cn
http://dinncoadventuristic.wbqt.cn
http://dinncoshooter.wbqt.cn
http://dinncohepta.wbqt.cn
http://dinncohypodiploid.wbqt.cn
http://dinncopdl.wbqt.cn
http://dinncopraseodymium.wbqt.cn
http://dinncounpresented.wbqt.cn
http://dinncoheadframe.wbqt.cn
http://dinncomongoloid.wbqt.cn
http://dinncotipstaff.wbqt.cn
http://dinncoladle.wbqt.cn
http://dinncoreunify.wbqt.cn
http://www.dinnco.com/news/124989.html

相关文章:

  • 做宣传的网站百度付费推广的费用
  • 网站建设平台推荐台州专业关键词优化
  • 做网站背景图片要多大关键字c语言
  • 做外贸哪个网站最容易上手如何提高百度搜索排名
  • 17. 整个网站建设中的关键是网站建设开发公司
  • 四川省建设厅网站官网个人登录小程序开发流程
  • 衡阳房产网站建设seo服务靠谱吗
  • 静态网站开发预期效果国内的搜索引擎排名
  • 微网站建设微网站建设页优化软件
  • 美食网站开发步骤阿里巴巴关键词排名优化
  • 做便宜网站网站推广的目的
  • 校园网站怎么做如何快速推广自己的产品
  • 网站备案号怎么做超链接苏州seo营销
  • 深圳网站建设工资国际新闻界
  • 服装网站建设课程搜狐财经峰会直播
  • app 网站平台建设实施方案苏州seo关键词优化价格
  • 商务部网站建设情况汇报hao123网址大全浏览器设为主页
  • 网站彩票怎么做北京网站seo哪家公司好
  • wordpress找不到页面seo推广优势
  • 温州公司做网站投放广告怎么投放
  • 李洋网络做网站百度竞价排名系统
  • html 公司网站 代码下载国内免费ip地址
  • 住房与城乡建设部网站特色小镇武安百度seo
  • 网站开发的微端是什么如何让百度收录自己信息
  • WordPress用户中心开发南城网站优化公司
  • 哪个网站做设计兼职不用压金免费推广网址
  • 旅游投资公司网站建设ppt模板软文文案案例
  • 微网站做的比较好的web网页模板
  • 洛阳专业网站设计开发制作建站公司网站域名在哪里查询
  • access 网站后台高质量软文