Commits

Anonymous committed 52ae522

import first

Comments (0)

Files changed (13)

+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="src" path="src/main/java"/>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+	<classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/HADOOP"/>
+	<classpathentry kind="output" path="target/classes"/>
+</classpath>
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>MaxTemperature02</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.eclipse.jdt.core.javabuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.eclipse.jdt.core.javanature</nature>
+	</natures>
+</projectDescription>

.settings/com.google.gwt.eclipse.core.prefs

+#Sun Oct 24 16:36:07 JST 2010
+eclipse.preferences.version=1
+filesCopiedToWebInfLib=

.settings/org.eclipse.core.resources.prefs

+#Sun Oct 24 22:55:33 JST 2010
+eclipse.preferences.version=1
+encoding/<project>=UTF-8

output/._SUCCESS.crc

Binary file added.

output/.part-00000.crc

Binary file added.

output/_SUCCESS

Empty file added.

output/part-00000

+1949	111
+1950	22
+#!/bin/sh
+export HADOOP_CLASSPATH=target/classes
+hadoop examples.hadoop.MaxTemperature sample.txt output
+0067011990999991950051507004+68750+023550FM-12+038299999V0203301N00671220001CN9999999N9+00001+99999999999
+0043011990999991950051512004+68750+023550FM-12+038299999V0203201N00671220001CN9999999N9+00221+99999999999
+0043011990999991950051518004+68750+023550FM-12+038299999V0203201N00261220001CN9999999N9-00111+99999999999
+0043012650999991949032412004+62300+010750FM-12+048599999V0202701N00461220001CN0500001N9+01111+99999999999
+0043012650999991949032418004+62300+010750FM-12+048599999V0202701N00461220001CN0500001N9+00781+99999999999

src/main/java/examples/hadoop/MaxTemperature.java

+package examples.hadoop;
+
+import java.io.IOException;
+
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.io.IntWritable;
+import org.apache.hadoop.io.Text;
+import org.apache.hadoop.mapred.FileInputFormat;
+import org.apache.hadoop.mapred.FileOutputFormat;
+import org.apache.hadoop.mapred.JobClient;
+import org.apache.hadoop.mapred.JobConf;
+
+public class MaxTemperature {
+
+    public static void main(String[] args) throws IOException {
+        if (args.length != 2) {
+            System.err.println("Usage: MaxTemperature <input path> <output path>");
+            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.setCombinerClass(MaxTemperatureReducer.class);
+        conf.setReducerClass(MaxTemperatureReducer.class);
+
+        conf.setOutputKeyClass(Text.class);
+        conf.setOutputValueClass(IntWritable.class);
+
+        JobClient.runJob(conf);
+    }
+}

src/main/java/examples/hadoop/MaxTemperatureMapper.java

+package examples.hadoop;
+
+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.MapReduceBase;
+import org.apache.hadoop.mapred.Mapper;
+import org.apache.hadoop.mapred.OutputCollector;
+import org.apache.hadoop.mapred.Reporter;
+
+public class MaxTemperatureMapper extends MapReduceBase implements Mapper<LongWritable, Text, Text, IntWritable> {
+
+    private static final int MISSING = 9999;
+
+    /*
+     * (non-Javadoc)
+     * @see org.apache.hadoop.mapred.Mapper#map(java.lang.Object, java.lang.Object, org.apache.hadoop.mapred.OutputCollector, org.apache.hadoop.mapred.Reporter)
+     */
+    @Override
+    public void map(LongWritable key, Text value, OutputCollector<Text, IntWritable> output, Reporter reporter)
+            throws IOException {
+
+        String line = value.toString();
+        String year = line.substring(15, 19);
+        int airTempreture;
+        if (line.charAt(87) == '+') {
+            airTempreture = Integer.parseInt(line.substring(88, 92));
+        } else {
+            airTempreture = Integer.parseInt(line.substring(87, 92));
+        }
+        String quality = line.substring(92, 93);
+        if (airTempreture != MISSING && quality.matches("[01459]")) {
+            output.collect(new Text(year), new IntWritable(airTempreture));
+        }
+    }
+
+}

src/main/java/examples/hadoop/MaxTemperatureReducer.java

+package examples.hadoop;
+
+import java.io.IOException;
+import java.util.Iterator;
+
+import org.apache.hadoop.io.IntWritable;
+import org.apache.hadoop.io.Text;
+import org.apache.hadoop.mapred.MapReduceBase;
+import org.apache.hadoop.mapred.OutputCollector;
+import org.apache.hadoop.mapred.Reducer;
+import org.apache.hadoop.mapred.Reporter;
+
+public class MaxTemperatureReducer extends MapReduceBase implements Reducer<Text, IntWritable, Text, IntWritable> {
+
+    @Override
+    public void reduce(Text key, Iterator<IntWritable> values, OutputCollector<Text, IntWritable> collector,
+            Reporter reporter) throws IOException {
+        int maxValue = Integer.MIN_VALUE;
+        while (values.hasNext()) {
+            maxValue = Math.max(maxValue, values.next().get());
+        }
+        collector.collect(key, new IntWritable(maxValue));
+    }
+
+}