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

首頁 > 編程 > Java > 正文

MapReduce中ArrayWritable 使用指南

2019-11-26 15:26:49
字體:
供稿:網(wǎng)友

在編寫MapReduce程序時(shí),Map和Reduce之間傳遞的數(shù)據(jù)需要是ArrayList類型的,在調(diào)試運(yùn)行時(shí)遇到了這樣的一個(gè)錯(cuò)誤:

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

原來是要自己實(shí)現(xiàn)一個(gè)ArrayWritable類的派生類,使用時(shí)只要實(shí)現(xiàn)兩個(gè)構(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); }}

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 遂溪县| 无锡市| 当阳市| 时尚| 泌阳县| 韶关市| 凤城市| 绍兴市| 威海市| 潍坊市| 徐州市| 乌鲁木齐县| 榆社县| 视频| 托里县| 余庆县| 四川省| 浮梁县| 渭南市| 文水县| 平南县| 柳州市| 建阳市| 喀什市| 漯河市| 西昌市| 正安县| 红河县| 合作市| 双城市| 青海省| 漳平市| 新巴尔虎右旗| 甘谷县| 金堂县| 南和县| 华安县| 贵州省| 布尔津县| 宁国市| 惠州市|