zoukankan      html  css  js  c++  java
  • hadoop自己写的最高温度程序源码

    package com.teset;
    
    import java.io.IOException;
    import java.util.StringTokenizer;
    
    import org.apache.hadoop.conf.Configuration;
    import org.apache.hadoop.conf.Configured;
    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.FileInputFormat;
    import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
    import org.apache.hadoop.util.Tool;
    import org.apache.hadoop.util.ToolRunner;
    
    public class Tempreature extends Configured implements Tool {
        // 输入的是行偏移量,一行文本,输出的是 一个年份 最高温度
        public static class TemMapper extends
                Mapper<LongWritable, Text, Text, IntWritable> {
    
            @Override
            protected void map(LongWritable key, Text value,
                    Mapper<LongWritable, Text, Text, IntWritable>.Context context)
                    throws IOException, InterruptedException {
                // map处理数据
                String str = value.toString();
                String year = null;
                int Maxtemp = 0;
                StringTokenizer tokenstr = new StringTokenizer(str);
                int i=0;
                while (tokenstr.hasMoreTokens()) {
                    String tempstr = tokenstr.nextToken();
                    i++;
                    if (i==1){
                        year =tempstr;
                        continue;
                    }else if (i==5&&Integer.parseInt(tempstr)!=-9999){  
                        int tepMax = Integer.parseInt(tempstr);
                        Maxtemp =Math.max(tepMax, Maxtemp);
                        context.write(new Text(year), new IntWritable(Maxtemp));
                        break;
                    }
    
                    }
    
                }
    
            }
    
        public static class TempReducer extends
                Reducer<Text, IntWritable, Text, IntWritable> {
    
            @Override
            protected void reduce(Text key, Iterable<IntWritable> values,
                    Reducer<Text, IntWritable, Text, IntWritable>.Context context)
                    throws IOException, InterruptedException {
                int Maxtem = Integer.MIN_VALUE;
                for (IntWritable value:values){
                    Maxtem = Math.max(Maxtem, value.get());
                }
                context.write(key, new IntWritable(Maxtem));
            }
    
        }
    
        public static void main(String[] args) throws Exception {
            int res = ToolRunner.run(new Configuration(), new Tempreature(), args);
            System.exit(res);
        }
    
        @Override
        public int run(String[] arg0) throws Exception {
            Configuration conf = getConf();
            Job job = new Job(conf,"MaxTem");//任务名
            job.setJarByClass(Tempreature.class);//指定class
                //输入和输出流
            FileInputFormat.addInputPath(job, new Path(arg0[0]));
            FileOutputFormat.setOutputPath(job, new Path(arg0[1]));    
            job.setMapperClass(TemMapper.class);//map
            job.setReducerClass(TempReducer.class);
            job.setCombinerClass(TempReducer.class);
            job.setOutputValueClass(IntWritable.class);
            job.setOutputKeyClass(Text.class);
            job.waitForCompletion(true);
            return job.isSuccessful()?0:1;
    
        }
    
    }
    
  • 相关阅读:
    克隆用户过狗提权
    一个JS引发的血案
    python-标识符(Identifiers)和关键字(keywords)
    提取nmap扫描出来的xml文件
    Hydra扫描姿势
    Senparc.Weixin.MP SDK 微信公众平台开发教程(十二):OAuth2.0说明
    Senparc.Weixin.MP SDK 微信公众平台开发教程(十一):高级接口说明
    Senparc.Weixin.MP SDK 微信公众平台开发教程(十):多客服接口说明
    Senparc.Weixin.MP SDK 微信公众平台开发教程(九):自定义菜单接口说明
    Senparc.Weixin.MP SDK 微信公众平台开发教程(八):通用接口说明
  • 原文地址:https://www.cnblogs.com/mrcharles/p/11879930.html
Copyright © 2011-2022 走看看