国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

MapReduce中ArrayWritable 使用方法

2019-11-14 21:02:43
字體:
來源:轉載
供稿:網友
MaPReduce中ArrayWritable 使用方法

在編寫MapReduce程序時,Map和Reduce之間傳遞的數據需要是ArrayList類型的,在調試運行時遇到了這樣的一個錯誤:

java.lang.RuntimeException: java.lang.NoSuchMethodException: org.apache.hadoop.io.ArrayWritable.<init>()

  

經查詢官網API文檔后發現這樣的一段話:

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); }}

我的個人博客:http://www.yancey.info/?p=188

  


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 长春市| 稻城县| 得荣县| 双柏县| 襄樊市| 施秉县| 九寨沟县| 长垣县| 河曲县| 南充市| 和顺县| 扎赉特旗| 宁津县| 昌乐县| 南康市| 涪陵区| 宜春市| 栖霞市| 淮安市| 金门县| 永平县| 阿巴嘎旗| 岳池县| 衡山县| 永胜县| 潞城市| 横峰县| 和政县| 龙南县| 如皋市| 青州市| 石景山区| 阿合奇县| 新乐市| 宝丰县| 崇明县| 大足县| 全州县| 天柱县| 东乡族自治县| 静海县|