This is an automated email from the ASF dual-hosted git repository.
wwei pushed a commit to branch branch-3.2
in repository https://gitbox.apache.org/repos/asf/hadoop.git
The following commit(s) were added to refs/heads/branch-3.2 by this push:
new 0d78725 MAPREDUCE-7174. Mapreduce example wordmedian should handle
generic options. Contributed by Fei Hui.
0d78725 is described below
commit 0d78725fa81f6b35b7bc1a54a57ba6b435b517dd
Author: Weiwei Yang <[email protected]>
AuthorDate: Wed Jan 2 21:39:45 2019 +0800
MAPREDUCE-7174. Mapreduce example wordmedian should handle generic options.
Contributed by Fei Hui.
(cherry picked from commit 9e7196749ee025db7668c648743d1deb72d3ca28)
---
.../main/java/org/apache/hadoop/examples/WordMedian.java | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
diff --git
a/hadoop-mapreduce-project/hadoop-mapreduce-examples/src/main/java/org/apache/hadoop/examples/WordMedian.java
b/hadoop-mapreduce-project/hadoop-mapreduce-examples/src/main/java/org/apache/hadoop/examples/WordMedian.java
index 0ddfd3c..630c6ab 100644
---
a/hadoop-mapreduce-project/hadoop-mapreduce-examples/src/main/java/org/apache/hadoop/examples/WordMedian.java
+++
b/hadoop-mapreduce-project/hadoop-mapreduce-examples/src/main/java/org/apache/hadoop/examples/WordMedian.java
@@ -35,6 +35,7 @@ import org.apache.hadoop.mapreduce.Reducer;
import org.apache.hadoop.mapreduce.TaskCounter;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
+import org.apache.hadoop.util.GenericOptionsParser;
import org.apache.hadoop.util.Tool;
import org.apache.hadoop.util.ToolRunner;
@@ -173,13 +174,15 @@ public class WordMedian extends Configured implements
Tool {
@Override
public int run(String[] args) throws Exception {
- if (args.length != 2) {
+ Configuration conf = new Configuration();
+ String[] otherArgs =
+ new GenericOptionsParser(conf, args).getRemainingArgs();
+ if (otherArgs.length != 2) {
System.err.println("Usage: wordmedian <in> <out>");
return 0;
}
- setConf(new Configuration());
- Configuration conf = getConf();
+ setConf(conf);
Job job = Job.getInstance(conf, "word median");
job.setJarByClass(WordMedian.class);
@@ -188,8 +191,8 @@ public class WordMedian extends Configured implements Tool {
job.setReducerClass(WordMedianReducer.class);
job.setOutputKeyClass(IntWritable.class);
job.setOutputValueClass(IntWritable.class);
- FileInputFormat.addInputPath(job, new Path(args[0]));
- FileOutputFormat.setOutputPath(job, new Path(args[1]));
+ FileInputFormat.addInputPath(job, new Path(otherArgs[0]));
+ FileOutputFormat.setOutputPath(job, new Path(otherArgs[1]));
boolean result = job.waitForCompletion(true);
// Wait for JOB 1 -- get middle value to check for Median
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]