我是用Avro編寫Hadoop MapReduce的初學者,並且不清楚傳遞給map/reduce方法與String之間的區別是什麼,CharSequence還是Utf8?MapReduce與Java中的Avro:字符串與CharSequence與Utf8數據類型
如果字符串只是簡單的像「hello world」那麼該怎麼辦?
使用的CharSequence作爲輸出密鑰類型下面是例如一個簡單的地圖方法,在這種情況下:
public void map(Pair<CharSequence, Integer> datum, AvroCollector<Pair<CharSequence, Integer>> collector, Reporter reporter) throws IOException {
Integer number_one = new Integer(1);
String output_key = "hello world";
collector.collect(new Pair<CharSequence, Integer>(output_key, one));
}
任何幫助表示讚賞!
與此問題有關的警告詞。你可能會想要堅持CharSequence的一個特定實現,比如String,而不是使用通用接口。不同CharSequence實現的hashcode不一定匹配,這可能會導致問題。請參閱http://stackoverflow.com/questions/19728853/apache-avro-map-uses-charsequence-as-key –
@AlexA。好點,它會破壞map和reduce之間的分區。 –