最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(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ó)家法律
石屏县| 天津市| 侯马市| 论坛| 定安县| 昌图县| 南昌市| 怀集县| 宜川县| 砚山县| 江油市| 米易县| 武胜县| 潜江市| 固始县| 兴和县| 乌兰察布市| 饶阳县| 卢龙县| 潢川县| 巨野县| 班玛县| 揭阳市| 弋阳县| 太仆寺旗| 宜宾县| 阿合奇县| 曲阜市| 海盐县| 秀山| 乐至县| 清苑县| 海丰县| 鹤峰县| 长海县| 洪泽县| 北海市| 永宁县| 阿鲁科尔沁旗| 瑞安市| 晴隆县|