How to Use ArrayWritable in MapReduce, mapreducewritable

Source: Internet
Author: User

How to Use ArrayWritable in MapReduce, mapreducewritable

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 get started with the development of mapreduce programming framework in hadoop?

Check the code and use the built-in wordcount code to get started.

How to divide fields by using the file generated by mapreduce as the input file of the new mapreduce?

Your first job should use TextOutputFormat, so the output is a text document in key-value format by default. After being input, TextOutputFormat is used by default, the read key is the offset of each row rather than the key when the output of the previous job. This requires that the input format of the second job be set to KeyValueInputFormat.

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.