Created
May 8, 2012 12:26
-
-
Save suzuken/2634559 to your computer and use it in GitHub Desktop.
WordAverage
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package average; | |
import org.apache.hadoop.conf.Configured; | |
import org.apache.hadoop.fs.Path; | |
import org.apache.hadoop.io.FloatWritable; | |
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; | |
import org.apache.hadoop.util.Tool; | |
import org.apache.hadoop.util.ToolRunner; | |
public class WordAverage extends Configured implements Tool { | |
public int run(String[] args) throws Exception { | |
if (args.length != 2) { | |
System.out.printf( | |
"Usage: %s [generic options] <input dir> <output dir>\n", getClass().getSimpleName()); | |
ToolRunner.printGenericCommandUsage(System.out); | |
return -1; | |
} | |
JobConf conf = new JobConf(getConf(), WordAverage.class); | |
conf.setJobName(this.getClass().getName()); | |
FileInputFormat.setInputPaths(conf, new Path(args[0])); | |
FileOutputFormat.setOutputPath(conf, new Path(args[1])); | |
conf.setMapperClass(AverageMapper.class); | |
conf.setReducerClass(AverageReducer.class); | |
conf.setMapOutputKeyClass(Text.class); | |
conf.setMapOutputValueClass(IntWritable.class); | |
conf.setOutputKeyClass(Text.class); | |
conf.setOutputValueClass(FloatWritable.class); | |
JobClient.runJob(conf); | |
return 0; | |
} | |
public static void main(String[] args) throws Exception { | |
int exitCode = ToolRunner.run(new WordAverage(), args); | |
System.exit(exitCode); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment