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.