hadoop
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了hadoop相关的知识,希望对你有一定的参考价值。
package com.javaMapReduce; import java.io.IOException; import org.apache.hadoop.io.IntWritable; import org.apache.hadoop.io.LongWritable; import org.apache.hadoop.io.Text; import org.apache.hadoop.mapred.JobConf; import org.apache.hadoop.mapred.Mapper; import org.apache.hadoop.mapred.OutputCollector; import org.apache.hadoop.mapred.Reporter; import org.apache.hadoop.mapreduce.Mapper.Context; public class MaxTemperatureMapper extends MapReduceBase implements Mapper<LongWritable, Text, Text, IntWritable> { private static final int MISSING = 9999; @Override public void configure(JobConf arg0) { // TODO Auto-generated method stub } @Override public void close() throws IOException { // TODO Auto-generated method stub } @Override public void map(LongWritable key, Text value, OutputCollector<Text, IntWritable> arg2, Reporter arg3) throws IOException { } @Override public void map(LongWritable key,Text value,Context context) throws IOException,InterruptedException { // TODO Auto-generated method stub String line = value.toString(); String year = line.substring(15,19); int airTemperature; if(line.charAt(87)==‘+‘){ airTemperature = Integer.parseInt(line.substring(88,92)); }else{ airTemperature = Integer.parseInt(line.substring(87,92)); } String quality = line.substring(92,93); if(airTemperature != MISSING && quality.matches("[01459]")){ context.write(new Text(year),new IntWritable(airTemperature)); } } }
以上是关于hadoop的主要内容,如果未能解决你的问题,请参考以下文章