MapReduce中ArrayWritable 使用指南
在編寫MapReduce程序時,Map和Reduce之間傳遞的數(shù)據(jù)需要是ArrayList類型的,在調(diào)試運行時遇到了這樣的一個錯誤:
java.lang.RuntimeException: java.lang.NoSuchMethodException: org.apache.hadoop.io.ArrayWritable.<init>()
經(jīng)查詢官網(wǎng)API文檔后發(fā)現(xiàn)這樣的一段話:
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); } }
原來是要自己實現(xiàn)一個ArrayWritable類的派生類,使用時只要實現(xiàn)兩個構(gòu)造函數(shù)即可
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); } }
- MongoDB中MapReduce編程模型使用實例
- 用PHP和Shell寫Hadoop的MapReduce程序
- java連接hdfs ha和調(diào)用mapreduce jar示例
- Mongodb中MapReduce實現(xiàn)數(shù)據(jù)聚合方法詳解
- JavaScript mapreduce工作原理簡析
- MongoDB中的MapReduce簡介
- Java函數(shù)式編程(七):MapReduce
- Java/Web調(diào)用Hadoop進(jìn)行MapReduce示例代碼
- MongoDB中MapReduce的使用方法詳解
- 通用MapReduce程序復(fù)制HBase表數(shù)據(jù)
相關(guān)文章
Springboot WebFlux集成Spring Security實現(xiàn)JWT認(rèn)證的示例
這篇文章主要介紹了Springboot WebFlux集成Spring Security實現(xiàn)JWT認(rèn)證的示例,幫助大家更好的理解和學(xué)習(xí)使用springboot框架,感興趣的朋友可以了解下2021-04-04Spring整合Quartz實現(xiàn)動態(tài)定時器的示例代碼
本篇文章主要介紹了Spring整合Quartz實現(xiàn)動態(tài)定時器的示例代碼,具有一定的參考價值,感興趣的小伙伴們可以參考一下。2017-01-01httpclient模擬post請求json封裝表單數(shù)據(jù)的實現(xiàn)方法
下面小編就為大家?guī)硪黄猦ttpclient模擬post請求json封裝表單數(shù)據(jù)的實現(xiàn)方法。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2016-12-12通過Docker啟動Solace并在Spring?Boot通過JMS整合Solace的操作方法
本文將介紹如何在Spring中使用,雖然代碼使用的是Spring Boot,但并沒有使用相關(guān)starter,跟Spring的整合一樣,可通用,JMS是通過的消息處理框架,可以深入學(xué)習(xí)一下,不同的MQ在JMS的整合上都是類似的,感興趣的朋友跟隨小編一起看看吧2023-01-01Java NumberFormat格式化float類型的bug
今天小編就為大家分享一篇關(guān)于Java NumberFormat格式化float類型的bug,小編覺得內(nèi)容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧2018-10-10