I want to write an empty mapreduce job, Actually I mean a mapreduce job that doing nothing, Just has a Mapper, a Reducer and a main class. I want it for a test in hortonwoks sandbox 2.1. this is my code:
import java.io.IOException;
import java.util.*;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.conf.*;
import org.apache.hadoop.io.*;
import org.apache.hadoop.mapred.*;
import org.apache.hadoop.util.*;
public class MainClassName {
public static class Map extends MapReduceBase
implements Mapper<IntWritable, Text, IntWritable, Text>
{
private final static IntWritable one = new IntWritable(1);
private Text word = new Text();
public void map(LongWritable key, Text value,
OutputCollector<Text, IntWritable> output,
Reporter reporter) throws IOException
{
output.collect(word, one);
}
}
public static class Reduce extends MapReduceBase
implements Reducer<Text, IntWritable, Text, IntWritable>
{
public void reduce(Text key, Iterator<IntWritable> values,
OutputCollector<Text, IntWritable> output, Reporter reporter)
throws IOException
{
int data = 0;
}
output.collect(key, new IntWritable(data));
}
}
public static void main(String[] args) throws Exception
{
JobConf conf = new JobConf(MainClassName.class);
conf.setJobName("JobName");
conf.setOutputKeyClass(Text.class);
conf.setOutputValueClass(IntWritable.class);
conf.setMapperClass(Map.class);
conf.setCombinerClass(Reduce.class);
conf.setReducerClass(Reduce.class);
conf.setInputFormat(TextInputFormat.class);
conf.setOutputFormat(TextOutputFormat.class);
FileInputFormat.setInputPaths(conf, new Path(args[0]));
FileOutputFormat.setOutputPath(conf, new Path(args[1]));
JobClient.runJob(conf);
}
}
Is it correct? but it gives me an error:
Description Resource Path Location Type The type MainClassName.Map must implement the inherited abstract method Mapper.map(Text, Text, OutputCollector, Reporter) MainClassName.java /mainempty/src line 14 Java Problem
And also I want to know which java files must be imported to run a simple job. Thanks a lot. :)
Your type arguments are a bit muddled. Your mapper is taking a <LongWritable,Text>
pair, and outputting a <Text,IntWritable>
pair. However your class declaration says:
implements Mapper<IntWritable, Text, IntWritable, Text>
Which should read
implements Mapper<LongWritable, Text, Text, LongWritable>
The rest looks OK.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.