MapReduce中ArrayWritable 使用指南
时间:2021-03-23 09:35:11|栏目: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);
}
}
上一篇:hibernate通过session实现增删改查操作实例解析
栏 目:JAVA代码
下一篇:Java正则之贪婪匹配、惰性匹配
本文标题:MapReduce中ArrayWritable 使用指南
本文地址:http://www.codeinn.net/misctech/86436.html


阅读排行
- 1Java Swing组件BoxLayout布局用法示例
- 2java中-jar 与nohup的对比
- 3Java邮件发送程序(可以同时发给多个地址、可以带附件)
- 4Caused by: java.lang.ClassNotFoundException: org.objectweb.asm.Type异常
- 5Java中自定义异常详解及实例代码
- 6深入理解Java中的克隆
- 7java读取excel文件的两种方法
- 8解析SpringSecurity+JWT认证流程实现
- 9spring boot里增加表单验证hibernate-validator并在freemarker模板里显示错误信息(推荐)
- 10深入解析java虚拟机




