Hadoop outputCollector
I have a mapreduce progr开发者_如何学JAVAam and is working fine, following are the signatures of map and reduce functions. The outputcollector presently is
output.collect(newtext, new IntWritable(someintegervalue like 5)); //works ok
I need to change this to handle/output double values. (need to divide two integers to get result which is double). I tried changing outputcollector as following
output.collect(newtext, new DoubleWritable(somedoublevalue like 5.1))
and compile/run has issues. Hope to minimize changes in Map and Reduce signatures since the program is running fine, only need to get output in double instead of integers.
Following are current Map Reduce signatures and work fine.
class Map extends MapReduceBase implements Mapper<LongWritable, Text, Text, IntWritable>
map(LongWritable key, Text value, OutputCollector<Text, IntWritable> output, Reporter reporter) throws IOException
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 {
Don't forget that you need to specify the output classes when you're configuring your job, e.g., you'd need to write:
conf.setOutputKeyClass(Text.class);
conf.setOutputValueClass(DoubleWritable.class);
Otherwise it'll complain like this:
"type mismatch value from map: expected org.apache.hadoop.io.IntWritable,
recieved org.apache.hadoop.io.DoubleWritable"
From your comment, it seems you haven't changed the signature everywhere. You need to change them to the following:
class Map extends MapReduceBase implements Mapper<LongWritable, Text, Text, DoubleWritable>
map(LongWritable key, Text value, OutputCollector<Text, DoubleWritable> output, Reporter reporter) throws IOException
public static class Reduce extends MapReduceBase implements Reducer<Text, DoubleWritable, Text, DoubleWritable>
public void reduce(Text key, Iterator<DoubleWritable> values, OutputCollector<Text, DoubleWritable> output, Reporter reporter) throws IOException {
精彩评论