From 4888b16a4355241d5ef64e975c1167124f9a8b49 Mon Sep 17 00:00:00 2001 From: Chris Nauroth Date: Tue, 10 Jun 2014 17:48:52 +0000 Subject: [PATCH] MAPREDUCE-5886. Allow wordcount example job to accept multiple input paths. Contributed by Chris Nauroth. git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1601704 13f79535-47bb-0310-9956-ffa450edef68 --- hadoop-mapreduce-project/CHANGES.txt | 3 +++ .../java/org/apache/hadoop/examples/WordCount.java | 11 +++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/hadoop-mapreduce-project/CHANGES.txt b/hadoop-mapreduce-project/CHANGES.txt index 79ba4d0ede..70d1d7d68c 100644 --- a/hadoop-mapreduce-project/CHANGES.txt +++ b/hadoop-mapreduce-project/CHANGES.txt @@ -207,6 +207,9 @@ Release 2.5.0 - UNRELEASED MAPREDUCE-5899. Support incremental data copy in DistCp. (jing9) + MAPREDUCE-5886. Allow wordcount example job to accept multiple input paths. + (cnauroth) + OPTIMIZATIONS BUG FIXES diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-examples/src/main/java/org/apache/hadoop/examples/WordCount.java b/hadoop-mapreduce-project/hadoop-mapreduce-examples/src/main/java/org/apache/hadoop/examples/WordCount.java index 48c02fe1e1..8634130767 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-examples/src/main/java/org/apache/hadoop/examples/WordCount.java +++ b/hadoop-mapreduce-project/hadoop-mapreduce-examples/src/main/java/org/apache/hadoop/examples/WordCount.java @@ -68,8 +68,8 @@ public class WordCount { public static void main(String[] args) throws Exception { Configuration conf = new Configuration(); String[] otherArgs = new GenericOptionsParser(conf, args).getRemainingArgs(); - if (otherArgs.length != 2) { - System.err.println("Usage: wordcount "); + if (otherArgs.length < 2) { + System.err.println("Usage: wordcount [...] "); System.exit(2); } Job job = new Job(conf, "word count"); @@ -79,8 +79,11 @@ public class WordCount { job.setReducerClass(IntSumReducer.class); job.setOutputKeyClass(Text.class); job.setOutputValueClass(IntWritable.class); - FileInputFormat.addInputPath(job, new Path(otherArgs[0])); - FileOutputFormat.setOutputPath(job, new Path(otherArgs[1])); + for (int i = 0; i < otherArgs.length - 1; ++i) { + FileInputFormat.addInputPath(job, new Path(otherArgs[i])); + } + FileOutputFormat.setOutputPath(job, + new Path(otherArgs[otherArgs.length - 1])); System.exit(job.waitForCompletion(true) ? 0 : 1); } }