Hadoop

Páginas: 2 (345 palabras) Publicado: 29 de enero de 2012
// Aplicacion para encontrar la temperatura maxima en datos climaticos (driver)
import java.io.IOException;

import org.apache.hadoop.fs.Path;

import org.apache.hadoop.io.IntWritable;
importorg.apache.hadoop.io.Text;

import org.apache.hadoop.mapred.FileInputFormat;
import org.apache.hadoop.mapred.FileOutputFormat;
import org.apache.hadoop.mapred.JobClient;
importorg.apache.hadoop.mapred.JobConf;

public class MaxTemperature
{
public static void main(String[] args) throws IOException
{
if (args.length!=2)
{
System.err.println("Uso: MaxTemperature ");System.exit(-1);
}
JobConf conf = new JobConf(MaxTemperature.class);
conf.setJobName("Max temperature");

FileInputFormat.addInputPath(conf, new Path(args[0]));FileOutputFormat.setOutputPath(conf, new Path(args[1]));

conf.setMapperClass(MaxTemperatureMapper.class);
conf.setReducerClass(MaxTemperatureReducer.class);

conf.setOutputKeyClass(Text.class);conf.setOutputValueClass(IntWritable.class);

JobClient.runJob(conf);
}
}

// cc MaxTemperatureMapper Mapper for maximum temperature example
import java.io.IOException;

importorg.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;

import org.apache.hadoop.mapred.MapReduceBase;
import org.apache.hadoop.mapred.Mapper;
importorg.apache.hadoop.mapred.OutputCollector;
import org.apache.hadoop.mapred.Reporter;

public class MaxTemperatureMapper extends MapReduceBase implements Mapper
{
private static final int MISSING = 9999;public void map(LongWritable key, Text value, OutputCollector output, Reporter reporter) throws IOException
{
String line = value.toString();
String year = line.substring(15, 19);
intairTemperature;
if (line.charAt(87) == '+')
{
// parseInt doesn't like leading plus signs
airTemperature = Integer.parseInt(line.substring(88, 92));
}
else
{
airTemperature =...
Leer documento completo

Regístrate para leer el documento completo.

Estos documentos también te pueden resultar útiles

  • HADOOP
  • Hadoop
  • Hadoop
  • Hadoop Correciones
  • Hadoop ensayo asi tipo

Conviértase en miembro formal de Buenas Tareas

INSCRÍBETE - ES GRATIS