2012-06-15 104 views
0

我有一个Java MR程序。我的地图方法的输出是各种字符串/数字,我现在把它放在一个字符串中。在减少我分割字符串,然后使用参数。现在我想知道这样做是否容易。Hadoop Map Reduce:MapOutputValueClass:Map <String,String>?

我想在那里我存储我的字符串/数字与它描述了每个值的键名为值的地图。这个地图将是我的“超值”(MapOutputValueClass)。

这可能吗?正如我在实况读这个我想我的想法是不实现的:

The key and value classes have to be serializable by the framework and hence need to implement the Writable interface. Additionally, the key classes have to implement the WritableComparable interface to facilitate sorting by the framework.

所以,你会建议我选择我的MapOutputValueClass? :-)也许带一个Map并将其转换为ImmutableBytesWritable?我也不想我的计划......

感谢答案放慢!

+0

同样的事情,你可以发布你的映射器/减速器输入/输出类型的一些示例代码? –

回答

1

你可以用各种字符串/数字编写你自己的类。并将其作为映射器的输出值类和reducer的输入值类传递。

public class MyMapper extends Mapper<Text, Text, Text, Foo>{ 
     .... 
} 
在减速

设置映射输出值类:

job.setMapOutputValueClass(Foo.class); 
public class MyReducer extends Reducer<Text, Foo, Text, LongWritable>{ 
     ... 
} 
在驱动程序

Class Foo{ 
    String A; 
    String B; 
    int c, d; 

     .... 
} 
在你的映射器

记住,当你extendsMapper,您需要填写的顺序类:<KEYIN_CLASS, VALUEIN_CLASS, KEYOUT_CLASS, VALUEOUT_CLASS>,为Reducer

相关问题