手机
当前位置:查字典教程网 >编程开发 >Java >MapReduce中ArrayWritable 使用指南
MapReduce中ArrayWritable 使用指南
摘要:在编写MapReduce程序时,Map和Reduce之间传递的数据需要是ArrayList类型的,在调试运行时遇到了这样的一个错误:java...

在编写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); } }

【MapReduce中ArrayWritable 使用指南】相关文章:

java遍历properties文件操作指南

java类中使用Jfreechart的简单实例

java中File类的使用方法

java中break和continue区别及使用场合分析

深入解析Java中volatile关键字的作用

jdbc中class.forname的作用

java this super使用方法详解

java中Class.forName的作用浅谈

Java中instanceof关键字的用法总结

Java中CyclicBarrier的用法分析

精品推荐
分类导航