国产精品天干天干,亚洲毛片在线,日韩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ó)家法律
平顺县| 德阳市| 兰考县| 丘北县| 宜章县| 台南县| 松潘县| 广昌县| 乳山市| 利川市| 确山县| 平塘县| 合川市| 鹿邑县| 陈巴尔虎旗| 黎平县| 泸水县| 麻江县| 邻水| 隆回县| 汤阴县| 石城县| 西乌| 怀来县| 平顶山市| 于都县| 永平县| 台山市| 宁国市| 临桂县| 德兴市| 广南县| 荥经县| 崇阳县| 陈巴尔虎旗| 沈丘县| 上犹县| 辽阳县| 高密市| 米易县| 福鼎市|