import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.mapreduce.Job; import org.apache.hadoop.fs.Path; import org.apache.hadoop.mapreduce.Mapper; import org.apache.hadoop.mapreduce.Reducer; import org.apache.hadoop.io.IntWritable; import org.apache.hadoop.io.Text; @Configuration( inputPath = "/input", outputPath = "/output" ) public class WordCountJob { public static class WordCountMapper extends Mapper<LongWritable, Text, Text, IntWritable> { // Mapper implementation } public static class WordCountReducer extends Reducer<Text, IntWritable, Text, IntWritable> { // Reducer implementation } public static void main(String[] args) throws Exception { Configuration conf = new Configuration(); Job job = Job.getInstance(conf, "word count"); job.setJarByClass(WordCountJob.class); job.setMapperClass(WordCountMapper.class); job.setCombinerClass(WordCountReducer.class); job.setReducerClass(WordCountReducer.class); job.setOutputKeyClass(Text.class); job.setOutputValueClass(IntWritable.class); // Set input and output paths based on the configuration annotation Path inputPath = new Path(WordCountJob.class.getAnnotation(Configuration.class).inputPath()); Path outputPath = new Path(WordCountJob.class.getAnnotation(Configuration.class).outputPath()); FileInputFormat.addInputPath(job, inputPath); FileOutputFormat.setOutputPath(job, outputPath); System.exit(job.waitForCompletion(true) ? 0 : 1); } }


上一篇:
下一篇:
切换中文