国产精品天干天干,亚洲毛片在线,日韩gay小鲜肉啪啪18禁,女同Gay自慰喷水

歡迎光臨散文網(wǎng) 會(huì)員登陸 & 注冊(cè)

期末大數(shù)據(jù)Mapreduce、Hadoop復(fù)習(xí)

2023-06-08 22:01 作者:是mirror  | 我要投稿

第五題代碼理解 有問題 是總數(shù)?

不是 每個(gè)時(shí)間段

修改如下:

import java.io.IOException;

import org.apache.hadoop.conf.Configuration;

import org.apache.hadoop.fs.Path;

import org.apache.hadoop.io.IntWritable;

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 Fifth {

??public static class TimeRangeUsageMapper extends Mapper<Object, Text, Text, IntWritable> {

????private final static IntWritable usageCount = new IntWritable();

????private final static Text timeRange = new Text();


????public void map(Object key, Text value, Context context) throws IOException, InterruptedException {

??????String[] row = value.toString().split(" ");

??????if (!row[0].equals("id")) {

????????String datetime = row[1];

????????int hour = getHour(datetime);

????????int usage = Integer.parseInt(row[10]);

????????String[] res = datetime.split(" ");

????????if (hour >= 12 && hour <= 15) {

??????????timeRange.set(res[0]);

??????????usageCount.set(usage);

??????????context.write(timeRange, usageCount);

????????}

??????}

????}


????private int getHour(String datetime) {

??????String[] datetimeParts = datetime.split(" ");

??????String[] timeParts = datetimeParts[1].split(":");

??????return Integer.parseInt(timeParts[0]);

????}

??}


??public static class TimeRangeUsageReducer extends Reducer<Text, IntWritable, Text, IntWritable> {


????private final IntWritable result = new IntWritable();


????public void reduce(Text key, Iterable<IntWritable> values, Context context)

????????throws IOException, InterruptedException {

??????int sum = 0;

??????for (IntWritable val : values) {

????????sum += val.get();

??????}

??????result.set(sum);

??????context.write(key, result);

????}

??}


??public static void main(String[] args) throws Exception {

????Configuration conf = new Configuration();

????Job job = Job.getInstance(conf, "Bike Data Processor");

????job.setJarByClass(Fifth.class);

????job.setMapperClass(TimeRangeUsageMapper.class);

????job.setReducerClass(TimeRangeUsageReducer.class);

????job.setOutputKeyClass(Text.class);

????job.setOutputValueClass(IntWritable.class);

????FileInputFormat.addInputPath(job, new Path("hdfs://localhost:9000/exam/自己的學(xué)號(hào)"));

????FileOutputFormat.setOutputPath(job, new Path("hdfs://localhost:9000/自己的學(xué)號(hào)/output"));

????System.exit(job.waitForCompletion(true) ? 0 : 1);

??}

}

期末大數(shù)據(jù)Mapreduce、Hadoop復(fù)習(xí)的評(píng)論 (共 條)

分享到微博請(qǐng)遵守國(guó)家法律
上高县| 门头沟区| 丹寨县| 巴林左旗| 禹城市| 瓦房店市| 翁牛特旗| 大新县| 寿光市| 永平县| 台山市| 仙居县| 邵东县| 卢龙县| 当涂县| 桃江县| 闵行区| 中牟县| 巫山县| 江达县| 哈密市| 涞源县| 龙门县| 广东省| 阆中市| 鄂托克前旗| 裕民县| 临海市| 成武县| 舟曲县| 林口县| 齐齐哈尔市| 民权县| 曲靖市| 无锡市| 正镶白旗| 阳朔县| 弥渡县| 镇远县| 蒙城县| 古丈县|