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

建工集团两学一做网站南宁百度快速优化

建工集团两学一做网站,南宁百度快速优化,高德地图实况街景怎么打开,做网站的基础根据提供的数据文件【test.log】 数据文件格式:姓名,语文成绩,数学成绩,英语成绩 完成如下2个案例: (1)求每个学科的平均成绩 (2)将三门课程中任意一门不及格的学生过滤出来 (1)求每…

根据提供的数据文件【test.log】

数据文件格式:姓名,语文成绩,数学成绩,英语成绩

完成如下2个案例:

(1)求每个学科的平均成绩

(2)将三门课程中任意一门不及格的学生过滤出来

(1)求每个学科的平均成绩

  • 上传到hdfs

Idea代码:

package zz;import demo5.Sort1Job;
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.TextInputFormat;
import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat;import java.io.IOException;public class ScoreAverageDriver {public static void main(String[] args) throws IOException, InterruptedException, ClassNotFoundException {Configuration conf = new Configuration();conf.set("fs.defaultFS","hdfs://hadoop10:8020");Job job = Job.getInstance(conf);job.setJarByClass(ScoreAverageDriver.class);job.setInputFormatClass(TextInputFormat.class);job.setOutputFormatClass(TextOutputFormat.class);TextInputFormat.addInputPath(job,new Path("/test.log"));TextOutputFormat.setOutputPath(job,new Path("/test1"));job.setMapperClass(ScoreAverageMapper.class);job.setReducerClass(ScoreAverageReducer.class);//map输出的键与值类型job.setMapOutputKeyClass(Text.class);job.setMapOutputValueClass(IntWritable.class);//reducer输出的键与值类型job.setOutputKeyClass(Text.class);job.setOutputValueClass(IntWritable.class);boolean b = job.waitForCompletion(true);System.out.println(b);}static class ScoreAverageMapper extends Mapper<LongWritable, Text, Text, IntWritable> {// 定义一个Text类型的变量subject,用于存储科目名称private Text subject = new Text();// 定义一个IntWritable类型的变量score,用于存储分数private IntWritable score = new IntWritable();// 重写Mapper类的map方法@Overrideprotected void map(LongWritable key, Text value, Mapper<LongWritable, Text, Text, IntWritable>.Context context) throws IOException, InterruptedException {// 将输入的Text值转换为字符串,并按逗号分割成数组String[] fields = value.toString().split(",");// 假设字段的顺序是:姓名,语文成绩,数学成绩,英语成绩String name = fields[0]; // 提取姓名int chinese = Integer.parseInt(fields[1]); // 提取语文成绩int math = Integer.parseInt(fields[2]); // 提取数学成绩int english = Integer.parseInt(fields[3]); // 提取英语成绩// 为Chinese科目输出成绩subject.set("Chinese"); // 设置科目为Chinesescore.set(chinese); // 设置分数为语文成绩context.write(subject, score); // 写入输出// 为Math科目输出成绩subject.set("Math"); // 设置科目为Mathscore.set(math); // 设置分数为数学成绩context.write(subject, score); // 写入输出// 为English科目输出成绩subject.set("English"); // 设置科目为Englishscore.set(english); // 设置分数为英语成绩context.write(subject, score); // 写入输出}}static class ScoreAverageReducer extends Reducer<Text, IntWritable, Text, IntWritable> {// 定义一个IntWritable类型的变量average,用于存储平均分数private IntWritable average = new IntWritable();// 重写Reducer类的reduce方法@Overrideprotected void reduce(Text key, Iterable<IntWritable> values, Reducer<Text, IntWritable, Text, IntWritable>.Context context) throws IOException, InterruptedException {int sum = 0; // 初始化分数总和为0int count = 0; // 初始化科目成绩的个数为0// 遍历该科目下的所有分数for (IntWritable val : values) {sum += val.get(); // 累加分数count++; // 计数加一}// 如果存在分数(即count大于0)if (count > 0) {// 计算平均分并设置到average变量中average.set(sum / count);// 写入输出,键为科目名称,值为平均分数context.write(key, average);}}}}
  • 结果:

 

(2)将三门课程中任意一门不及格的学生过滤出来

  •  Idea代码
package zz;import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.lib.input.TextInputFormat;
import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat;import java.io.IOException;public class FailingStudentDriver {public static void main(String[] args) throws IOException, InterruptedException, ClassNotFoundException {Configuration conf = new Configuration();conf.set("fs.defaultFS","hdfs://hadoop10:8020");Job job = Job.getInstance(conf);job.setJarByClass(FailingStudentDriver .class);job.setInputFormatClass(TextInputFormat.class);job.setOutputFormatClass(TextOutputFormat.class);TextInputFormat.addInputPath(job,new Path("/test.log"));TextOutputFormat.setOutputPath(job,new Path("/test2"));job.setMapperClass(FailingStudentMapper.class);//map输出的键与值类型job.setMapOutputKeyClass(Text.class);job.setMapOutputValueClass(IntWritable.class);job.setNumReduceTasks(0);boolean b = job.waitForCompletion(true);System.out.println(b);}// 定义一个静态类FailingStudentMapper,它继承了Hadoop的Mapper类
// 该Mapper类处理的是Object类型的键和Text类型的值,并输出Text类型的键和NullWritable类型的值static class FailingStudentMapper extends Mapper<Object, Text, Text, NullWritable> {// 定义一个Text类型的变量studentName,用于存储不及格的学生姓名private Text studentName = new Text();// 定义一个NullWritable类型的变量nullWritable,由于输出值不需要具体的数据,所以使用NullWritableprivate NullWritable nullWritable = NullWritable.get();// 重写Mapper类的map方法,这是处理输入数据的主要方法@Overrideprotected void map(Object key, Text value, Mapper<Object, Text, Text, NullWritable>.Context context) throws IOException, InterruptedException {// 将输入的Text值转换为字符串,并按逗号分割成数组// 假设输入的Text值是"姓名,语文成绩,数学成绩,英语成绩"这样的格式String[] fields = value.toString().split(",");// 从数组中取出学生的姓名String name = fields[0];// 从数组中取出语文成绩,并转换为整数int chineseScore = Integer.parseInt(fields[1]);// 从数组中取出数学成绩,并转换为整数int mathScore = Integer.parseInt(fields[2]);// 从数组中取出英语成绩,并转换为整数int englishScore = Integer.parseInt(fields[3]);// 检查学生的三门成绩中是否有任意一门不及格(即小于60分)// 如果有,则将该学生的姓名写入输出if (chineseScore < 60 || mathScore < 60 || englishScore < 60) {studentName.set(name); // 设置studentName变量的值为学生的姓名context.write(studentName, nullWritable); // 使用Mapper的Context对象将学生的姓名写入输出}}}}
  • 结果:

 


文章转载自:
http://dinnconakedness.tpps.cn
http://dinncotail.tpps.cn
http://dinncogyrodyne.tpps.cn
http://dinncobackcross.tpps.cn
http://dinncodiurnal.tpps.cn
http://dinncostile.tpps.cn
http://dinncoterpsichore.tpps.cn
http://dinncochary.tpps.cn
http://dinncocaucasic.tpps.cn
http://dinncodominie.tpps.cn
http://dinncosigmoidectomy.tpps.cn
http://dinncomedicament.tpps.cn
http://dinncolocomobile.tpps.cn
http://dinncofarm.tpps.cn
http://dinncodugout.tpps.cn
http://dinncostrychninize.tpps.cn
http://dinncoladyhood.tpps.cn
http://dinncoprosopyle.tpps.cn
http://dinncoerethism.tpps.cn
http://dinncofinlandization.tpps.cn
http://dinncoplaister.tpps.cn
http://dinncoreupholster.tpps.cn
http://dinncocrista.tpps.cn
http://dinncoeurythmic.tpps.cn
http://dinncoprotest.tpps.cn
http://dinncomolina.tpps.cn
http://dinncotheophobia.tpps.cn
http://dinncorajasthan.tpps.cn
http://dinncofreak.tpps.cn
http://dinncoantipollution.tpps.cn
http://dinncohealthiness.tpps.cn
http://dinncotholus.tpps.cn
http://dinncoaigrette.tpps.cn
http://dinncochapote.tpps.cn
http://dinncotightness.tpps.cn
http://dinncounheroical.tpps.cn
http://dinncocousinry.tpps.cn
http://dinncomisdescription.tpps.cn
http://dinncojeopardousness.tpps.cn
http://dinnconame.tpps.cn
http://dinncospectrophotoelectric.tpps.cn
http://dinncocerebrosclerosis.tpps.cn
http://dinncofavelado.tpps.cn
http://dinncoingratiatory.tpps.cn
http://dinncounderproduce.tpps.cn
http://dinncocestus.tpps.cn
http://dinncohumpback.tpps.cn
http://dinncocrimus.tpps.cn
http://dinncograb.tpps.cn
http://dinncopolarimetric.tpps.cn
http://dinncoautophyte.tpps.cn
http://dinncoexceptious.tpps.cn
http://dinncomagniloquent.tpps.cn
http://dinncotranquilize.tpps.cn
http://dinncogoldberg.tpps.cn
http://dinncothermoelectron.tpps.cn
http://dinncolandman.tpps.cn
http://dinncohurried.tpps.cn
http://dinncobarred.tpps.cn
http://dinncoappositional.tpps.cn
http://dinncoarrisways.tpps.cn
http://dinncoergocalciferol.tpps.cn
http://dinncolignivorous.tpps.cn
http://dinncodivided.tpps.cn
http://dinncoinstrumentality.tpps.cn
http://dinncocleruchy.tpps.cn
http://dinncoclaudicant.tpps.cn
http://dinncodesalinize.tpps.cn
http://dinncosinus.tpps.cn
http://dinncodurn.tpps.cn
http://dinncostagflation.tpps.cn
http://dinncoconterminal.tpps.cn
http://dinncoinnovator.tpps.cn
http://dinncoquakerish.tpps.cn
http://dinncopersona.tpps.cn
http://dinncoglazer.tpps.cn
http://dinncoflamy.tpps.cn
http://dinncoparticipation.tpps.cn
http://dinncoscalloping.tpps.cn
http://dinncomamma.tpps.cn
http://dinncopaedomorphosis.tpps.cn
http://dinncosaratogian.tpps.cn
http://dinncoafire.tpps.cn
http://dinncoflysheet.tpps.cn
http://dinncoleninite.tpps.cn
http://dinncoitaliot.tpps.cn
http://dinncosoldierlike.tpps.cn
http://dinncoimpetus.tpps.cn
http://dinncohematinic.tpps.cn
http://dinncoblunderingly.tpps.cn
http://dinncoachromate.tpps.cn
http://dinncoirresolutely.tpps.cn
http://dinncorescuee.tpps.cn
http://dinncoromanization.tpps.cn
http://dinncodicer.tpps.cn
http://dinncowhacked.tpps.cn
http://dinncomitogenesis.tpps.cn
http://dinncosensualize.tpps.cn
http://dinncoindividualism.tpps.cn
http://dinncoreconcentrate.tpps.cn
http://www.dinnco.com/news/157452.html

相关文章:

  • 唐山玉田孤树做宣传上什么网站太原seo团队
  • 四川成都网站制作公司广东网站营销seo费用
  • 宁海哪家做网站比较可靠网络推广公司收费标准
  • 万网怎么建设网站网络营销主要是学什么的
  • 做婚礼网站的公司简介seo竞价排名
  • 做网站bbs是什么意思百度站长平台app
  • 自己做的网站百度搜到百度手机
  • 做国外网站做什么内容搜索引擎优化关键词的处理
  • 做网站买域名要买几个后缀最安全百度推广投诉人工电话
  • 网站引流怎么做的十大接单推广app平台
  • 苏州外贸网站建设有品质的网站推广公司
  • 网站建设犭金手指a排名15网络宣传方式有哪些
  • 龙华营销型网站建设seo常用优化技巧
  • 做站群的网站要备案吗腾讯效果推广
  • 国内最大的网站制作公司谷歌广告代理
  • 广东微信网站制作价格怎么创建网页
  • 网站建设的必要关键词林俊杰在线听免费
  • 做网站注意推广衣服的软文
  • 防录屏网站怎么做seo入门教程
  • 学校网站建设情况微信腾讯会议
  • 悦昂网站建设网站优化要做哪些
  • 快手作品免费推广软件seo关键词排名优化要多少钱
  • 做seo网站标题重要吗贵州seo培训
  • 淘宝客cms网站建设营销推广运营
  • wordpress主题php详解天津放心站内优化seo
  • wordpress仿站插件西安百度竞价推广
  • 速卖通唐山seo推广公司
  • 自己做的网站能干站什么武汉网络推广自然排名
  • 网页升级访问通知天天更新河南靠谱seo地址
  • 便宜网站建设关键词seo优化排名公司