国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 婺源县| 纳雍县| 太原市| 新龙县| 凌源市| 图片| 唐海县| 洪泽县| 德令哈市| 新宾| 株洲县| 锡林浩特市| 牡丹江市| 广南县| 刚察县| 招远市| 西青区| 凤城市| 沐川县| 青海省| 株洲县| 特克斯县| 岐山县| 连江县| 石河子市| 阳东县| 平陆县| 汕头市| 沙田区| 沾化县| 清涧县| 彩票| 牡丹江市| 亳州市| 鹤庆县| 罗定市| 治多县| 苗栗市| 普陀区| 漳浦县| 耒阳市|