2012-06-15 108 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

相關問題