How to Use arraywritable in mapreduce

Source: Internet
Author: User

When writing a mapreduce program, the data transmitted between map and reduce must be of the arraylist type. During debugging and running, the following error occurs:

 
Java. Lang. runtimeexception: Java. Lang. nosuchmethodexception: org. Apache. hadoop. Io. arraywritable. <init> ()

After querying the API documentation on the official website, you can find the following:

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

It turns out that you need to implement a derived class of the arraywritable class by yourself. When using this class, you only need to implement two constructors.

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

My personal blog: http://www.yancey.info /? P = 188

How to Use arraywritable in mapreduce

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.