2011-10-10 40 views
1

我有一个mapreduce程序,工作正常,以下是map和reduce函数的签名。输出集合目前是Hadoop outputCollector

output.collect(newtext, new IntWritable(someintegervalue like 5)); //works ok 

我需要改变这个来处理/输出double值。 (需要分两个整数才能得到双倍的结果)。 我试图改变outputcollector如下

output.collect(newtext, new DoubleWritable(somedoublevalue like 5.1))

和编译/运行有问题。希望尽量减少Map和Reduce签名的变化,因为程序运行良好,只需要输出double而不是整数。

以下是当前地图缩小签名并正常工作。

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 { 
+0

“编译/运行有问题” - 它们是什么? –

+0

我试着改变outputcollector如下output.collect(newtext,新DoubleWritable(somedoublevalue像5.1))它抱怨Reducer签名是不兼容的。我需要得到我的输出在双重,而不是整数(目前正在工作正常)。 –

回答

1

从你的评论看来,你似乎并没有改变任何地方的签名。您需要将其更改为以下:

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 { 
2

不要忘记,你需要指定输出类,当你配置你的工作,例如,你需要写:

conf.setOutputKeyClass(Text.class); 
conf.setOutputValueClass(DoubleWritable.class); 

否则,它会抱怨这样的:

"type mismatch value from map: expected org.apache.hadoop.io.IntWritable, 
recieved org.apache.hadoop.io.DoubleWritable"