无码av一区二区三区无码,在线观看老湿视频福利,日韩经典三级片,成 人色 网 站 欧美大片在线观看

歡迎光臨散文網(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ó)家法律
安远县| 黔南| 南和县| 兴海县| 鹤壁市| 尼勒克县| 开封县| 安岳县| 瑞安市| 嘉峪关市| 深州市| 宿州市| 柳州市| 石阡县| 泸水县| 栾川县| 汉寿县| 金门县| 宜昌市| 孟州市| 安康市| 上蔡县| 兴宁市| 政和县| 明光市| 徐水县| 涞水县| 南开区| 旬阳县| 通州区| 革吉县| 郴州市| 遵化市| 从江县| 安远县| 南康市| 宣化县| 武山县| 兴仁县| 胶南市| 西贡区|