MapReduce中ArrayWritable 使用指南
更新時間:2014年08月31日 10:29:22 投稿:hebedich
MapReduce是一種編程模型,用于大規(guī)模數據集的并行運算。概念"Map(映射)"和"Reduce(歸約)"和他們的主要思想,都是從函數式編程語言里借來的,還有從矢量編程語言里借來的特性。他極大地方便了編程人員在不會分布式并行編程的情況下,將自己的程序運行在分布式系統(tǒng)上。
在編寫MapReduce程序時,Map和Reduce之間傳遞的數據需要是ArrayList類型的,在調試運行時遇到了這樣的一個錯誤:
java.lang.RuntimeException: java.lang.NoSuchMethodException: org.apache.hadoop.io.ArrayWritable.<init>()
經查詢官網API文檔后發(fā)現這樣的一段話:
A Writable for arrays containing instances of a class. The elements of this writable must all be instances of the same class. If this writable will be the input for a Reducer, you will need to create a subclass that sets the value to be of the proper type. For example: public class IntArrayWritable extends ArrayWritable { public IntArrayWritable() { super(IntWritable.class); } }
原來是要自己實現一個ArrayWritable類的派生類,使用時只要實現兩個構造函數即可
public static class TextArrayWritable extends ArrayWritable { public TextArrayWritable() { super(Text.class); } public TextArrayWritable(String[] strings) { super(Text.class); Text[] texts = new Text[strings.length]; for (int i = 0; i < strings.length; i++) { texts[i] = new Text(strings[i]); } set(texts); } }
相關文章
Springboot WebFlux集成Spring Security實現JWT認證的示例
這篇文章主要介紹了Springboot WebFlux集成Spring Security實現JWT認證的示例,幫助大家更好的理解和學習使用springboot框架,感興趣的朋友可以了解下2021-04-04Spring整合Quartz實現動態(tài)定時器的示例代碼
本篇文章主要介紹了Spring整合Quartz實現動態(tài)定時器的示例代碼,具有一定的參考價值,感興趣的小伙伴們可以參考一下。2017-01-01httpclient模擬post請求json封裝表單數據的實現方法
下面小編就為大家?guī)硪黄猦ttpclient模擬post請求json封裝表單數據的實現方法。小編覺得挺不錯的,現在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2016-12-12通過Docker啟動Solace并在Spring?Boot通過JMS整合Solace的操作方法
本文將介紹如何在Spring中使用,雖然代碼使用的是Spring Boot,但并沒有使用相關starter,跟Spring的整合一樣,可通用,JMS是通過的消息處理框架,可以深入學習一下,不同的MQ在JMS的整合上都是類似的,感興趣的朋友跟隨小編一起看看吧2023-01-01Java NumberFormat格式化float類型的bug
今天小編就為大家分享一篇關于Java NumberFormat格式化float類型的bug,小編覺得內容挺不錯的,現在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧2018-10-10